1/* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2002-2020 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 This file is based on schedlock.c. */ 19 20#include <stdio.h> 21#include <unistd.h> 22#include <stdlib.h> 23#include <pthread.h> 24 25int THREADS = 10; 26unsigned int *args; 27volatile int done = 0; 28 29void * 30thread_function (void *arg) 31{ 32 int my_number = (long) arg; 33 volatile int *myp = (volatile int *) &args[my_number]; 34 35 /* Don't run forever. Run just short of it :) */ 36 while (*myp > 0 && !done) 37 { 38 (*myp)++; /* set breakpoint here */ 39 } 40 41 if (done) 42 usleep (100); /* Some time to make sure we don't mask any bad 43 SIGTRAP handling. */ 44 45 pthread_exit (NULL); 46} 47 48int 49main (int argc, char **argv) 50{ 51 int res; 52 pthread_t *threads; 53 void *thread_result; 54 long i = 0; 55 56 threads = malloc (THREADS * sizeof (pthread_t)); 57 args = malloc (THREADS * sizeof (unsigned int)); 58 59 for (i = 0; i < THREADS; i++) 60 { 61 args[i] = 1; /* Init value. */ 62 res = pthread_create (&threads[i], 63 NULL, 64 thread_function, 65 (void *) i); 66 } 67 68 for (i = 0; i < THREADS; i++) 69 pthread_join (threads[i], &thread_result); 70 71 exit(EXIT_SUCCESS); 72} 73