POSIX shared memory with Zig

Ғылым және технология

Inter-process communication is a way to share information between different processes. In this video, I'll dive into what IPC is and how to create shared memory with Zig.
Disclaimer: This code is not production safe and just for educational purposes.
You can find the code written in this video here: github.com/BrookJeynes/zig-sh...
You can find the diagrams used in this video here: excalidraw.com/#json=a7YXNXJe...
Corrections are in the pinned ERRATA comment.
Timestamps:
- [0:00] Intro
- [0:12] IPC
- [0:24] Shared memory
- [0:48] Example program
- [1:04] Disclaimer
- [1:17] Programming
- [1:32] Shared memory considerations
- [2:45] mmap()
- [4:18] Mapping to a file
- [6:18] Back to the program
- [6:36] Forking the child
- [7:59] Output
- [8:21] Outro
Resources:
- [Operating System Concepts: Global Edition](www.wiley.com/en-au/Silbersch...)
- [musl - shm_open](elixir.bootlin.com/musl/lates...)
--------------------------------------------------------------
🎵 Music "bread" by ‘Lukrembo’
💿 Listen: • (no copyright music) j...
--------------------------------------------------------------

Пікірлер: 27

  • @chooky_
    @chooky_3 ай бұрын

    ERRATA - As of 0.12.0-dev.2750+5f9255829, `mmap` no longer takes a bitset for the fourth argument but rather a struct. I've updated the code for this in the GitHub repo - github.com/BrookJeynes/zig-shared-memory/commit/a749e16c9ad610d62ef0396b2bd535a195c7c289

  • @AlleBalle54
    @AlleBalle546 ай бұрын

    Very good explanation, clear and easy to follow. Great job!

  • @sanderbos4243
    @sanderbos42434 ай бұрын

    High-quality videos explaining concepts in Zig, let's gooo

  • @jakubvf
    @jakubvf5 ай бұрын

    Thank you for taking the time to make this video!😀

  • @timibolu
    @timibolu6 ай бұрын

    I really like the digrams and the explanation. please create more videos

  • @0LoneTech

    @0LoneTech

    6 ай бұрын

    Fun fact: digram is a real word, distinct from diagram.

  • @timibolu

    @timibolu

    6 ай бұрын

    lol. I didn't even see the typo. Thanks. I just learnt a new word@@0LoneTech

  • @saif5267
    @saif52676 ай бұрын

    great video, keep this stuff going.

  • @hiongun
    @hiongun3 ай бұрын

    great explanation♥

  • @someonesalt5084
    @someonesalt50846 ай бұрын

    ur going places

  • @lilzin69
    @lilzin696 ай бұрын

    bro, i love you

  • @dlesner
    @dlesner6 ай бұрын

    Very well done video. And it’s only your second…

  • @Nemo_64
    @Nemo_646 ай бұрын

    Really good video! May I ask how did you do to make the animations and such? Is it PowerPoint? And how did you do the voice over?

  • @chooky_

    @chooky_

    6 ай бұрын

    I used PowerPoint to make the presentation, OBS to record it, Audacity to record the audio, and iMovie to piece it all together.

  • @ha5anmukhlis
    @ha5anmukhlis4 ай бұрын

    you can get rid of the else clause in the final section of the code

  • @anthonvanderneut
    @anthonvanderneut4 ай бұрын

    5:48 that should be `std.c.ftruncate(` for consistency. You probably do `const c = std.c;` somewhere outside of your `main()`. I also don't see a pinned ERRATA comment (yet).

  • @fishsayhelo9872
    @fishsayhelo98726 ай бұрын

    nice

  • @jamesmorrison9893
    @jamesmorrison98936 ай бұрын

    this was fuegolian josephine

  • @0LoneTech
    @0LoneTech6 ай бұрын

    This has oddities. The title said POSIX shared memory, so I expected it to be about that, but then you start out using mmap, the system for mapping files. Then you carry on to say how you'd demonstrate using files, and switch to the shared memory functions, which "are not backed by actual files" (glibc manual). It's an OS specific implementation detail that Linux does have a filesystem to expose shm regions, exactly the sort of thing POSIX (IEEE Std 1003.1) is designed not to rely on; the specification states "It is unspecified whether the name appears in the file system and is visible to other functions that take pathnames as arguments." The distiction is significant particularly on POSIX compliant systems supporting the Shared Memory Objects option but not Memory Mapped Files. I'm also uneasy about skipping over synchronization. It's not that hard to say you synchronize by spawning and waiting on a process, and it is significant; you mustn't start sorting before the data is initialized. There are upsides too. I needed a refresher on how System V and POSIX shared memory differ (though this video really never touches on the former, and probably shouldn't).

  • @chooky_

    @chooky_

    6 ай бұрын

    Hey @0LoneTech, appreciate the feedback, I'll look into the stuff you mentioned. In regards to skipping over synchronisation, although I didn't mention it in this video, I do plan to follow up with another video talking about synchronisation methods in more detail and how to implement them. Thanks for watching and providing some feedback. Maybe removing POSIX out of the title, and thumbnail, and just titling it "Shared memory with Zig" would reduce the confusion?

  • @0LoneTech

    @0LoneTech

    6 ай бұрын

    The second method shown, titled "Mapping to a file", really is the POSIX shared memory method accessible from Zig. But it may not be backed by files, which would be the third mmap way (and what mmap is most known for; e.g. it's how your program is loaded). Anonymous mapping is not in POSIX (a cursory glance in Zig's library suggests it exists on Darwin but not Plan 9), and in Linux couldn't be combined with shared mapping before Linux 2.4. I wonder if there's a Zig platform where shm use requires using std.c.mmap rather than std.os.mmap.

  • @Eugensson

    @Eugensson

    4 ай бұрын

    Wasn't Windows POSIX certified at certain point?

  • @0LoneTech

    @0LoneTech

    4 ай бұрын

    @@Eugensson They certainly advertised it as such, though they had only fragmentary compatibility. One infamous event was them trying to claim compatibility with the Korn shell... while Korn was in attendance with a prepared laundry list of how broken it was.

  • @sid6576
    @sid65766 ай бұрын

    Great video man. It's daytuh not dahtah 👍

  • @albertovelasquez9027
    @albertovelasquez90273 ай бұрын

    So fucking good video

  • @naranyala_dev
    @naranyala_dev5 ай бұрын

    more zig

Келесі