From fb61813650d8aee85bfa51f3803d40926786e811 Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Mon, 18 Jan 2010 12:43:28 -0500 Subject: [PATCH 1/5] use unsigned long for even more digits! --- tests/backend/test-threadpool.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/backend/test-threadpool.c b/tests/backend/test-threadpool.c index 805e61c2c..d241926b4 100644 --- a/tests/backend/test-threadpool.c +++ b/tests/backend/test-threadpool.c @@ -30,10 +30,10 @@ void is_prime(void * arg) { - int number = *(int *)arg; - int prime = 1; + unsigned long long number = *(unsigned long long *)arg; + unsigned long long prime = 1; - for (int x = number; x >= sqrt(number); --x) + for (unsigned long long x = number; x >= sqrt(number); --x) { if (number % x == 0) { @@ -41,7 +41,7 @@ void is_prime(void * arg) break; } } - *(int *)arg = prime; + *(unsigned long long *)arg = prime; } TESTS_BEGIN @@ -180,11 +180,11 @@ TEST ("process-function") { // this is what the scheduler would do once it figures out what function a job needs to run LumieraThread t; - int number = 1073676287; + unsigned long long number = 18014398241046527; lumiera_threadpool_init(); - ECHO ("the input to the function is %d", number); + ECHO ("the input to the function is %llu", number); t = lumiera_thread_run (LUMIERA_THREADCLASS_INTERACTIVE, &is_prime, From fca6cd786b70fafa2ffbe024089bd3f8c30efaa9 Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Wed, 20 Jan 2010 07:54:26 -0500 Subject: [PATCH 2/5] fix the prime test algorithm actually test for the output of the function --- tests/30backend-threadpool.tests | 2 +- tests/backend/test-threadpool.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/30backend-threadpool.tests b/tests/30backend-threadpool.tests index 6ba717091..65125489d 100644 --- a/tests/30backend-threadpool.tests +++ b/tests/30backend-threadpool.tests @@ -10,7 +10,7 @@ END TEST "process a function" process-function <= sqrt(number); --x) + for (unsigned long long x = number-1; x >= sqrt(number); --x) { - if (number % x == 0) + if ((number % x) == 0) { prime = 0; break; @@ -180,7 +180,7 @@ TEST ("process-function") { // this is what the scheduler would do once it figures out what function a job needs to run LumieraThread t; - unsigned long long number = 18014398241046527; + unsigned long long number = 10000019; lumiera_threadpool_init(); @@ -193,8 +193,9 @@ TEST ("process-function") &NOBUG_FLAG(NOBUG_ON)); // struct nobug_flag* flag) // cleanup - ECHO("finished waiting"); lumiera_threadpool_destroy(); + ECHO("the result is %llu", number); + } TESTS_END From 571c265ccdeced48f835c5a03e84547379d2880e Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Wed, 20 Jan 2010 07:58:22 -0500 Subject: [PATCH 3/5] minor fixes: remove an old comment and change another --- src/backend/threadpool.c | 1 - src/backend/threads.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/threadpool.c b/src/backend/threadpool.c index 9de1e6d81..b4811bc75 100644 --- a/src/backend/threadpool.c +++ b/src/backend/threadpool.c @@ -173,7 +173,6 @@ lumiera_threadpool_acquire_thread (enum lumiera_thread_class kind, return ret; } -// TODO: rename to lumiera_threadpool_park_thread void lumiera_threadpool_release_thread(LumieraThread thread) { diff --git a/src/backend/threads.c b/src/backend/threads.c index 4aeebbf23..860ee1770 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -161,7 +161,7 @@ lumiera_thread_new (enum lumiera_thread_class kind, { pthread_once (&lumiera_thread_initialized, lumiera_thread_tls_init); - // TODO: do something with these: + // TODO: do something with this string: (void) purpose; REQUIRE (attrs, "invalid pthread attributes structure passed"); From a22bb5e54f372688b3cbb0bb717a1cc524f8ba43 Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Wed, 20 Jan 2010 17:09:37 -0500 Subject: [PATCH 4/5] show the state of the thread in question --- src/backend/threads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/threads.c b/src/backend/threads.c index 860ee1770..f842f32ae 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -294,7 +294,7 @@ lumiera_thread_sync_other (LumieraThread other) LUMIERA_CONDITION_SECTION (threads, &other->signal) { - REQUIRE (other->state == LUMIERA_THREADSTATE_SYNCING); TODO("Runtime error when state expectation isnt met"); + REQUIRE (other->state == LUMIERA_THREADSTATE_SYNCING, "the other thread is in the wrong state: %s", lumiera_threadstate_names[other->state]); TODO("Runtime error when state expectation isn't met"); other->state = LUMIERA_THREADSTATE_RUNNING; LUMIERA_CONDITION_SIGNAL; } From dc87e78590ea86615d3ebe90d23af4548445b941 Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Tue, 26 Jan 2010 16:58:30 -0500 Subject: [PATCH 5/5] add a two-thread acquire test currently this results in a deadlock between lumiera_threadpool_destroy() and thread_loop() --- tests/30backend-threadpool.tests | 10 ++++++++++ tests/backend/test-threadpool.c | 10 ++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/30backend-threadpool.tests b/tests/30backend-threadpool.tests index 65125489d..6945d4d5d 100644 --- a/tests/30backend-threadpool.tests +++ b/tests/30backend-threadpool.tests @@ -13,4 +13,14 @@ err: the input to the function is err: the result is 1 END +TEST "acquire two threads" two-thread-acquire <state]); CHECK(LUMIERA_THREADSTATE_IDLE == t2->state); - ECHO("releasing thread 1"); - //lumiera_threadpool_release_thread(t1); - ECHO("thread 1 has been released"); - - ECHO("releasing thread 2"); - //lumiera_threadpool_release_thread(t2); - ECHO("thread 2 has been released"); + ECHO("cleaning up"); lumiera_threadpool_destroy(); }