]>
| Commit | Line | Data |
|---|---|---|
| ae7dc4d8 | 1 | /* Pthreads test program. |
| d01e8234 | 2 | Copyright 1996-2025 Free Software Foundation, Inc. |
| ae7dc4d8 MC |
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 | |
| a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
| ae7dc4d8 | 13 | (at your option) any later version. |
| a9762ec7 | 14 | |
| ae7dc4d8 MC |
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. | |
| a9762ec7 | 19 | |
| ae7dc4d8 | 20 | You should have received a copy of the GNU General Public License |
| a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| ae7dc4d8 | 22 | |
| d1a2f204 | 23 | #include <stdio.h> |
| 5a2e8882 | 24 | #include <stdlib.h> |
| d1a2f204 | 25 | #include <pthread.h> |
| 37bc665e | 26 | #include <unistd.h> |
| d1a2f204 | 27 | |
| d1a2f204 KS |
28 | void * |
| 29 | routine (void *arg) | |
| 30 | { | |
| 2fe4e8d0 MC |
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 | ||
| d1a2f204 KS |
39 | printf ("hello thread\n"); |
| 40 | } | |
| 41 | ||
| 42 | /* Marker function for the testsuite */ | |
| 43 | void | |
| 44 | done_making_threads (void) | |
| 45 | { | |
| 46 | /* Nothing */ | |
| 06ded8b8 | 47 | } |
| d1a2f204 KS |
48 | |
| 49 | void | |
| 50 | create_thread (void) | |
| 51 | { | |
| 52 | pthread_t tid; | |
| 53 | ||
| 3ca22649 | 54 | if (pthread_create (&tid, NULL, routine, (void *) 0xfeedface)) |
| d1a2f204 KS |
55 | { |
| 56 | perror ("pthread_create 1"); | |
| 57 | exit (1); | |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 61 | int | |
| 62 | main (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 | } |