This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: [PATCH]: Thread safe FILE allocation [WAS: Re: [RFC]: Threadsafety in __sfp and atexit]
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Thomas Pfaff <thomas dot pfaff at gmx dot net>
- Cc: newlib at sources dot redhat dot com
- Date: Thu, 22 Jan 2004 17:08:47 -0500
- Subject: Re: [PATCH]: Thread safe FILE allocation [WAS: Re: [RFC]: Threadsafety in __sfp and atexit]
- References: <400C46CA.6000605@gmx.net> <400C544F.7050002@redhat.com> <40103553.3000004@gmx.net>
Thomas Pfaff wrote:
Jeff Johnston wrote:
Thomas Pfaff wrote:
The list operations in __sfp and atexit are not thread safe AFAICS.
This could be avoided by using a mutex or atomic instructions when a
FILE pointer is acquired or an atexit function is added.
The problem hereby is that such a mutex should be created on newlib
initialization (_REENT_INIT on the _impure_ptr for example), but
there might be better locations.
Doing list insert with atomic instructions on the other hand is easy
on i86 (i486 and above) but might be a problem on other platfomrs.
Comments are welcome.
Thomas
You can't assume atomic instructions exist for all platforms. I
think something akin to the ENV_LOCK. MALLOC_LOCK methods used by the
getenv and malloc family routines would be appropriate.
-- Jeff J.
Attached is what i think would be appropriate.
It protects the FILE pointer list by using __LOCK_INIT, __lock_acquire
and __lock_release.
Thomas
2004-01-22 Thomas Pfaff <tpfaff@gmx.net>
* libc/stdio/findfp.c (__sfp): Protect global FILE pointer list
by a lock when newlib is multithreaded.
Thanks. Patch has been committed.
-- Jeff J.