Difference between processes and threads

  Рет қаралды 117,052

CodeVault

CodeVault

Күн бұрын

Пікірлер: 110
@thomasl863
@thomasl863 3 жыл бұрын
I love this style of teaching. It's like investigating the functionality of the code instead of having it lectured about conceptually
@codex8797
@codex8797 Жыл бұрын
Bro you are basically my Operating Systems teacher now. You cover all the topics I have seen in class but in a clearer way. Also your videos have helped me with a lot of previous programming classes I took. Thanks so much man, greetings from Brazil.
@kevinzebb
@kevinzebb 6 ай бұрын
pls never stop making vids man, maybe at times it may seem boring or stressful, but you're helping out so much. BITTE!
@CodeVault
@CodeVault 6 ай бұрын
Thanks for the encouragement! I promise I'll make new videos in the future
@nsabesz
@nsabesz 3 жыл бұрын
videos with 200k+ views teach nothing compared to this, you are the best
@ismailcetin3253
@ismailcetin3253 2 жыл бұрын
Hey CodeVault. I came across your lectures in searching for a good resource on Operating Systems and found them very useful. Your explanations are pretty clear and detailed. Thank you and keep up the good work.
@lehisluguer9300
@lehisluguer9300 Ай бұрын
thank you so much.. i really appreciate all your tutorials, everything is well explained and goes to the point.. you're the best 😋
@matthieu9303
@matthieu9303 3 жыл бұрын
Very interesting, very clear. Straight to the essential. That's how every tutorial should be. Thanks.
@teodoravlad3023
@teodoravlad3023 Жыл бұрын
I wouldn't have passed my processes exam without you and now I have a threads exam. Thank you!
@ojussinghal2501
@ojussinghal2501 2 жыл бұрын
The most underrated channel on youtube
@dmbdwn
@dmbdwn 10 ай бұрын
this channel is proof not all heroes wear capes.
@adi11cr7
@adi11cr7 3 жыл бұрын
Really comfortable with the way you teach. Please do a video on dining philsopher problem
@marianaaa24
@marianaaa24 Жыл бұрын
This was such a cool video, I finished your Processes video list and now getting through this one :) Thank you!!
@silviudinca6501
@silviudinca6501 3 жыл бұрын
You are explaining so well man. Im understand so good this concepts.
@stephenjames5745
@stephenjames5745 3 жыл бұрын
This was an excellent explanation. Thank you!
@RushikeshDhekare1989
@RushikeshDhekare1989 3 жыл бұрын
You are so damn underrated. Tomorrow I have an OS lab exam. Hugee help. Thanks and keep up the good work.
@Анастасиядр-п2п
@Анастасиядр-п2п 3 жыл бұрын
thank you very much from Moscow, school21 student! You're the best
@gian6725
@gian6725 6 ай бұрын
The best explaination i found so far
@YiniShangguan
@YiniShangguan Жыл бұрын
Thank you soooo much! Always enjoy the lab session after the lecture and this video explains the concept so well in practice!
@ivanphoenix8064
@ivanphoenix8064 3 жыл бұрын
This is just worth every single second, ty man, quality content every single time! You just got a subscriber.
@seymanurkaraoglan9888
@seymanurkaraoglan9888 3 жыл бұрын
made it easy to explain this subject in practice thanks from Turkey ❤❤
@AloneInTheSummer
@AloneInTheSummer 3 жыл бұрын
What a guy! Thank you for these videos.
@thodoriskalliontzis1193
@thodoriskalliontzis1193 23 күн бұрын
Very good video!! I have a question on how do you manage the programm with sys/wait.h sys/types.h, becasue im getting a fatal error on my windows compiler. I ve searched it online and i found that these libraries are for macOS and Unix
@CodeVault
@CodeVault 22 күн бұрын
Yes, the processes and threads playlists are only for Unix-like systems. Doesn't work natively on Windows
@sony1979iq
@sony1979iq 3 жыл бұрын
i hoped that i saw your series before i took the exam :(, very nice explanation thumbs up
@stack.1
@stack.1 6 күн бұрын
For accessing variables accross threads shouldn't that be limited to stuff created on heap?
@khomo12
@khomo12 2 күн бұрын
Nice! Thank you!
@matyasmarkkovacs8336
@matyasmarkkovacs8336 Жыл бұрын
Good tutorial, but I have a few questions. When to use which one? Do threads and processes have anything to do with my CPU cores and CPU threads? How many threads and processes can I create on a 4 core CPU?
@CodeVault
@CodeVault Жыл бұрын
The operating systems have been coded in such a way that threads and processes are an abstraction and you have to care about the underlying hardware. The limit of how many threads and processes is determined by the operating system as well. From here you can Google the exact numbers and more details about them. For example here are the limits for Windows: techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-processes-and-threads/ba-p/723824
@matyasmarkkovacs8336
@matyasmarkkovacs8336 Жыл бұрын
@@CodeVault Thank you for the information!
@Sdirimohamedsalah
@Sdirimohamedsalah Жыл бұрын
Operating system runs processes and identify them by an ID each process can contain a set of instructions.. eg threads, functions …
@navidnouri151
@navidnouri151 3 жыл бұрын
Thank you!
@turki8542
@turki8542 3 жыл бұрын
you are the best!literally
@marcophono3434
@marcophono3434 2 жыл бұрын
Thank you so much for your teaching! i learned a lot watching them!!
@bsgamer5069
@bsgamer5069 4 жыл бұрын
❤️your explanation is awesome
@suhass5979
@suhass5979 2 жыл бұрын
I have a doubt, so tell me what I have understood is correct or not 1. In processes only one can execute at a time, so even when we use fork system call the parent or child either one of them can execute at a particular point of time/stay in the running state and they do context switching to achieve multiprogramming 2. But in the case of threads they can execute simultaneously and use the multithreaded CPU cores Is this correct sir??
@CodeVault
@CodeVault Жыл бұрын
No. Both can execute simultaneously
@duanakshbandi6494
@duanakshbandi6494 3 жыл бұрын
Amazing as always
@AMSHASH-xw7lt
@AMSHASH-xw7lt 3 жыл бұрын
Simply Amazing !!!!! What text editor did you use that allow you to split your screen into three sections ?
@CodeVault
@CodeVault 3 жыл бұрын
Visual Studio Code
@DINO5551000
@DINO5551000 2 жыл бұрын
When you said the other thread sees the changes to x, I immediately had to think about, what if the thread running the incrementing didn't finish first, but rather the second thread finishes, the one that just sleeps and prints the value of x, the value of x wouldn't have been incremented yet due to the first thread not having finished yet? I suppose pthread_join makes sure that the threads run in order by waiting on the first thread and then the second with join so the question I thought about is irrelevant, right?
@CodeVault
@CodeVault 2 жыл бұрын
It's not at all irrelevant. You're asking the right question. Multi-threaded programming could become unpredictable based on the order of execution of the threads themselves. As programmers we don't want that, it would be chaos. In this playlist we actually take a look at tools that make multi-threaded programs predictable again (mutexes, barriers, semaphores etc.). And teaching you how to make such programs predictable is one of the goals of these videos
@dimadem
@dimadem 5 ай бұрын
thank you so much
@ivanmoren3643
@ivanmoren3643 2 жыл бұрын
Right, and if x had the storage class _Thread_local (c11) it wouldn't change in the threads example either?
@CodeVault
@CodeVault 2 жыл бұрын
Yea, exactly
@yasminamran5
@yasminamran5 3 жыл бұрын
Ypur vedios are great. Would you fo one about processe I anffinity?
@CodeVault
@CodeVault 3 жыл бұрын
I'll look into it
@stefansilverio245
@stefansilverio245 3 жыл бұрын
how do you get to work with mingw?
@stefansilverio245
@stefansilverio245 3 жыл бұрын
did you port the header file over somehow? or are you using cygwin? or is this on linux?
@CodeVault
@CodeVault 3 жыл бұрын
It's on Linux. I have a video on how I'm actually running my code here: code-vault.net/lesson/tv93s6yw9r:1610568955955
@yazou4564
@yazou4564 Жыл бұрын
best vdieo ever!
@booksvip8273
@booksvip8273 6 ай бұрын
Bro you're amazing keep going and don't stop making new vids
@meleearcher7684
@meleearcher7684 3 жыл бұрын
Thanks for the tutorial about pthread and it helps me a lot; I have a question with regards to sleep() when you are showing that threads are sharing memory; what does it do to the threads? If the sleep function is not added, it does not seem to be showing the results as the one with it. why does it happen like that? Thanks.
@CodeVault
@CodeVault 3 жыл бұрын
Ahh, I just wanted for the second thread to wait until that x++ in the other thread is executed. There are better ways, of course, but I don't want to overcomplicate things right in the beginning
@meleearcher7684
@meleearcher7684 3 жыл бұрын
@@CodeVault Got it. Thanks so much for your answer. Please continue making tutorials about C. You are great !
@vincegelo4495
@vincegelo4495 2 жыл бұрын
I have a question, what’s the difference between a usual function call and a thread call, where both calls follow the same code implementation. Moreover, is a function call faster than thread call? Given that in the process only one thread is created.
@CodeVault
@CodeVault 2 жыл бұрын
There's a bit of an overhead when creating a thread... so usually you want to create a set of threads at the beginning of the process and use them until the process finishes execution. For sure simply calling a function is going to be faster
@mittyouness9163
@mittyouness9163 2 жыл бұрын
I have a question: so how useful threads are, or what's the benefits of using threads and not just calling a function(its seem more faster than creating threads)?, and thank u for your BiiiG effort doing us like those videos
@CodeVault
@CodeVault 2 жыл бұрын
It's to take advantage of all of your computer's processes. Nowadays you hear a lot of computers with CPUs of 4, 8 or even 16 cores. Well, each core can basically run a thread at a time. Say, you have a 4 core CPU: If you only use the main thread for your program at *most* you can use 1 core of that CPU (that's 25% of your total processing power). With 4 threads you could use all 100% of it
@brightlyricsmusic
@brightlyricsmusic 3 жыл бұрын
sir please upload more videos pleaseeeeee
@kk3528
@kk3528 3 жыл бұрын
Very good 🙏👌
@ZebedeusZwalper
@ZebedeusZwalper Жыл бұрын
Superb series ! However, I have a question:At time 4min25 you show that these threads have the same PID numbers But if I run htop in Linux, I see a different unique number for each thread? Any ideas?
@CodeVault
@CodeVault Жыл бұрын
Threads are treated as processes in Linux. It's quite technical and I don't want to explain things wrongly but you can research more on the manual files of pthread: man7.org/linux/man-pages/man7/pthreads.7.html
@ZebedeusZwalper
@ZebedeusZwalper Жыл бұрын
Thanks, will have a look. The main thing is that my code works.
@MrTega1975
@MrTega1975 2 жыл бұрын
but from the point of view of operating system process (parent thread) or threads (childs) are the same thing?
@CodeVault
@CodeVault 2 жыл бұрын
No. An operating system will see multiple threads as just one process. While, with processes, the os will actually see multiple processes. This is important, for example, when forcefully terminating a process. If it's only using thread, you only need to terminate that one process, if it's using multiple processes you will have to terminate each one individually
@somnath2536
@somnath2536 3 жыл бұрын
one question..you have taken x as global data to threads and in case of process it is local to main. how things works if thread is having local variable(X).
@CodeVault
@CodeVault 3 жыл бұрын
That would be local to every thread, and thus each thread would be modifying its own x variable
@georgechacko4793
@georgechacko4793 3 жыл бұрын
How can we conclude on a decision regarding the usage of fork() or threads during design.. what all criteria we need to consider as part of choosing fork() or threads
@CodeVault
@CodeVault 3 жыл бұрын
I guess it mostly depends on how independent you want your processes/threads to be. If a process crashes and you want everything else to still work, you'd have to use processes, for example. Other considerations are memory usage (each process has its own memory while threads can easily share the same memory space), bandwidth... usually, with processes you want a message-based data sharing mechanism (like with pipes) and concurrency if those processes/threads are distributed, how many things doyou need synchronized? It's much more difficult to synchronize processes than it is threads.
@georgechacko4793
@georgechacko4793 3 жыл бұрын
@@CodeVault thanks a lot for your support
@fernandaeschallots2485
@fernandaeschallots2485 3 жыл бұрын
thx! You're the best
@dijkstra4678
@dijkstra4678 2 жыл бұрын
This is great
@antarbasu5342
@antarbasu5342 3 жыл бұрын
Great Video. I am joining discord today
@rachedbennasr2394
@rachedbennasr2394 3 жыл бұрын
But why would we ever need to return the values from threads then if they modify the variable in the main scope?
@CodeVault
@CodeVault 3 жыл бұрын
Depends how you want to use it. Usually you can simply assign the result to a global array but, if you want to change something in the caller function's memory then returning is also an option.
@rachedbennasr2394
@rachedbennasr2394 3 жыл бұрын
Alright that makes sense Thank you
@abhaygaikwad6251
@abhaygaikwad6251 2 жыл бұрын
understood
@bamberghh1691
@bamberghh1691 3 жыл бұрын
Aren't processes and threads both created with the clone syscall?
@CodeVault
@CodeVault 3 жыл бұрын
From what I can tell, clone creates a new process (doesn't create a thread). www.man7.org/linux/man-pages/man2/clone.2.html
@persia5195
@persia5195 4 ай бұрын
Can I run this program on windows?
@CodeVault
@CodeVault 2 ай бұрын
If you find the pthread library compatible with Windows, yes
@Codality
@Codality 2 жыл бұрын
THE BEST
@nischalsehrawat2130
@nischalsehrawat2130 3 жыл бұрын
Hi where would you use a process and where would you use threads?
@CodeVault
@CodeVault 3 жыл бұрын
If you want to do any computing in parallel you would usually use threads. If you need to execute certain other programs within your program you would use processes.
@nischalsehrawat2130
@nischalsehrawat2130 3 жыл бұрын
@@CodeVault Hi, I was watching another video and there the presenter said that multi-threading is used for IO intensive task such as reading, writing data and multi processing would be used for processor intensive task such as computations. But I didn't fully understand it. Is it correct what he was saying?
@CodeVault
@CodeVault 3 жыл бұрын
No, that's not at all correct. Both can be used for processor and IO intensive tasks. Can you send the video to me? Maybe he meant this in a specific situation?
@nischalsehrawat2130
@nischalsehrawat2130 3 жыл бұрын
@@CodeVault kzbin.info/www/bejne/nHzPY32NlNalqdE
@nischalsehrawat2130
@nischalsehrawat2130 3 жыл бұрын
somewhere around timestamp 39:50
@ReactCode0
@ReactCode0 Жыл бұрын
sir my vs code not run pthread process
@CodeVault
@CodeVault Жыл бұрын
You need to add -pthread as argument to gcc in the build.json file
@kubraaksu733
@kubraaksu733 2 жыл бұрын
why fork did not give the result 0?
@CodeVault
@CodeVault 2 жыл бұрын
It did for the child process. Although here I am outputting the process ID which is not the same as what fork() returns
@kubraaksu733
@kubraaksu733 2 жыл бұрын
@@CodeVault i get it, thank you for answer!!
@satviksharma6102
@satviksharma6102 2 жыл бұрын
I have a doubt .... In thread code you have declared x globally and in process x was declared locally , so if x was declared globally in process function its value would have changed after incrementing
@CodeVault
@CodeVault 2 жыл бұрын
It wouldn't have changed since processes don't share memory (even global memory)
@satviksharma6102
@satviksharma6102 2 жыл бұрын
@@CodeVault Thank you this has been a great learning experience
@anushkapopalghat3941
@anushkapopalghat3941 Жыл бұрын
The sys/wait header file is not working on my IDE. It shows the error "cannot open source file "sys/wait.h"C/C++(1696)". Can anyone help me with this? I've tried downloading the library from linux, but that's not working either.
@CodeVault
@CodeVault Жыл бұрын
What I'm showing here only works on Linux (and MacOS). You will need to install something like WSL for Windows
@shaharrefaelshoshany9442
@shaharrefaelshoshany9442 2 жыл бұрын
best
@ansharora3248
@ansharora3248 2 жыл бұрын
Didn't know Jesus looked like this.
@דניאל-ט9ד
@דניאל-ט9ד Жыл бұрын
Summary Thread share memory, and they in the same process. to make two processes you have to fork one, to make two threads you have to make two threads. This kind of unfair video because the diffrences are huge, and you covered only small part of it. (it's not mentioned)
@matzacomn
@matzacomn Жыл бұрын
Cred ca esti roman :))) Haha, facui putin stalking Daca da, sa-ti dea Dumnezeu sanatate ca nu mai este NIMENI pe net sa explice lucrurile astea atat de bine si nici la facultate (in US) nu ne explica, nici in cartile recomandate nu gasim cine stie ce :))))) Nu pot sa cred, haha
@CodeVault
@CodeVault Жыл бұрын
Mersi. Da, sunt roman. Era foarte greu de inteles modul in care se explica la facultate. Tot timpul mergeau prea in detaliu si se bazau prea mult pe teorie. Fix de asta am facut aceste video-uri
@matzacomn
@matzacomn Жыл бұрын
@@CodeVault Suntem multi in grupa care ne uitam la videoclipurile tale. Numai bine si succes in tot!
@kiseijuu7420
@kiseijuu7420 4 ай бұрын
is it better to fork and creat threads in the fork, or creat a thread and fork in that thread?
@CodeVault
@CodeVault 2 ай бұрын
You can simply create threads without forking and fork without creating threads. Those are two distinct scenarios, I doubt it makes any sense to compare the two
@kiseijuu7420
@kiseijuu7420 2 ай бұрын
@@CodeVault yeah but both of them creat like a new path, like is it better to creat a thread in a fork or to fork in a thread
What are Race Conditions?
13:09
CodeVault
Рет қаралды 96 М.
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,2 МЛН
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 4 МЛН
Communicating between processes (using pipes) in C
14:00
CodeVault
Рет қаралды 286 М.
FANG Interview Question | Process vs Thread
3:51
ByteByteGo
Рет қаралды 343 М.
How to pass arguments to threads in C
13:52
CodeVault
Рет қаралды 82 М.
How to create threads in a loop (pthread_create)
8:50
CodeVault
Рет қаралды 89 М.
Process IDs in C
10:14
CodeVault
Рет қаралды 95 М.
What is a mutex in C? (pthread_mutex)
9:18
CodeVault
Рет қаралды 169 М.
Producer - Consumer Problem in Multi-Threading
25:18
CodeVault
Рет қаралды 116 М.
Practical use case for fork and pipe in C
12:52
CodeVault
Рет қаралды 82 М.