[20de272] | 1 | /* |
---|
[08311cc3] | 2 | * COPYRIGHT (c) 1989-1999. |
---|
[20de272] | 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
[98e4ebf5] | 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 7 | * http://www.OARcorp.com/rtems/license.html. |
---|
[20de272] | 8 | * |
---|
| 9 | * $Id$ |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #define CONFIGURE_INIT |
---|
| 13 | #include "system.h" |
---|
| 14 | #include <errno.h> |
---|
| 15 | |
---|
| 16 | void *POSIX_Init( |
---|
| 17 | void *argument |
---|
| 18 | ) |
---|
| 19 | { |
---|
| 20 | int status; |
---|
| 21 | void *return_pointer; |
---|
| 22 | |
---|
| 23 | puts( "\n\n*** POSIX TEST 8 ***" ); |
---|
| 24 | |
---|
| 25 | /* set the time of day, and print our buffer in multiple ways */ |
---|
| 26 | |
---|
| 27 | set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
| 28 | |
---|
| 29 | /* get id of this thread */ |
---|
| 30 | |
---|
| 31 | Init_id = pthread_self(); |
---|
| 32 | printf( "Init's ID is 0x%08x\n", Init_id ); |
---|
| 33 | |
---|
[42418a9] | 34 | puts( "Init: pthread_detach - ESRCH (invalid id)" ); |
---|
| 35 | status = pthread_detach( -1 ); |
---|
| 36 | assert( status == ESRCH ); |
---|
| 37 | |
---|
[20de272] | 38 | /* detach this thread */ |
---|
| 39 | |
---|
| 40 | puts( "Init: pthread_detach self" ); |
---|
| 41 | status = pthread_detach( pthread_self() ); |
---|
| 42 | assert( !status ); |
---|
| 43 | |
---|
| 44 | /* create thread */ |
---|
| 45 | |
---|
[7d96321] | 46 | status = pthread_create( &Task1_id, NULL, Task_1, NULL ); |
---|
[20de272] | 47 | assert( !status ); |
---|
| 48 | |
---|
[42418a9] | 49 | puts( "Init: pthread_join - ESRCH (invalid id)" ); |
---|
| 50 | status = pthread_join( -1, &return_pointer ); |
---|
| 51 | assert( status == ESRCH ); |
---|
| 52 | |
---|
[20de272] | 53 | puts( "Init: pthread_join - SUCCESSFUL" ); |
---|
[7d96321] | 54 | status = pthread_join( Task1_id, &return_pointer ); |
---|
[20de272] | 55 | |
---|
[7d96321] | 56 | puts( "Init: returned from pthread_join through return" ); |
---|
| 57 | if ( status ) |
---|
| 58 | printf( "status = %d\n", status ); |
---|
| 59 | assert( !status ); |
---|
[20de272] | 60 | |
---|
[7d96321] | 61 | if ( return_pointer == &Task1_id ) |
---|
| 62 | puts( "Init: pthread_join returned correct pointer" ); |
---|
| 63 | else |
---|
| 64 | printf( |
---|
| 65 | "Init: pthread_join returned incorrect pointer (%p != %p)\n", |
---|
| 66 | return_pointer, |
---|
| 67 | &Task1_id |
---|
| 68 | ); |
---|
| 69 | |
---|
| 70 | puts( "Init: creating two pthreads" ); |
---|
| 71 | status = pthread_create( &Task2_id, NULL, Task_2, NULL ); |
---|
| 72 | assert( !status ); |
---|
| 73 | |
---|
| 74 | status = pthread_create( &Task3_id, NULL, Task_3, NULL ); |
---|
| 75 | assert( !status ); |
---|
| 76 | |
---|
| 77 | puts( "Init: pthread_join - SUCCESSFUL" ); |
---|
| 78 | status = pthread_join( Task2_id, &return_pointer ); |
---|
| 79 | /* assert is below comment */ |
---|
| 80 | |
---|
| 81 | puts( "Init: returned from pthread_join through pthread_exit" ); |
---|
[20de272] | 82 | if ( status ) |
---|
| 83 | printf( "status = %d\n", status ); |
---|
| 84 | assert( !status ); |
---|
| 85 | |
---|
[7d96321] | 86 | if ( return_pointer == &Task2_id ) |
---|
[20de272] | 87 | puts( "Init: pthread_join returned correct pointer" ); |
---|
| 88 | else |
---|
| 89 | printf( |
---|
| 90 | "Init: pthread_join returned incorrect pointer (%p != %p)\n", |
---|
| 91 | return_pointer, |
---|
[7d96321] | 92 | &Task2_id |
---|
[20de272] | 93 | ); |
---|
| 94 | |
---|
| 95 | puts( "Init: exitting" ); |
---|
[7d96321] | 96 | return NULL; |
---|
[20de272] | 97 | } |
---|