[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch: Thread safe obstack
From: |
Bruno Haible |
Subject: |
Re: Patch: Thread safe obstack |
Date: |
Sun, 26 Aug 2007 11:49:42 +0200 |
User-agent: |
KMail/1.5.4 |
Hello Herbert Euler,
> Below is my patch to obstack
gnulib provides for obstack the same API as glibc. It makes no sense for
gnulib to provide a variant of obstack that has features that glibc does
not have.
Therefore the right place to post your patch is either the libc-alpha
AT sourceware DOT org mailing list, or the glibc bugzilla
http://sourceware.org/bugzilla/
> I have trouble using obstacks with my threaded server, since obstack's
> error handling is not thread safe. It provides a user defined
> function `obstack_alloc_failed_handler' to signal errors when
> allocation fails, and this function can call longjmp instead of
> exiting.
There is nothing not thread-safe about this.
> But I can only call longjmp with a global jmp_buf, since
> this function is called with no arguments.
There are at least three ways to have a function with no arguments react
depending where it is called:
- Use thread-local storage. See function pthread_getspecific [1]. gnulib has
a module 'tls' for portability.
- Create the function as a local function (function defined inside a
function); this is a GCC extension to the C language [2].
- The 'trampoline' library [3], part of ffcall [4]. This facility allows
to create functions depending on arbitrary data (not just depending on
the current thread).
Bruno
[1] http://www.opengroup.org/susv3/functions/pthread_getspecific.html
[2] http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC65
[3] http://www.haible.de/bruno/documentation/ffcall/trampoline/trampoline.html
[4] http://www.haible.de/bruno/packages-ffcall.html