Re: [PATCH] exit.3: ATTRIBUTES: Note function that is not thread-safe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/19/2013 02:30 AM, Michael Kerrisk wrote:
> 
> Ouch! Really? so one cannot call exit(3) from a multithreaded program?
> This seems a clear violation of the standard. 
> 

Yes.
I make a test program to test exit(3) which is not thread-safe.

$ gcc -o exit exit.c -lpthread
$ ./exit
Goodbye.
...
Goodbye.
Segmentation fault

> Could you provide some pointers to more information on this point (e.g., URL
> of mail thread archive discussions.)
> 

http://sourceware.org/ml/libc-alpha/2013-03/msg00004.html


-- 
Best Regards,
Peng

> Thanks,
> 
> Michael
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-man" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

long long int i = 0;

static void bye (void)
{
	printf ("Goodbye.\n");
}

void *thread_severity()
{
	while (1) {
		atexit(bye);
		i++;
		if ( i >= 1000000) {
			printf("i is enough.\n");
			return NULL;
		}
	}

	return NULL;
}

int main (void)
{
	pthread_t thread_severity_id, thread_fmtmsg_id;

	pthread_create(&thread_fmtmsg_id, NULL, thread_severity, NULL);

	while(1) {
		if (i >= 500000)
			exit(0);
		usleep(1000);
	}
}


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux