From 208f46d8bf8feb9f677ed3e4f1e4169dbaa270e1 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Thu, 20 Sep 2012 10:35:05 +0200 Subject: [PATCH] make the thread test work on windows --- tests/test_threaded_calls.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/test_threaded_calls.c b/tests/test_threaded_calls.c index 0ed1c74..5e11568 100644 --- a/tests/test_threaded_calls.c +++ b/tests/test_threaded_calls.c @@ -30,10 +30,23 @@ #include #include -#include #include #include +#ifdef _WIN32 +#include +#include +#define ALLOC_THREADS(size) HANDLE *threads = malloc(sizeof(HANDLE) * times) +#define spawn_thread(thread, attr, start_routine, arg) thread = CreateThread(attr, 0, start_routine, arg, 0, NULL) +#define join_thread(thread, retval) WaitForSingleObject(thread, INFINITE) +#else +#include +#define ALLOC_THREADS(size) pthread_t *threads = malloc(sizeof(pthread_t) * times) +#define spawn_thread(thread, attr, start_routine, arg) pthread_create(&thread, attr, start_routine, arg) +#define join_thread(thread, retval) pthread_join(thread, retval) +#endif +#define FREE_THREADS free(threads) + #include void *start_thread(void *arg) @@ -61,14 +74,14 @@ void _test_threaded_calls() { int times = 5; int i; - pthread_t *threads = malloc(sizeof(pthread_t) * times); + ALLOC_THREADS(times); for(i = 0; i < times; i++) { - pthread_create(&threads[i], NULL, start_thread, NULL); - pthread_join(threads[i], NULL); + spawn_thread(threads[i], NULL, start_thread, NULL); + join_thread(threads[i], NULL); } - free(threads); + FREE_THREADS; } int main(void) -- 2.39.5