Merge remote branch 'plouj/second-tp-attempt' into backend_devel

* plouj/second-tp-attempt:
  basic joinable thread test
  joinable thread sync test
This commit is contained in:
Christian Thaeter 2010-02-08 18:20:05 +01:00
commit 26f88bc3f1
2 changed files with 67 additions and 0 deletions

View file

@ -36,4 +36,13 @@ err: result is 0
err: value is 84
END
TEST "joinable thread" joinable-thread <<END
END
TEST "sync joinable" sync-joinable <<END
err: syncing with the master thread
err: the master thread received its arguments
err: the master thread terminated
END
PLANNED "error cleared on join"

View file

@ -73,6 +73,28 @@ void sleeping_worker_fn(void * arg)
ECHO ("result is %d", input);
}
void joinable_worker_fn(void * arg)
{
int input = *(int *)arg;
lumiera_thread_sync ();
input += 42;
}
void joinable_master_fn(void * arg)
{
int input = *(int *)arg;
lumiera_thread_sync ();
input -= 42;
LumieraThread worker = lumiera_thread_run (LUMIERA_THREADCLASS_IDLE
| LUMIERA_THREAD_JOINABLE,
&joinable_worker_fn,
(void *)&input,
"joinable worker thread",
&NOBUG_FLAG (test));
lumiera_thread_sync_other (worker);
lumiera_thread_join (worker);
}
TESTS_BEGIN
TEST ("threadpool-basic")
@ -287,4 +309,40 @@ TEST ("sync-many")
lumiera_threadpool_destroy ();
}
TEST ("joinable-thread")
{
int delay = 10000;
lumiera_threadpool_init ();
LumieraThread t = lumiera_thread_run (LUMIERA_THREADCLASS_IDLE
| LUMIERA_THREAD_JOINABLE,
&sleep_fn,
(void *)&delay,
"joinable idle thread",
&NOBUG_FLAG (test));
lumiera_thread_join(t);
lumiera_threadpool_destroy ();
}
TEST ("sync-joinable")
{
lumiera_threadpool_init ();
int value = 0;
LumieraThread master = lumiera_thread_run (LUMIERA_THREADCLASS_IDLE
| LUMIERA_THREAD_JOINABLE,
&joinable_master_fn,
(void *)&value,
"joinable master thread",
&NOBUG_FLAG (test));
ECHO ("syncing with the master thread");
lumiera_thread_sync_other (master);
ECHO ("the master thread received its arguments");
lumiera_thread_join (master);
ECHO ("the master thread terminated");
lumiera_threadpool_destroy ();
}
TESTS_END