[Libaio-oracle-devel] Re: libaio-oracle.0.3.0 threadsafe?

Joel Becker Joel.Becker at oracle.com
Thu Aug 26 13:21:43 CDT 2004


On Thu, Aug 26, 2004 at 04:03:54PM +0200, Marrek, Norbert wrote:
> Can I use the libaio-oracle.0.3.0 in multi-threaded programs,
> i.e. is the library threadsafe?

	No, the library is not threadsafe.  Because the SUSv2 interfaces
do not take an AIO context, the library stores the context in a static
variable.  All calls reference this variable.  Calling aio_init() will
get a new context (useful for fork(2) without exec(2)), but that means
nothing in threaded apps, as it doesn't use thread-local storage.
	Note that SUSv2 does not make thread safety a requirement of
this interface.  I detest the idea of forcing people to link libpthreads
for single-threaded applications, so I had no intention of using TLS or
the like in the application.
	You can either have only one thread handle the aio calls, or you
can do your own locking.  Either works.  You can also use the raw system
call interface provided by libaio.  As this returns a context to the
caller, it is threadsafe.

Joel

-- 

"It is not the function of our government to keep the citizen from
 falling into error; it is the function of the citizen to keep the
 government from falling into error."
	- Robert H. Jackson

Joel Becker
Senior Member of Technical Staff
Oracle Corporation
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127


More information about the Libaio-oracle-devel mailing list