source: CIVL/examples/pthread/bug2.cvl@ 068c228

1.23 2.0 main test-branch
Last change on this file since 068c228 was 9f23e8b, checked in by John Edenhofner <johneden@…>, 12 years ago

Added bug fix programs and some documentation

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

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/******************************************************************************
2* FILE: bug2.cvl
3* DESCRIPTION:
4* A "hello world" Pthreads program that dumps core. Figure out why and
5* then fix it - or else see the solution bug2fix.c.
6* AUTHOR: 9/98 Blaise Barney
7* LAST REVISED: 01/29/09
8******************************************************************************/
9#include "pthread.cvh"
10#include <civlc.h>
11#include <stdio.h>
12#include <stdlib.h>
13#define NTHREADS 8
14#define ARRAY_SIZE 500000
15
16void *Hello(void *threadid)
17{
18 double A[ARRAY_SIZE];
19 int i;
20 long tid = (long)*threadid;
21 //sleep(3);
22 for (i=0; i<ARRAY_SIZE; i++)
23 {
24 A[i] = i * 1.0;
25 }
26 printf("%d: Hello World! %f\n", tid, A[ARRAY_SIZE-1]);
27 pthread_exit(NULL);
28}
29
30int main(int argc, char *argv[])
31{
32pthread_t threads[NTHREADS];
33size_t stacksize;
34pthread_attr_t attr;
35int rc;
36long t;
37pthread_attr_init(&attr);
38pthread_attr_getstacksize (&attr, &stacksize);
39printf("Thread stack size = %d bytes (hint, hint)\n",stacksize);
40for(t=0;t<NTHREADS;t++){
41 rc = pthread_create(&threads[t], NULL, Hello, (void *)&t);
42 if (rc){
43 printf("ERROR; return code from pthread_create() is %d\n", rc);
44 exit(-1);
45 }
46 }
47printf("Created %d threads.\n", t);
48pthread_exit(NULL);
49return 0;
50}
51
Note: See TracBrowser for help on using the repository browser.