1 /* BeginSourceFile start_stop.c
3 This file creates and deletes threads, so that wdb
4 can be tested on thread delete.
8 cc -Ae +DA1.0 -g -o start_stop -lpthread start_stop.c
12 start_stop --normal run
13 start_stop 1 --waits in each thread to keep it alive.
24 #define OUTER_LOOP_COUNT 3
26 #define MAX_LOCAL_VAL 40
28 /* Uncomment to turn on debugging output */
29 /* #define START_DEBUG */
31 /* True if waiting for attach.
35 /* Thing to check for debugging purposes.
39 /* Thread-local storage.
41 __thread
int a_thread_local
;
43 /* Check the results of thread-local storage.
45 int thread_local_val
[ N_THREADS
];
46 int val_debugger_saw
[ N_THREADS
];
48 /* Routine for each thread to run, does nothing.
57 printf( "== In thread %d\n", me
);
63 for( i
= 0; i
< a_global
; i
++ ) {
67 thread_local_val
[ me
] = a_thread_local
; /* Line 67 */
69 printf( "== Thread %d, a_thread_local is %d\n",
70 (int) vp
, a_thread_local
);
73 /* Extend life of thread to extend life of thread-local var.
74 * This makes life easier for human debugging (though you'd
75 * probably want to make the delay longer).
86 pthread_t t
[ N_THREADS
];
89 for( i
= 0; i
< N_THREADS
; i
++) {
90 thread_local_val
[i
] = 0;
91 val_debugger_saw
[i
] = 0;
94 /* Start N_THREADS threads, then join them so
95 * that they are terminated.
97 for( i
= 0; i
< N_THREADS
; i
++ ) {
98 err
= pthread_create( &t
[i
], NULL
, spin
, (void *)i
);
100 printf( "== Start/stop, error in thread %d create\n", i
);
104 for( i
= 0; i
< N_THREADS
; i
++ ) {
105 err
= pthread_join(t
[i
], NULL
); /* Line 105 */
106 if( err
!= 0 ) { /* Line 106 */
107 printf( "== Start/stop, error in thread %d join\n", i
);
111 i
= 10; /* Line 109. Null line for setting bpts on. */
113 /*#ifdef START_DEBUG*/
114 for( i
= 0; i
< N_THREADS
; i
++) {
115 printf( " Local in thread %d was %d, debugger saw %d\n",
116 i
, thread_local_val
[i
], val_debugger_saw
[i
] );
118 printf( "== Pass %d done\n", pass
);
126 /* We want to start some threads and then
127 * end them, and then do it again and again
132 for( i
= 0; i
< OUTER_LOOP_COUNT
; i
++ ) {
134 dummy
= i
; /* Line 134, null line for setting bps on */
143 if((argc
> 1) && (0 != argv
)) {
144 if( 1 == atoi( argv
[1] ) )
149 printf( "== Test starting\n" );
155 printf( "== Test done\n" );
This page took 0.032637 seconds and 4 git commands to generate.