From 14cd51f7793a9ce07bc435069f57269450141363 Mon Sep 17 00:00:00 2001 From: Stan Shebs Date: Fri, 16 Apr 1999 01:35:26 +0000 Subject: Initial revision --- gdb/testsuite/gdb.hp/more-steps.c | 140 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 gdb/testsuite/gdb.hp/more-steps.c (limited to 'gdb/testsuite/gdb.hp/more-steps.c') diff --git a/gdb/testsuite/gdb.hp/more-steps.c b/gdb/testsuite/gdb.hp/more-steps.c new file mode 100644 index 00000000000..c5ba1e26865 --- /dev/null +++ b/gdb/testsuite/gdb.hp/more-steps.c @@ -0,0 +1,140 @@ +/* BeginSourceFile more_steps.c + + This file creates a lot of threads which then execute + in parallel, so that wdb can be tested on handling + simultaneous thread events. + + To compile: + + cc -Ae +DA1.0 -g -o more_steps -lpthread more_steps.c + + To run: + + more_threads +*/ + +#include +#include +#include +#include +#include + +#define TRUE 1 +#define FALSE 0 +#define N_THREADS 3 +#define PHASES 3 + +typedef enum { + ZERO, + ONE, + TWO, + THREE +} phase_t; + +/* Uncomment to turn on debugging output */ +/* #define DEBUG */ + +/* Locks. + */ +int lock_one; /* Main W, others R */ +int lock_two; /* ditto */ +int lock_end[ N_THREADS ]; /* Main R, others R[i] */ +int phase[ N_THREADS ]; + +/* Routine for each thread to run. + */ +void *spin( vp ) + void * vp; +{ + int me = (int) vp; + int i; + + lock_end[ me ] = TRUE; + + phase[ me ] = ONE; + + while( lock_one ); + + phase[ me ] = TWO; + + while( lock_two ); + + phase[ me ] = THREE; + + lock_end[ me ] = FALSE; +} + +void +do_pass() +{ + int i; + pthread_t t[ N_THREADS ]; + int err; + int done; + + /* Start N_THREADS threads, then join them so + * that they are terminated. + */ + for( i = 0; i < N_THREADS; i++ ) { + err = pthread_create( &t[i], NULL, spin, (void *)i ); + if( err != 0 ) { + printf( "== Start/stop, error in thread %d create\n", i ); + } + } + + /* Do phase 1. + */ + lock_one = FALSE; + + /* Do phase 2. + */ + lock_two = FALSE; + + /* Be done. + */ + done = 0; + while( !done ) { + + /* Be optimistic. + */ + done = 1; + for( i = 0; i < N_THREADS; i++ ) { + if( lock_end[i] ) { + /* Thread "i" is not ready yet. + */ + done = 0; + break; + } + } + } + + /* Finish up + */ + for( i = 0; i < N_THREADS; i++ ) { + err = pthread_join(t[i], NULL ); /* Line 105 */ + if( err != 0 ) { /* Line 106 */ + printf( "== Start/stop, error in thread %d join\n", i ); + } + } + + i = 10; /* Line 109. Null line for setting bpts on. */ +} + +main( argc, argv ) +int argc; +char **argv; +{ + int i; + + /* Init + */ + lock_one = TRUE; + lock_two = TRUE; + for( i = 0; i < N_THREADS; i++ ) { + lock_end[i] = TRUE; + phase[i] = ZERO; + } + + do_pass(); + return(0); +} -- cgit v1.2.1