-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTestWithArgs.cpp
More file actions
45 lines (40 loc) · 1.13 KB
/
createTestWithArgs.cpp
File metadata and controls
45 lines (40 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define NUM_THREADS 8
const char *messages[NUM_THREADS];
void *PrintHello(void *threadid)
{
long taskid;
sleep(1);
taskid = (long)threadid;
printf("thread %ld: %s\n", taskid, messages[taskid]);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
long taskids[NUM_THREADS];
int rc, t;
messages[0] = "English: Hello World!";
messages[1] = "French: Bonjour, le monde!";
messages[2] = "Spanish: Hola al mundo";
messages[3] = "Klingon: Nuq neH!";
messages[4] = "German: Guten Tag, Welt!";
messages[5] = "Russian: Zdravstvuy, mir!";
messages[6] = "Japan: Sekai e konnichiwa!";
messages[7] = "Latin: Orbis, te saluto!";
for (t = 0; t < NUM_THREADS; t++)
{
taskids[t] = t;
printf("Creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)taskids[t]);
if (rc)
{
printf("ERROR: return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}