]>
Commit | Line | Data |
---|---|---|
ce78e7c3 | 1 | /* |
6aba47ca | 2 | * Copyright (C) 2004, 2007 Free Software Foundation, Inc. |
ce78e7c3 MI |
3 | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
18 | * This file was written by Steve Munroe. (sjmunroe@us.ibm.com) | |
19 | * Test break points and single step on thread functions. | |
20 | */ | |
21 | ||
22 | #include <string.h> | |
23 | #include <unistd.h> | |
24 | #include <pthread.h> | |
25 | #include <stdlib.h> | |
26 | #include <stdio.h> | |
27 | #include <errno.h> | |
28 | ||
29 | #define N 2 | |
30 | ||
31 | static void * | |
32 | tf (void *arg) | |
33 | { | |
34 | int n = (int) (long int) arg; | |
35 | char number[160]; | |
36 | int unslept = 10; | |
37 | ||
38 | sprintf(number, "tf(%ld): begin", (long)arg); | |
39 | puts (number); | |
40 | ||
41 | while (unslept > 0) | |
42 | unslept = sleep(unslept); | |
43 | ||
44 | sprintf(number, "tf(%ld): end", (long)arg); | |
45 | puts (number); | |
46 | return NULL; | |
47 | } | |
48 | ||
49 | int main (int argc, char *argv[]) | |
50 | { | |
51 | int n; | |
52 | int unslept = 2; | |
53 | pthread_t th[N]; | |
54 | ||
55 | for (n = 0; n < N; ++n) | |
56 | if (pthread_create (&th[n], NULL, tf, (void *) (long int) n) != 0) | |
57 | { | |
58 | while (unslept > 0) | |
59 | unslept = sleep(2); | |
60 | puts ("create failed"); | |
61 | exit (1); | |
62 | } | |
63 | ||
64 | puts("after create"); | |
65 | ||
66 | for (n = 0; n < N; ++n) | |
67 | if (pthread_join (th[n], NULL) != 0) | |
68 | { | |
69 | puts ("join failed"); | |
70 | exit (1); | |
71 | } | |
72 | ||
73 | puts("after join"); | |
74 | return 0; | |
75 | } |