Fw: pthreads and atexit on cygwin

peter garrone pgarrone@linuxmail.org
Thu Sep 4 16:02:00 GMT 2003


I recently reported a problem I was encountering on the
cygwin list and was redirected here.

If the main thread makes an "atexit" call, and "exit" is
called by another thread, then the exit routine specified
by "atexit" is not invoked.

This appears to be related to other issues recently discussed on this list,
to do with stdio reentrancy, mostly with the thread dealing with __DYNAMIC__REENT__,
I believe.



#include <pthread.h>
#include <stdio.h>
#include <assert.h>

static pthread_cond_t started = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t a_thread;

static void exitfunc(void)
{
	printf("exit function invoked.\n");
}
 
static void * thread_routine(void * data)
{
	exit(0);
}

int main(int argc, int argv)
{
	int r;
	r = atexit(exitfunc);
	assert(r == 0);

	if(argc > 1)return 0;

	r = pthread_mutex_lock(&a_mutex);
	assert(r == 0);

	r = pthread_create(&a_thread, NULL, thread_routine, NULL);
	assert(r == 0);

	r = pthread_cond_wait(&started, &a_mutex);
	assert(r == 0);

	return 0;
}
> 
> -- 
> ______________________________________________
> http://www.linuxmail.org/
> Now with e-mail forwarding for only US$5.95/yr
> 
> Powered by Outblaze

-- 
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze



More information about the Newlib mailing list