Any concrete examples?
I was recently toying with an idea of a language where all side effects would be idempotent. Couldn't find any counterexamples.
Any concrete examples?
I was recently toying with an idea of a language where all side effects would be idempotent. Couldn't find any counterexamples.
I certainly support your toying, because I think a lot of impedance to idempotency is the lack of easy patterns to achieving it.
https://man7.org/linux/man-pages/man3/sem_post.3.html
-----
In fact, multithreaded synchronization in general is non-idempotent. You don't want to send a synchronize signal twice, you need to send it exactly as many times as necessary. (Ex: mutex lock / unlock, which is probably the simplest version of a sempahore that you can get. Semaphore of size 1)
Think about a mutex lock: if the semaphore (aka: mutex) is already locked, your signature is: sem_wait(mutex, 0, 0).
Which is not idempotent. Two "sem_waits(s, 0, 0)" mean that you need two (other) threads to unlock you. One sem_wait(s, 0, 0) means that only one other thread needs to unlock you.
------
Semaphores used in this manner are how you implement reader/writer locks, as well as thread barriers. (If 100 threads are in existence, you wait for 100 semaphore_posts from those 100 other threads).
None of the semaphores or mutexes are idempotent. And never can be.