OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [gdb/] [testsuite/] [gdb.base/] [watch_thread_num.c] - Blame information for rev 341

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.