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]

exit & thread safety


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?

	Jakub


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