From 921aaaa1edaf41421398a3c0f1340902755fa3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 23 Feb 2011 17:28:42 +0000 Subject: [PATCH] the test now works as expected on Linux, and not on Haiku, it was broken before. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40644 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../libroot/posix/pthread_signal_test.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/tests/system/libroot/posix/pthread_signal_test.cpp b/src/tests/system/libroot/posix/pthread_signal_test.cpp index e217a57921..014741f469 100644 --- a/src/tests/system/libroot/posix/pthread_signal_test.cpp +++ b/src/tests/system/libroot/posix/pthread_signal_test.cpp @@ -9,6 +9,7 @@ static pthread_attr_t attributes; +static int id[4] = {0, 1, 2, 3}; static pthread_t tid[4]; static bool state[4]; static bool blocking[4]; @@ -85,18 +86,20 @@ self_suspend(int* i) void * threadStart(void *arg) { - int *i = (int*)arg; - pthread_setspecific(self, i); + int i = *(int*)arg; + pthread_setspecific(self, &i); - state[*i] = true; - blocking[*i] = true; + state[i] = true; + blocking[i] = true; + + printf("threadStart(%d)\n", i); for (int j = 0; j < 10; j++) { - self_suspend(i); - usleep(10000); + usleep(1000000); + self_suspend(&i); } - printf("quitting %d\n", *i); + printf("quitting %d\n", i); return NULL; } @@ -130,8 +133,9 @@ resumeAllThreads() } } + int t = 50; for (int i = 0; i < 4; i++) { - while(state[i] == false) { + while(state[i] == false && t-- > 0) { printf("thread %d still suspended, yielding\n", i); sched_yield(); } @@ -150,14 +154,14 @@ main(int argc, char **argv) pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED); for (int i = 0; i < 4; i++) { - if (pthread_create(&tid[i], &attributes, threadStart, &i) != 0) + if (pthread_create(&tid[i], &attributes, threadStart, &id[i]) != 0) fprintf(stderr, "couldn't create thread %d\n", i); printf("thread %d created\n", i); } /*suspendAllThreads();*/ printf("snoozing\n"); - usleep(2000000); + usleep(3000000); printf("resuming all threads\n"); resumeAllThreads(); printf("resuming all threads done\n");