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

Sdílet
Vložit
  • čas přidán 7. 08. 2024
  • 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

Komentáře • 48

  • @petermainwaringsx
    @petermainwaringsx Před rokem +11

    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 Před 5 měsíci +1

    so helpful for my operating systems class, thank you!

  • @oraflores
    @oraflores Před rokem +1

    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.

  • @mortenlund1418
    @mortenlund1418 Před měsícem

    Great video. Thanks.

  • @adrianalanbennett
    @adrianalanbennett Před rokem +1

    Thanks so much!

  • @muddyexport5639
    @muddyexport5639 Před rokem +1

    Thanks!

  • @cezarcatalin1406
    @cezarcatalin1406 Před rokem +4

    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  Před rokem +6

      Yes, if this video is well received then I will do more including looking at the Windows API.

  • @peterjansen4826
    @peterjansen4826 Před rokem

    I am going to type over that code. :)

  • @filker0
    @filker0 Před rokem +2

    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  Před rokem

      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.

  • @Musaafir-ln6feet
    @Musaafir-ln6feet Před rokem +1

    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  Před rokem +1

      Thanks for the encouragement. Any particular topics you have in mind?

    • @Musaafir-ln6feet
      @Musaafir-ln6feet Před rokem

      Topics realted to CUDA programming and High Performance Computing

    • @GaryExplains
      @GaryExplains  Před rokem

      Have you watched my "supercomputer" videos on this channel?

  • @jamiemcglynn6600
    @jamiemcglynn6600 Před rokem

    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 Před rokem

      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  Před rokem

      You might like my video on multitasking vs multiprocessing vs multithreading. It is linked in the description.

    • @jamiemcglynn6600
      @jamiemcglynn6600 Před rokem

      @@GaryExplains Ah, must have missed that one, thanks!

    • @justadude8716
      @justadude8716 Před rokem

      Go language implemented threads in an amazing way using channels, making race conditions a thing of the past!

    • @GaryExplains
      @GaryExplains  Před rokem

      @@justadude8716 Interesting comment because in my video on goroutines I show how you can easily create a race condition!

  • @williamstevenson2649
    @williamstevenson2649 Před rokem +3

    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  Před rokem +1

      Good guess, but no! The quote is older than the movies.

  • @MrFilip121
    @MrFilip121 Před rokem +1

    Can you do a video on passing variables between processes/sharing variables(i.e. buffers) between threads? Some sort of interprocess communication

    • @GaryExplains
      @GaryExplains  Před rokem +2

      Indeed I will. I have also covered that in my Arduino dual-core programming video.

  • @KyrychenkoAnton
    @KyrychenkoAnton Před rokem

    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  Před rokem +1

      I am glad you found it useful. I cover multi core microcontroller programming here czcams.com/video/w5YigjvSaF4/video.html and in my video about programming the Pico in C, plus of course my videos about Piccolo OS

    • @KyrychenkoAnton
      @KyrychenkoAnton Před rokem

      @@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 Před rokem

    Could you please suggest a book or any other resource to learn more about this topic? thanks :)

  • @yngvenystrand167
    @yngvenystrand167 Před rokem +1

    Gary, is it the game released 1982 for ZX Spectrum? Ported later to TRS-80, and others?

  • @zz3709
    @zz3709 Před rokem

    Is there a correlation/connection with this and CPU cores and threads?

    • @GaryExplains
      @GaryExplains  Před rokem

      You might like my video "Multitasking vs Multithreading vs Multiprocessing" it should help answer that question - czcams.com/video/Tn0u-IIBmtc/video.html

    • @zz3709
      @zz3709 Před rokem

      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?

  • @peterjansen4826
    @peterjansen4826 Před rokem

    On line 48, why does i have to be casted with (* void)(long)?

    • @GaryExplains
      @GaryExplains  Před rokem

      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.

  • @wilsonursua8927
    @wilsonursua8927 Před rokem

    Hi Gary what happened to your speed test g channel, still hoping you could still test those new phones

  • @chuckbiscuito
    @chuckbiscuito Před rokem

    fork(2): call it once and it returns twice!

  • @TaureanSmoke
    @TaureanSmoke Před rokem

    The Hobbit

  • @joakimedholm128
    @joakimedholm128 Před rokem

    this is so boring

    • @TaureanSmoke
      @TaureanSmoke Před rokem

      That's because you're not a real nerd. Get out of here!

    • @GaryExplains
      @GaryExplains  Před rokem +1

      🤣🤣🤣 twitter.com/garyexplains/status/1580196280361308160