This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: exit & thread safety


On Tue, Jun 04, 2002 at 07:16:25PM +0200, Jakub Jelinek wrote:
> Hi!
> 
> We got a report in Red Hat bugzilla about:
> 
> #include <pthread.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <sys/resource.h>
> #include <unistd.h>
> 
> void* foo(void * n)
> {
>   exit(0);
> }
> 
> int main()
> {
>   int n;
>   int status;
>   void *thread_result;
>   size_t size;
>   pthread_t thread_id;
>   pthread_attr_t thread_attr;
>   char * val;
>   status = pthread_create(&thread_id, NULL, foo, &n);
>   if (status) printf("ERROR: creating thread\n");
>   status = pthread_create(&thread_id, NULL, foo, &n);
>   if (status) printf("ERROR: creating thread\n");
> }
> 
> crashing from time to time.
> http://www.opengroup.org/onlinepubs/007908799/xsh/_exit.html
> says:
> If exit() is called more than once, the effects are undefined.
> among other things, so I'm not sure if glibc needs to do anything at all,
> but I think we can crash in other ways too (like if one threads does
> dlclose and another exit() or if one thread does atexit/__cxa_atexit/...
> and another one exit() at the same time.
> If exit() e.g. did not free the memory (which is needed for
> memory usage debuggers, right?), did not even change anything in the
> __exit_funcs chain and used compare_and_swap for each f->flavor right
> before its handler is called, then we should be ok IMHO.
> 
> What do you think?
> 

See

http://sources.redhat.com/ml/libc-alpha/2002-05/msg00008.html

While you are on it, also see

http://sources.redhat.com/ml/libc-alpha/2002-05/msg00201.html


H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]