Thread #108262843
File: 1737780691839246.jpg (222.1 KB)
222.1 KB JPG
previous: >>108252317#define __NR_semget 64
#define __NR_semop 65
#define __NR_semctl 66
https://man7.org/linux/man-pages/man2/semget.2.html
https://man7.org/linux/man-pages/man2/semop.2.html
https://man7.org/linux/man-pages/man2/semctl.2.html
tl;dr:
semaphores, but worse!
https://man7.org/linux/man-pages/man7/sem_overview.7.html
to be clear, these syscalls are NOT posix semaphores. but the above link mentions them in the notes, and it should explain a bit more
i try to avoid any multi-threading primitives outside of the basic mutex and condition variable. i know that the others have their places, and there are definitely circumstances where they're far better suited to the task at hand, but they're also way less widely known and used. if you stick to just mutexes and cvs, it's a lot easier for anyone coming after you to read your code and know what the hell is going on.
what about you, anon? what's been your experience with multi-threading primitives? have you ever used semaphores before? if so, why?
bonus: https://en.wikipedia.org/wiki/Semaphore
are you familiar with where the term semaphore came from? most people are, but in case you aren't, give this article a read. it's pretty interesting
relevant resources:man manman syscalls
https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
26 RepliesView Thread
>>
>are you familiar with where the term semaphore came from? most people are, but in case you aren't, give this article a read. it's pretty interesting
I only knew that semaphore was traffic light in Czech/Slovak, so I was familiar with the term before I knew about semaphores in computers, but I didn't know its actual origin.
>what about you, anon? what's been your experience with multi-threading primitives? have you ever used semaphores before? if so, why?
I read about them on the Osdev wiki when I was browsing through it, but I never got far enough with my hobby OS that they would have been of any use though. I never programmed anything with semaphores, and I doubt I will any time soon.
Also putting questions in the OP makes it easier to know what to respond with, so it's easier to have a conversation like this.
>>
>>
File: 1767852603238574.png (235.6 KB)
235.6 KB PNG
>>108263011
i'm mostly sex negative, i think
>>
>what about you, anon? what's been your experience with multi-threading primitives? have you ever used semaphores before? if so, why?
I used semaphores when implementing blocking in a multiple-producer multiple-consumer queue. If a thread tries to pop an entry out of an empty queue, it runs sem_wait, and when a thread adds something to a queue, it checks to see if any threads are blocked on it, and then runs sem_post to wake them up. Those were posix semaphores though.
Nowadays I'd probably just use a futex instead, but it worked fine.
>>
>you stick to just mutexes and cvs, it's a lot easier for anyone coming after you to read your code and know what the hell is going on.
As far as I understand it, the point of these semaphore apis isn't necessarily for thread synchronization but process synchronization.
So why does the OS only provide syscalls for semaphore, but not for mutex? You can trivially implement mutex in terms of semaphore operations, but I guess the other way around isn't as straightforward? I haven't really played this out my head.
>>
>>
>>
>>
>>
>>108265526
l-lewd....
>>108265536
you too honestly
>>
>>
>>
>>
>>
>>
>>
>>
File: 1734797483073999.jpg (720.1 KB)
720.1 KB JPG
>>108268097
Just trace. I got pic related thanks to tracing.
>>
>>108262843
UNIX grew in a single-processor environment and its lack of good inter-process communication and synchronization primitives show.
Superior NT and WinAPI solutions such as the humble WaitFor* family and IOCP as well as SendMessage and mailslots never got adopted.
>>
>>
>>