source: CIVL/examples/pthread/bug5.cvl@ 4b4bbb3

1.23 2.0 main test-branch
Last change on this file since 4b4bbb3 was 38374b7, checked in by John Edenhofner <johneden@…>, 12 years ago

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@984 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/******************************************************************************
2* FILE: bug5.c
3* DESCRIPTION:
4* A simple pthreads program that dies before the threads can do their
5* work. Figure out why.
6* AUTHOR: 07/06/05 Blaise Barney
7* LAST REVISED: 07/11/12
8******************************************************************************/
9#include "pthread.cvh"
10#include <civlc.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <math.h>
14#define NUM_THREADS 5
15
16void *PrintHello(void *threadid)
17{
18 int i;
19 double myresult=0.0;
20 printf("thread=%ld: starting...\n", threadid);
21 for (i=0; i<1000000; i++)
22 myresult += sin(i) * tan(i);
23 printf("thread=%ld result=%e. Done.\n",threadid,myresult);
24 pthread_exit(NULL);
25}
26
27int main(int argc, char *argv[])
28{
29pthread_t threads[NUM_THREADS];
30int rc;
31long t;
32for(t=0;t<NUM_THREADS;t++){
33 printf("Main: creating thread %ld\n", t);
34 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
35 if (rc){
36 printf("ERROR; return code from pthread_create() is %d\n", rc);
37 exit(-1);
38 }
39 }
40printf("Main: Done.\n");
41}
42
Note: See TracBrowser for help on using the repository browser.