Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
THREAD_SAFE_EXCEPTIONS.cpp
Go to the documentation of this file.
1// checking if exceptions are thread safe
2
3
25#include "thread.h"
26#include "nodbg.h"
27
28
29extern "C" void* thread_proc (void *arg)
30{
31 long sum = 0;
32 long n = (char*)arg - (char*)0;
33
34 for (long i = 0; i != 0x20000; ++i) {
35 try {
36 if (i % 2 == n)
37 throw i;
38 else
39 throw arg;
40 }
41 catch (long) {
42 ++sum;
43 }
44 catch (...) {
45 sum += 2;
46 }
47 }
48
49 return (void*)sum;
50}
51
52
53int main ()
54{
55 nodbg ();
56
57 pthread_t tid [2];
58
59 const unsigned N = sizeof tid / sizeof *tid;
60
62
63 unsigned i;
64
65 for (i = 0; i != N; ++i)
66 if (pthread_create (tid + i, 0, thread_proc, (void*)i))
67 return 1;
68
69 for (i = 0; i != N; ++i)
70 pthread_join (tid [i], 0);
71
72 return 0;
73}
#define N
Definition 17.names.cpp:157
#define i
Definition 17.names.cpp:126
#define n
Definition 17.names.cpp:130
void * thread_proc(void *arg)
void nodbg()
Definition nodbg.h:52
#define set_concurrency(n)
Definition thread.h:103
int arg
Definition locale.cpp:2806