-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpthread_exec.c
More file actions
33 lines (27 loc) · 747 Bytes
/
pthread_exec.c
File metadata and controls
33 lines (27 loc) · 747 Bytes
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
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
/* Threads with context to execution -> Context switching */
/* In this program the threads run in parallel(with context switching) in respect to the cpu scheduler & jobs */
/* At first, the main thread print fewer lines as the text(code->var init) are executed*/
void *ThreadFunc(void *args)
{
int i;
for(i=0;i<25;++i)
{
printf("This is from thread i=%d\n", i);
}
}
int main()
{
pthread_t mythread;
void *thread_result;
int j;
pthread_create(&mythread, NULL, ThreadFunc, NULL);
for(j=0;j<25;++j)
{
printf("This is from parent or main thread j=%d\n", j);
}
pthread_join(mythread, &thread_result);
return 0;
}