Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: gdb/testsuite/gdb.threads/fork-thread-pending.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* This testcase is part of GDB, the GNU debugger. 1 /* This testcase is part of GDB, the GNU debugger.
2 2
3 Copyright 2008-2012 Free Software Foundation, Inc. 3 Copyright 2008-2012 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
(...skipping 10 matching lines...) Expand all
21 #include <stdio.h> 21 #include <stdio.h>
22 #include <stdlib.h> 22 #include <stdlib.h>
23 #include <errno.h> 23 #include <errno.h>
24 #include <unistd.h> 24 #include <unistd.h>
25 #include <sys/types.h> 25 #include <sys/types.h>
26 #include <sys/wait.h> 26 #include <sys/wait.h>
27 27
28 #define NUMTHREADS 10 28 #define NUMTHREADS 10
29 29
30 volatile int done = 0; 30 volatile int done = 0;
31 static pthread_barrier_t barrier;
31 32
32 static void * 33 static void *
33 start (void *arg) 34 start (void *arg)
34 { 35 {
35 while (!done) 36 while (!done)
36 usleep (100); 37 usleep (100);
37 assert (0); 38 assert (0);
38 return arg; 39 return arg;
39 } 40 }
40 41
41 void * 42 void *
42 thread_function (void *arg) 43 thread_function (void *arg)
43 { 44 {
44 int x = * (int *) arg; 45 int x = * (int *) arg;
45 46
46 printf ("Thread <%d> executing\n", x); 47 printf ("Thread <%d> executing\n", x);
47 48
49 pthread_barrier_wait (&barrier);
50
48 while (!done) 51 while (!done)
49 usleep (100); 52 usleep (100);
50 53
51 return NULL; 54 return NULL;
52 } 55 }
53 56
54 void * 57 void *
55 thread_forker (void *arg) 58 thread_forker (void *arg)
56 { 59 {
57 int x = * (int *) arg; 60 int x = * (int *) arg;
58 pid_t pid; 61 pid_t pid;
59 int rv; 62 int rv;
60 int i; 63 int i;
61 pthread_t thread; 64 pthread_t thread;
62 65
63 printf ("Thread forker <%d> executing\n", x); 66 printf ("Thread forker <%d> executing\n", x);
64 67
68 pthread_barrier_wait (&barrier);
69
65 switch ((pid = fork ())) 70 switch ((pid = fork ()))
66 { 71 {
67 case -1: 72 case -1:
68 assert (0); 73 assert (0);
69 default: 74 default:
70 wait (&rv); 75 wait (&rv);
71 done = 1; 76 done = 1;
72 break; 77 break;
73 case 0: 78 case 0:
74 i = pthread_create (&thread, NULL, start, NULL); 79 i = pthread_create (&thread, NULL, start, NULL);
75 assert (i == 0); 80 assert (i == 0);
76 i = pthread_join (thread, NULL); 81 i = pthread_join (thread, NULL);
77 assert (i == 0); 82 assert (i == 0);
78 83
79 assert (0); 84 assert (0);
80 } 85 }
81 86
82 return NULL; 87 return NULL;
83 } 88 }
84 89
85 int 90 int
86 main (void) 91 main (void)
87 { 92 {
88 pthread_t threads[NUMTHREADS]; 93 pthread_t threads[NUMTHREADS];
89 int args[NUMTHREADS]; 94 int args[NUMTHREADS];
90 int i, j; 95 int i, j;
91 96
97 i = pthread_barrier_init (&barrier, NULL, NUMTHREADS);
98 assert (i == 0);
99
92 /* Create a few threads that do mostly nothing, and then one that 100 /* Create a few threads that do mostly nothing, and then one that
93 forks. */ 101 forks. */
94 for (j = 0; j < NUMTHREADS - 1; ++j) 102 for (j = 0; j < NUMTHREADS - 1; ++j)
95 { 103 {
96 args[j] = j; 104 args[j] = j;
97 pthread_create (&threads[j], NULL, thread_function, &args[j]); 105 pthread_create (&threads[j], NULL, thread_function, &args[j]);
98 } 106 }
99 107
100 args[j] = j; 108 args[j] = j;
101 pthread_create (&threads[j], NULL, thread_forker, &args[j]); 109 pthread_create (&threads[j], NULL, thread_forker, &args[j]);
102 110
103 for (j = 0; j < NUMTHREADS; ++j) 111 for (j = 0; j < NUMTHREADS; ++j)
104 { 112 {
105 pthread_join (threads[j], NULL); 113 pthread_join (threads[j], NULL);
106 } 114 }
107 115
108 return 0; 116 return 0;
109 } 117 }
OLDNEW
« no previous file with comments | « gdb/testsuite/gdb.threads/fork-child-threads.exp ('k') | gdb/testsuite/gdb.threads/fork-thread-pending.exp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698