-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path006.c
More file actions
37 lines (32 loc) · 960 Bytes
/
006.c
File metadata and controls
37 lines (32 loc) · 960 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
34
35
36
37
/*
..........................................................................................................................................
Name : 006.c
Author : SHRUTI VERMA
Description : Write a simple program to create three threads.
Date : 29 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<pthread.h>
void* fthread(void* arg) {
int id = *(int*)arg;
printf("thread %d created\n", id);
return NULL;
}
int main() {
pthread_t threads[3];
int ids[3] = {1, 2, 3};
for(int i=0; i<3; i++) {
pthread_create(&threads[i], NULL, fthread, &ids[i]);
}
for(int i=0; i<3; i++) {
pthread_join(threads[i], NULL);
}
}
/*-------------------------------------OUTPUT------------------------------
thread 1 created
thread 3 created
thread 2 created
*/