Fork and Pthreads - A Guide To Get You Started with Multiprocessing

  Рет қаралды 8,662

Gary Explains

Gary Explains

Күн бұрын

Most modern multitasking operating systems support process creation, forking, and some kind of threading. In this video I take a look at fork() and POSIX Threads (pthreads) and show you how to start using multiprocessing in your code.
---
You might also want to watch:
Multitasking vs Multithreading vs Multiprocessing - • Multitasking vs Multit...
Dual Core Programming for the Raspberry Pi Pico, ESP32, and ESP32-S3 Using the Arduino IDE - • Dual Core Programming ...
Let Me Explain T-shirt: teespring.com/gary-explains-l...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains

Пікірлер: 48
@petermainwaringsx
@petermainwaringsx Жыл бұрын
I did pass an aptitude test for a job as a "programmer" in the 70's but decided to stay as a radio comms engineer with the post office. All of my coding has been self taught and I do enjoy a bit of code writing but not going beyond VB, Python and some scratch with my grandchildren. I always find your videos so interesting and learn a load of stuff which I'm unlikely to use in my 70+ year old life. I still dip into your videos on encryption as they are undoubtedly the best out there.
@bruhstfuu
@bruhstfuu 5 ай бұрын
so helpful for my operating systems class, thank you!
@GaryExplains
@GaryExplains 5 ай бұрын
Glad it was helpful!
@oraflores
@oraflores Жыл бұрын
Although it may date me -- "Thorin...": The Hobbit. "time passes": Zork I I remember my first exposure to forking years ago when modifying some "C" code to prevent zombies which are orphan children processes. Thank you for your videos. Always a treat to watch.
@peterjansen4826
@peterjansen4826 Жыл бұрын
I am going to type over that code. :)
@mortenlund1418
@mortenlund1418 Ай бұрын
Great video. Thanks.
@GaryExplains
@GaryExplains Ай бұрын
Glad you liked it!
@adrianalanbennett
@adrianalanbennett Жыл бұрын
Thanks so much!
@filker0
@filker0 Жыл бұрын
Before going much farther with threading, you should go over the synchronization primitives like semaphores and mutexes, and also cover thread scheduling priority.
@GaryExplains
@GaryExplains Жыл бұрын
Of course. I have already covered that (in part) in my Arduino dual-core programming video. But I will do a specific video about it for this series.
@cezarcatalin1406
@cezarcatalin1406 Жыл бұрын
Can you do a video on windows process creation and windows threads ? It’s a bit different and most linux people don’t know how it functions.
@GaryExplains
@GaryExplains Жыл бұрын
Yes, if this video is well received then I will do more including looking at the Windows API.
@muddyexport5639
@muddyexport5639 Жыл бұрын
Thanks!
@williamstevenson2649
@williamstevenson2649 Жыл бұрын
OK- I'll play the game: The Hobbit according to Jackson, Part 3. Maybe that's different to the book, which I haven't read. This is very interesting - I don't know anything about C and I'm not about to do any multi - core programming, but at least I now have a vague idea of what it's about
@GaryExplains
@GaryExplains Жыл бұрын
Good guess, but no! The quote is older than the movies.
@Musaafir-ln6feet
@Musaafir-ln6feet Жыл бұрын
I wish you can cover more educational topics in future as you have an extraordinary experience in Computer Science field this would help students like me, who wanna study higher level topis in much detail.
@GaryExplains
@GaryExplains Жыл бұрын
Thanks for the encouragement. Any particular topics you have in mind?
@Musaafir-ln6feet
@Musaafir-ln6feet Жыл бұрын
Topics realted to CUDA programming and High Performance Computing
@GaryExplains
@GaryExplains Жыл бұрын
Have you watched my "supercomputer" videos on this channel?
@jamiemcglynn6600
@jamiemcglynn6600 Жыл бұрын
I have seen so much drumming up about "async" and whatnot, but it always kept me thinking whether it is true multi-tasking or just one core switching too and fro between one execution context to the next. I've always felt that threads was always the way to go because you're not locking execution to specific cores, and the workload scales better the more available cores there are. Yeah, sure, it's harder when race conditions come into play, but, if you have the cores, best put them to work and not have them being couch potatoes. Great video, Gary!
@TimSavage-drummer
@TimSavage-drummer Жыл бұрын
Async is more akin to cooperative multitasking. For workloads that are not CPU intensive or are IO heavy, it can be more efficient. A threaded solution has a lot of overhead if it's spending the majority of its time blocking on IO. Many web applications scale quite well using async when the majority of the processing time is spent essentially stalled waiting for external cache, databases or other external resources. Async can also work well in conjunction with threading. Can await on multiple threaded tasks to complete on the main thread while servicing other requests that may not require an entire thread.
@GaryExplains
@GaryExplains Жыл бұрын
You might like my video on multitasking vs multiprocessing vs multithreading. It is linked in the description.
@jamiemcglynn6600
@jamiemcglynn6600 Жыл бұрын
@@GaryExplains Ah, must have missed that one, thanks!
@justadude8716
@justadude8716 Жыл бұрын
Go language implemented threads in an amazing way using channels, making race conditions a thing of the past!
@GaryExplains
@GaryExplains Жыл бұрын
@@justadude8716 Interesting comment because in my video on goroutines I show how you can easily create a race condition!
@MrFilip121
@MrFilip121 Жыл бұрын
Can you do a video on passing variables between processes/sharing variables(i.e. buffers) between threads? Some sort of interprocess communication
@GaryExplains
@GaryExplains Жыл бұрын
Indeed I will. I have also covered that in my Arduino dual-core programming video.
@KyrychenkoAnton
@KyrychenkoAnton Жыл бұрын
Thanks a lot! Would be great if you plan to make more multicore programming tutorials on actual mcu's like rp2040 or esp32!
@GaryExplains
@GaryExplains Жыл бұрын
I am glad you found it useful. I cover multi core microcontroller programming here kzfaq.info/get/bejne/rZuJnMqb27nFdmg.html and in my video about programming the Pico in C, plus of course my videos about Piccolo OS
@KyrychenkoAnton
@KyrychenkoAnton Жыл бұрын
@@GaryExplains ah, sorry, I saw video you mentioned, in the end you mentioned to comment if we want to see more videos about multicore programming - so I commented of course) I just started browsing your other videos looking for it and ended up here. So sorry, I meant to comment on video you mentioned actually)
@SO-dl2pv
@SO-dl2pv Жыл бұрын
Could you please suggest a book or any other resource to learn more about this topic? thanks :)
@yngvenystrand167
@yngvenystrand167 Жыл бұрын
Gary, is it the game released 1982 for ZX Spectrum? Ported later to TRS-80, and others?
@GaryExplains
@GaryExplains Жыл бұрын
Yes!
@peterjansen4826
@peterjansen4826 Жыл бұрын
On line 48, why does i have to be casted with (* void)(long)?
@GaryExplains
@GaryExplains Жыл бұрын
Because the parameter to a thread is a void * pointer. Basically I convert the integer into a long and then pretend it is a pointer.
@zz3709
@zz3709 Жыл бұрын
Is there a correlation/connection with this and CPU cores and threads?
@GaryExplains
@GaryExplains Жыл бұрын
You might like my video "Multitasking vs Multithreading vs Multiprocessing" it should help answer that question - kzfaq.info/get/bejne/itRgqJB6rqjRpJc.html
@zz3709
@zz3709 Жыл бұрын
Thanks @@GaryExplains ... that was enlightening. Only other thing in testing to figure out is how to intentionally run different tasks in one program, on different cores. I can't do this on embedded devices, but it's there a way to tell day and i5 to use a separate core for a specific task?
@wilsonursua8927
@wilsonursua8927 Жыл бұрын
Hi Gary what happened to your speed test g channel, still hoping you could still test those new phones
@GaryExplains
@GaryExplains Жыл бұрын
Sadly it is on pause. It wasn't popular.
@chuckbiscuito
@chuckbiscuito Жыл бұрын
fork(2): call it once and it returns twice!
@TaureanSmoke
@TaureanSmoke Жыл бұрын
The Hobbit
@GaryExplains
@GaryExplains Жыл бұрын
👍😁
@GaryExplains
@GaryExplains Жыл бұрын
But not the book!
@joakimedholm128
@joakimedholm128 Жыл бұрын
this is so boring
@TaureanSmoke
@TaureanSmoke Жыл бұрын
That's because you're not a real nerd. Get out of here!
@GaryExplains
@GaryExplains Жыл бұрын
🤣🤣🤣 twitter.com/garyexplains/status/1580196280361308160
Piccolo OS: What is Context Switching?
17:56
Gary Explains
Рет қаралды 23 М.
The One BIG Reason to Learn Google's Go Language
17:55
Gary Explains
Рет қаралды 156 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 4,6 МЛН
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 22 МЛН
Multithreading Code - Computerphile
15:54
Computerphile
Рет қаралды 381 М.
Multitasking vs Multithreading vs Multiprocessing
10:30
Gary Explains
Рет қаралды 85 М.
Arm vs RISC V- What You Need to Know
22:19
Gary Explains
Рет қаралды 302 М.
Signals. I spent 2 years to understand this part.
21:24
kimylamp
Рет қаралды 205 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 4,6 МЛН