main
test-branch
|
Last change
on this file since e2570cd 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
|
| Line | |
|---|
| 1 | #ifdef _CIVL
|
|---|
| 2 | #include <civlc.cvh>
|
|---|
| 3 | #endif
|
|---|
| 4 | /*****************************************************************************
|
|---|
| 5 | * FILE: bug3.c
|
|---|
| 6 | * DESCRIPTION:
|
|---|
| 7 | * This "hello world" Pthreads program demonstrates an unsafe (incorrect)
|
|---|
| 8 | * way to pass thread arguments at thread creation. Compare with hello_arg1.c.
|
|---|
| 9 | * AUTHOR: Blaise Barney
|
|---|
| 10 | * LAST REVISED: 01/29/09
|
|---|
| 11 | ******************************************************************************/
|
|---|
| 12 | #include <pthread.h>
|
|---|
| 13 | #include <stdio.h>
|
|---|
| 14 | #include <stdlib.h>
|
|---|
| 15 | #define NUM_THREADS 2
|
|---|
| 16 |
|
|---|
| 17 | void *PrintHello(void *threadid)
|
|---|
| 18 | {
|
|---|
| 19 | long taskid = *((long*)threadid);
|
|---|
| 20 | //sleep(1);
|
|---|
| 21 | printf("Hello from thread %ld\n", taskid);
|
|---|
| 22 | #pragma CIVL $assert((taskid != NUM_THREADS));
|
|---|
| 23 | pthread_exit(NULL);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | int main(int argc, char *argv[])
|
|---|
| 27 | {
|
|---|
| 28 | pthread_t threads[NUM_THREADS];
|
|---|
| 29 | int rc;
|
|---|
| 30 | long t;
|
|---|
| 31 |
|
|---|
| 32 | for(t=0;t<NUM_THREADS;t++) {
|
|---|
| 33 | printf("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 | }
|
|---|
| 40 |
|
|---|
| 41 | pthread_exit(NULL);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.