diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-31 19:02:30 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-31 19:02:30 +0200 |
commit | 6930fcf8f8f22384cb0a4a050afbaa8cbaa32f94 (patch) | |
tree | f898d2e04643f5b151e1808854eb571710b4b9d2 /tests/threads | |
parent | 80fabedc72b56664a4f6d77c253f9b3fe3939707 (diff) | |
download | wolfbones-6930fcf8f8f22384cb0a4a050afbaa8cbaa32f94.tar.gz wolfbones-6930fcf8f8f22384cb0a4a050afbaa8cbaa32f94.tar.bz2 |
added a simple thread test
Diffstat (limited to 'tests/threads')
-rw-r--r-- | tests/threads/test_create_join.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/threads/test_create_join.c b/tests/threads/test_create_join.c index 70fee97..117c304 100644 --- a/tests/threads/test_create_join.c +++ b/tests/threads/test_create_join.c @@ -1,7 +1,48 @@ #include "threads/threads.h" +#include "port/unused.h" -#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */ +#include <stdlib.h> /* for EXIT_SUCCESS, EXIT_FAILURE */ +#include <stdio.h> /* for fprintf */ + +#define NOF_THREADS 10 +#define NOF_ITERATIONS 10000 + +static void *thread_func( void *thread_data ) { + int i; + + for( i = 0; i < NOF_ITERATIONS; i++ ) { + printf( "%d\n", i ); + fflush( stdout ); + } + + WOLF_UNUSED( thread_data ); + return NULL; +} int main( void ) { + int i; + wolf_thread_t thread[NOF_THREADS]; + wolf_error_t error; + + for( i = 0; i < NOF_THREADS; i++ ) { + error = wolf_thread_create( &thread[i], thread_func ); + if( error != WOLF_OK ) { + fprintf( stderr, "Unable to start thread %d: %d\n", i, error ); + return EXIT_FAILURE; + } + printf( "Created thread %d\n", i ); + fflush( stdout ); + } + + for( i = 0; i < NOF_THREADS; i++ ) { + error = wolf_thread_join( &thread[i] ); + if( error != WOLF_OK ) { + fprintf( stderr, "Unable to join thread %d: %d\n", i, error ); + return EXIT_FAILURE; + } + printf( "Joined thread %d\n", i ); + fflush( stdout ); + } + return EXIT_SUCCESS; } |