diff options
Diffstat (limited to 'tests')
-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; } |