source: CIVL/examples/pthread/llnl/bug5.c@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[506de9d]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.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <math.h>
13#define NUM_THREADS 5
14
15void *PrintHello(void *threadid)
16{
17 int i;
18 double myresult=0.0;
19 printf("thread=%ld: starting...\n", threadid);
20 for (i=0; i<1000000; i++)
21 myresult += sin(i) * tan(i);
22 printf("thread=%ld result=%e. Done.\n",threadid,myresult);
23 pthread_exit(NULL);
24}
25
26int main(int argc, char *argv[])
27{
28pthread_t threads[NUM_THREADS];
29int rc;
30long t;
31for(t=0;t<NUM_THREADS;t++){
32 printf("Main: creating thread %ld\n", t);
33 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
34 if (rc){
35 printf("ERROR; return code from pthread_create() is %d\n", rc);
36 exit(-1);
37 }
38 }
39printf("Main: Done.\n");
40}
41
Note: See TracBrowser for help on using the repository browser.