1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2009-2014 Free Software Foundation, Inc.
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.
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.
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/>.
18 Check that watchpoints get propagated to all existing threads when the
19 watchpoint is created.
33 #define X_INCR_COUNT 10
36 void *thread_function (void *arg
); /* Function executed by each thread. */
38 pthread_mutex_t x_mutex
;
41 /* Used to hold threads back until watchthreads2.exp is ready. */
48 pthread_t threads
[NR_THREADS
];
51 pthread_mutex_init (&x_mutex
, NULL
);
53 for (i
= 0; i
< NR_THREADS
; ++i
)
55 res
= pthread_create (&threads
[i
],
58 (void *) (intptr_t) i
);
61 fprintf (stderr
, "error in thread %d create\n", i
);
66 for (i
= 0; i
< NR_THREADS
; ++i
)
68 res
= pthread_join (threads
[i
], NULL
);
71 fprintf (stderr
, "error in thread %d join\n", i
);
79 /* Easy place for a breakpoint.
80 watchthreads2.exp uses this to track when all threads are running
81 instead of, for example, the program keeping track
82 because we don't need the program to know when all threads are running,
83 instead we need gdb to know when all threads are running.
84 There is a delay between when a thread has started and when the thread
85 has been registered with gdb. */
93 thread_function (void *arg
)
99 /* Don't start incrementing X until watchthreads2.exp is ready. */
103 for (i
= 0; i
< X_INCR_COUNT
; ++i
)
105 pthread_mutex_lock (&x_mutex
);
107 printf ("Thread %ld changing x %d -> %d\n", (long) arg
, x
, x
+ 1);
108 /* The call to usleep is so that when the watchpoint triggers,
109 the pc is still on the same line. */
110 ++x
; usleep (1); /* X increment. */
111 pthread_mutex_unlock (&x_mutex
);
This page took 0.031469 seconds and 4 git commands to generate.