Program to create Threads in Linux || pthread_create()

preview_player
Показать описание
In this lecture on Program to Create Threads in Linux you will learn how to write a program using C language in Linux to create threads. The function required is pthread_create( ) which takes four parameters.


Reference Videos:

Tools Required:
1. Linux environment
2. Basic knowledge of C Language
3. gcc compiler installed

Other Playlists:

Was this tutorial about the Program on Creating Threads helpful? If so, please share. Let me know your thoughts in the comments.

#linux #oslab #os #threads
Рекомендации по теме
Комментарии
Автор

//Incase someone is too lazy to write the program
#include<stdio.h>
#include<unistd.h>
#include<pthread.h>
void *thread_fun(void *arg);
int main()
{
pthread_t thread1;
pthread_create(&thread1, NULL, thread_fun, NULL);
pthread_join(thread1, NULL);
printf("Back to main process\n");
for(int i=15;i<20;i++)
{
printf("%d\n", i);
sleep(1);
}
return 0;
}
void *thread_fun(void *arg){
printf("Inside thread\n");
for(int j=0;j<5;j++)
{
printf("%d\n", j);
sleep(1);
}
}

ano
Автор

Your videos are really good to understand in a easy way about the topic....❣️

arpandatta
Автор

very very good sir...as always...kindly upload more such examples

aninditasaha
Автор

the easiest and the best explaination out there . Suuupper easy boi . Loved this. 🫡🫡

KushagraJain-fcnt
Автор

Finally got the Answer! Thanks a lot!

pramudithjayasekra
Автор

Enjoyed this, nice way of explaination

MagicianSaransh
Автор

upload more about threads used in sockets in c language

technotech
Автор

"undefined reference to `pthread_create' " i am getting this error

AnkitSharma-csrn
Автор

How to create multiple threads for solving a group of operations, distribute the load and execute it parallelly so that the execution time is reduced

agpskalaparipaadeex
Автор

when commented i am getting this output:
Inside the driver program
0
INside the thread
0
1
2
3
4

what is the reason?

muhammadtaimourafzal
Автор

#include<stdio.h>
#include<pthread.h>
#include<unistd.h>

int sum;
int i, j;
void *thread_function(int *arg)
{
printf("IN thread\n");
for(j=20;j<25;j++)
{
printf("%d\n", j);
sleep(1);
}
sum=arg[0]+arg[1];
printf("sum in thread:%d\n", sum);
pthread_exit(sum);
}

int main()
{
pthread_t a_thread;
int num[2]={1, 2};
void *sum_main;
pthread_create(&a_thread, NULL, thread_function, num);
pthread_join(a_thread, &sum_main);
printf("In main\n");

for(i=0;i<5;i++)
{
printf("%d\n", i);
sleep(1);
}
printf("In main sum:%d\n", (int*)sum_main);
}

Mounika-vrvq