1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include "test_support.h" |
---|
16 | #include <pthread.h> |
---|
17 | |
---|
18 | const char rtems_test_name[] = "PSX 16"; |
---|
19 | |
---|
20 | /* forward declarations to avoid warnings */ |
---|
21 | void *POSIX_Init(void *argument); |
---|
22 | void *TestThread(void *argument); |
---|
23 | |
---|
24 | int Index; |
---|
25 | |
---|
26 | void *TestThread( |
---|
27 | void *argument |
---|
28 | ) |
---|
29 | { |
---|
30 | int *index = (int *)argument; |
---|
31 | |
---|
32 | *index = 7; |
---|
33 | |
---|
34 | puts( "TestThread exiting" ); |
---|
35 | return argument; |
---|
36 | } |
---|
37 | |
---|
38 | void *POSIX_Init(void *argument) |
---|
39 | { |
---|
40 | int status; |
---|
41 | pthread_t id; |
---|
42 | pthread_attr_t attr; |
---|
43 | void *join_return; |
---|
44 | |
---|
45 | TEST_BEGIN(); |
---|
46 | |
---|
47 | Index = 5; |
---|
48 | |
---|
49 | /* Initialize and set thread detached attribute */ |
---|
50 | pthread_attr_init(&attr); |
---|
51 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
---|
52 | |
---|
53 | puts( "Creating TestThread" ); |
---|
54 | status = pthread_create( &id, &attr, TestThread, (void *)&Index ); |
---|
55 | rtems_test_assert( status == 0 ); |
---|
56 | |
---|
57 | /* let test thread run and exit */ |
---|
58 | puts( "Let TestThread run and exit before we attempt to join" ); |
---|
59 | sleep( 2 ); |
---|
60 | |
---|
61 | join_return = NULL; |
---|
62 | status = pthread_join( id, &join_return ); |
---|
63 | rtems_test_assert( status == 0 ); |
---|
64 | rtems_test_assert( join_return == &Index ); |
---|
65 | rtems_test_assert( *(int *)join_return == 7 ); |
---|
66 | puts( "Successfully joined with TestThread" ); |
---|
67 | |
---|
68 | TEST_END(); |
---|
69 | |
---|
70 | rtems_test_exit(0); |
---|
71 | } |
---|
72 | |
---|
73 | /* configuration information */ |
---|
74 | |
---|
75 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
76 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
77 | |
---|
78 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
79 | |
---|
80 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
81 | |
---|
82 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
83 | |
---|
84 | #define CONFIGURE_INIT |
---|
85 | #include <rtems/confdefs.h> |
---|
86 | /* end of file */ |
---|