| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
#include "glthread/thread.h" |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
#include "macros.h" |
| 27 |
|
| 28 |
static gl_thread_t main_thread_before; |
| 29 |
static gl_thread_t main_thread_after; |
| 30 |
static gl_thread_t worker_thread; |
| 31 |
|
| 32 |
static int dummy; |
| 33 |
static volatile int work_done; |
| 34 |
|
| 35 |
static void * |
| 36 |
worker_thread_func (void *arg) |
| 37 |
{ |
| 38 |
work_done = 1; |
| 39 |
return &dummy; |
| 40 |
} |
| 41 |
|
| 42 |
int |
| 43 |
main () |
| 44 |
{ |
| 45 |
main_thread_before = gl_thread_self (); |
| 46 |
|
| 47 |
if (glthread_create (&worker_thread, worker_thread_func, NULL) == 0) |
| 48 |
{ |
| 49 |
void *ret; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
main_thread_after = gl_thread_self (); |
| 54 |
ASSERT (memcmp (&main_thread_before, &main_thread_after, |
| 55 |
sizeof (gl_thread_t)) |
| 56 |
== 0); |
| 57 |
|
| 58 |
gl_thread_join (worker_thread, &ret); |
| 59 |
|
| 60 |
|
| 61 |
ASSERT (ret == &dummy); |
| 62 |
|
| 63 |
|
| 64 |
ASSERT (work_done); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |
| 68 |
else |
| 69 |
{ |
| 70 |
#if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS |
| 71 |
fputs ("glthread_create failed\n", stderr); |
| 72 |
return 1; |
| 73 |
#else |
| 74 |
fputs ("Skipping test: multithreading not enabled\n", stderr); |
| 75 |
return 77; |
| 76 |
#endif |
| 77 |
} |
| 78 |
} |