]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/thread-specific.c
* configure.ac: Switch license to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / thread-specific.c
CommitLineData
c47cebdb
DJ
1/* This testcase is part of GDB, the GNU debugger.
2
6aba47ca 3 Copyright 2004, 2007 Free Software Foundation, Inc.
c47cebdb
DJ
4
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 2 of the License, or
8 (at your option) any later version.
9
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.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <stdio.h>
21#include <unistd.h>
22#include <stdlib.h>
23#include <pthread.h>
24
25void *thread_function(void *arg);
26
27unsigned int args[1];
28
29int main() {
30 int res;
31 pthread_t threads[2];
32 void *thread_result;
33 long i = 1;
34
35 args[0] = 1;
36 res = pthread_create(&threads[0],
37 NULL,
38 thread_function,
39 (void *) 0);
40
41 /* thread-specific.exp: last thread start. */
42 args[1] = 1;
43
44 /* Don't run forever. Run just short of it :) */
45 while (i > 0)
46 {
47 /* thread-specific.exp: main loop. */
48 (i) ++;
49 }
50
51 exit(EXIT_SUCCESS);
52}
53
54void *thread_function(void *arg) {
55 int my_number = (long) arg;
e5b25496 56 int *myp = (int *) &args[my_number];
c47cebdb
DJ
57
58 /* Don't run forever. Run just short of it :) */
59 while (*myp > 0)
60 {
61 /* thread-specific.exp: thread loop. */
62 (*myp) ++;
63 }
64
65 pthread_exit(NULL);
66}