Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
THREAD_SAFE_ERRNO.cpp
Go to the documentation of this file.
1// checking if errno is thread safe
2
3
25#include <errno.h>
26#include "thread.h"
27
28
29void *errno_addr = 0;
30
31
32extern "C" void* thread_routine (void*)
33{
34 errno_addr = &errno;
35 return 0;
36}
37
38
39int main ()
40{
41 pthread_t thread;
42
43 int err;
44
45 // create a thread that gets the address of errno
46 if ((err = pthread_create (&thread, 0, thread_routine, 0))) {
47 return 3;
48 }
49
50 if ((err = pthread_join (thread, 0))) {
51 return 2;
52 }
53
54 // compare the address of the (presumably) thread-local
55 // errno variable against that of the global errno and
56 // return 0 if they are different, 1 otherwise
57 return !(&errno != errno_addr);
58}
void * thread_routine(void *)
void * errno_addr
int main()