Fork me on GitHub
#missionary
<
2024-04-25
>
Andrew Wilcox00:04:47

Is initializing a semaphore with 0 tokens expected to work? (I'd expect this to wait at the m/?, but 0 seems to act more like ##Inf)

(let [sem (m/sem 0)]
  (m/? sem)
  (println "acquired"))

acquired

leonoel09:04:39

it's currently undefined behavior, do you think it should be defined ?

Andrew Wilcox09:04:43

I was working on a priority queue, where tasks are run one at a time, and when the current task has finished it pulls the highest priority task from the queue. So I needed a way of notifying when a new task had been added to the queue so that the task runner could unblock when the queue was no longer empty. An m/sem seemed like the simplest facility since no data needs to be transmitted, just that another task has been added; although it may be more than is needed since I don't need to count the number of messages in the queue, just whether it's empty or not. If I was going to use a sem I'd need to start at zero since the queue would initially be empty. But I switched to sending nil through an mbx which worked fine. I don't know anything about semaphores aside from reading the Missionary documentation on m/sem so I don't really have an opinion on what it should do, though if 0 is invalid that would be good to mention in the documentation.

joshcho04:04:41

curious about the design of missionary. the language-native dsl feels a lot simpler than monadic approach, but from a theoretical, abstract perspective, are there monads under the hood? would that be the correct mathematical framing?

Andrew Wilcox07:04:03

I can't say about monads, but in terms of the design, https://github.com/leonoel/task and https://github.com/leonoel/flow are excellent references, if you haven't seen them already.

❤️ 1
joshcho11:04:09

oh this is great! thank you