Parallel execution of two tasks on two threads. - Multi-Threading in Linux - Part 6

preview_player
Показать описание
Parallel execution of two different tasks on two threads. Multi Threading using C language in Linux Environment.
Рекомендации по теме
Комментарии
Автор

Some people were asking me about an issue they were facing in this task where the output of both threads in jumbled up because value taken in scanf in one thread is not entered yet, while printf of other thread is printed on screen.

So yes this happens because order of execution is random. There are two solutions for this.
First is to put sleep of some seconds in main thread between creation of both two (or three) threads to give some delay between them. That delay will allow you to enter value from user while the second thread won't disturb the output. This will keep the execution parallel.
Second solution is to join each thread after creation and then start the other thread, that of course will not be parallel execution.

I'll suggest you to go for first solution.


Reason behind this is, Multi threading actually uses a single core, and it is not actually parallel it just gives you a parallel illusion by really fast context switching. Since it is one core that is running all threads turn by turn, this is bound to happen.
For pure parallel execution we will study multi processing in one of the next classes.

ProgrammingEpitome
Автор

no fcfs and sjf implementation in the playlist. By the way amazing video thankyou

suhaibkhan
Автор

HI Umrah, what about task 4 how to solve it, please post video reference how to create 3 threads and assign every single thread seperate job waiting for ur reply

srkentertainments
Автор

the sounds of river waves are distracting 👿

vamsisaikrishna
join shbcf.ru