/* Copyright (C) 2008 Andreas Baumann This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "threads/threads.h" #include "port/unused.h" #include /* for EXIT_SUCCESS, EXIT_FAILURE */ #include /* for fprintf */ #define NOF_THREADS 10 #define NOF_ITERATIONS 10000 static WOLF_THREAD_RETURN_DECL thread_func( void *thread_data ) { int thread_id = *((int *)thread_data); int i; printf( "Starting thread %d\n", thread_id ); fflush( stdout ); for( i = 0; i < NOF_ITERATIONS; i++ ) { printf( "%d\n", i ); fflush( stdout ); } printf( "Terminating thread %d\n", thread_id ); fflush( stdout ); WOLF_THREAD_RETURN } int main( void ) { int i; wolf_thread_t thread[NOF_THREADS]; wolf_error_t error; int thread_data[NOF_THREADS]; for( i = 0; i < NOF_THREADS; i++ ) { thread_data[i] = i; error = wolf_thread_create( &thread[i], thread_func, (void *)&thread_data[i] ); 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; }