]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/watch_thread_num.c
* Makefile.in gdb.ada/gnat_ada.gpr, gdb.base/gcore-buffer-overflow.c,
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / watch_thread_num.c
CommitLineData
37e4754d
LM
1/* This testcase is part of GDB, the GNU debugger.
2
0fb0cc75 3 Copyright 2002, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
37e4754d 4
d53a7b30
JB
5 Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003, 2007, 2008, 2009
6 Free Software Foundation, Inc.
7
37e4754d
LM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
d53a7b30 10 the Free Software Foundation; either version 3 of the License, or
37e4754d
LM
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
d53a7b30 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
37e4754d
LM
20
21 This file is copied from schedlock.c. */
22
23#include <stdio.h>
24#include <unistd.h>
25#include <stdlib.h>
26#include <pthread.h>
27
28void *thread_function (void *arg); /* Pointer to function executed by each thread */
29
30#define NUM 5
31
32static unsigned int shared_var = 1;
33
34int main () {
35 int res;
36 pthread_t threads[NUM];
37 void *thread_result;
38 long i;
39
40 for (i = 0; i < NUM; i++)
41 {
42 res = pthread_create (&threads[i],
43 NULL,
44 thread_function,
45 (void *) i);
46 }
47
48 thread_result = thread_function ((void *) i);
49
50 exit (EXIT_SUCCESS);
51}
52
53void *thread_function (void *arg) {
54 int my_number = (long) arg;
55 /* Don't run forever. Run just short of it :) */
56 while (shared_var > 0)
57 {
58 shared_var++;
59 usleep (1); /* Loop increment. */
60 }
61
62 pthread_exit (NULL);
63}
64