1/* Pthreads test program. 2 Copyright 1996-2020 Free Software Foundation, Inc. 3 4 Written by Keith Seitz of Red Hat. 5 Copied from gdb.threads/pthreads.c. 6 Contributed by Red Hat. 7 8 This file is part of GDB. 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 3 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 22 23#include <stdio.h> 24#include <stdlib.h> 25#include <pthread.h> 26#include <unistd.h> 27 28void * 29routine (void *arg) 30{ 31 /* When gdb is running, it sets hidden breakpoints in the thread 32 library. The signals caused by these hidden breakpoints can 33 cause system calls such as 'sleep' to return early. Pay attention 34 to the return value from 'sleep' to get the full sleep. */ 35 int unslept = 9; 36 while (unslept > 0) 37 unslept = sleep (unslept); 38 39 printf ("hello thread\n"); 40} 41 42/* Marker function for the testsuite */ 43void 44done_making_threads (void) 45{ 46 /* Nothing */ 47} 48 49void 50create_thread (void) 51{ 52 pthread_t tid; 53 54 if (pthread_create (&tid, NULL, routine, (void *) 0xfeedface)) 55 { 56 perror ("pthread_create 1"); 57 exit (1); 58 } 59} 60 61int 62main (int argc, char *argv[]) 63{ 64 int i; 65 66 /* Create a few threads */ 67 for (i = 0; i < 5; i++) 68 create_thread (); 69 done_making_threads (); 70 71 printf ("hello\n"); 72 printf ("hello\n"); 73 return 0; 74} 75 76