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.
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.
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??
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)
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.
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
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
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?
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
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?
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
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
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
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
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).
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.
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
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?
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
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
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
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.
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.
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.
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
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
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.
@@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?
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?