Thread #108262843
HomeIndexCatalogAll ThreadsNew ThreadReply
H
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 man

man 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/
+Showing all 26 replies.
>>
>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.
>>
>>108262843
i'm gonna fuck your ass
>>
>>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.
>>
she semgets me if you know what i mean
>>
>>108263556
it does provide syscalls for mutexes
>>
bampu
>>
>>108263045
idc
>>
mob face sexo
>>
>>108265526
l-lewd....
>>108265536
you too honestly
>>
semop is pomes backward
have you ever written a pome, OP
>>
>>108266486
>a fruit consisting of a fleshy enlarged receptacle and a tough central core containing the seeds, e.g., an apple or pear
a fleshy enlarged receptacle......
i wrote poems as an angsty teen, yes
>>
bampu 2
>>
why does glibc mimic a lot of kernel syscalls? do they think they can do it better or is it a comparability question?
>>
>>108267576
it (generally) doesn't mimic them, but just wraps them
>>
>>108262843
>what's been your experience with multi-threading primitives?
linux futexes are pretty good
>>
>>108262843
I wish I can draw like this.
>>
>>108268097
just download stablediffusion
>>
>>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.
>>
>>108268062
yeah, it's hard to go wrong using mutexes. or at least, if you do, you figure it out pretty quickly. that's part of why i like them
>>
bampu
>>
>>108262843
I like semaphores, they've a very simple API that lends itself well for certain producer/consumer patterns.
>>
>>108272283
oh yeah? like which ones?
>>
a へ |、
a ૮ - ՛ ) (` - 7
a / - ៸| |、-〵
a 乀 (ˍ, ل ل じしˍ,)ノ

Reply to Thread #108262843


Supported: JPG, PNG, GIF, WebP, WebM, MP4, MP3 (max 4MB)