This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


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

Fw: pthreads and atexit on cygwin


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


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