1 | /* |
---|
2 | * COPYRIGHT (c) 1989-1997. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * Copyright assigned to U.S. Government, 1994. |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may in |
---|
7 | * the file LICENSE in this distribution or at |
---|
8 | * http://www.OARcorp.com/rtems/license.html. |
---|
9 | * |
---|
10 | * $Id$ |
---|
11 | */ |
---|
12 | |
---|
13 | #define CONFIGURE_INIT |
---|
14 | #include "system.h" |
---|
15 | #include <errno.h> |
---|
16 | |
---|
17 | void *POSIX_Init( |
---|
18 | void *argument |
---|
19 | ) |
---|
20 | { |
---|
21 | int status; |
---|
22 | void *return_pointer; |
---|
23 | |
---|
24 | puts( "\n\n*** POSIX TEST 8 ***" ); |
---|
25 | |
---|
26 | /* set the time of day, and print our buffer in multiple ways */ |
---|
27 | |
---|
28 | set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
29 | |
---|
30 | /* get id of this thread */ |
---|
31 | |
---|
32 | Init_id = pthread_self(); |
---|
33 | printf( "Init's ID is 0x%08x\n", Init_id ); |
---|
34 | |
---|
35 | puts( "Init: pthread_detach - ESRCH (invalid id)" ); |
---|
36 | status = pthread_detach( -1 ); |
---|
37 | assert( status == ESRCH ); |
---|
38 | |
---|
39 | /* detach this thread */ |
---|
40 | |
---|
41 | puts( "Init: pthread_detach self" ); |
---|
42 | status = pthread_detach( pthread_self() ); |
---|
43 | assert( !status ); |
---|
44 | |
---|
45 | /* create thread */ |
---|
46 | |
---|
47 | puts( "Init: creating two tasks" ); |
---|
48 | status = pthread_create( &Task_id, NULL, Task_1, NULL ); |
---|
49 | assert( !status ); |
---|
50 | |
---|
51 | status = pthread_create( &Task2_id, NULL, Task_2, NULL ); |
---|
52 | assert( !status ); |
---|
53 | |
---|
54 | puts( "Init: pthread_join - ESRCH (invalid id)" ); |
---|
55 | status = pthread_join( -1, &return_pointer ); |
---|
56 | assert( status == ESRCH ); |
---|
57 | |
---|
58 | puts( "Init: pthread_join - SUCCESSFUL" ); |
---|
59 | status = pthread_join( Task_id, &return_pointer ); |
---|
60 | /* assert is below comment */ |
---|
61 | |
---|
62 | /* switch to Task 1 */ |
---|
63 | |
---|
64 | puts( "Init: returned from pthread_join" ); |
---|
65 | if ( status ) |
---|
66 | printf( "status = %d\n", status ); |
---|
67 | assert( !status ); |
---|
68 | |
---|
69 | if ( return_pointer == &Task_id ) |
---|
70 | puts( "Init: pthread_join returned correct pointer" ); |
---|
71 | else |
---|
72 | printf( |
---|
73 | "Init: pthread_join returned incorrect pointer (%p != %p)\n", |
---|
74 | return_pointer, |
---|
75 | &Task_id |
---|
76 | ); |
---|
77 | |
---|
78 | puts( "Init: exitting" ); |
---|
79 | pthread_exit( NULL ); |
---|
80 | |
---|
81 | return NULL; /* just so the compiler thinks we returned something */ |
---|
82 | } |
---|