3 ms·
I think you might not be able to write that program, there simply is no way to block in Pony (modulo FFI). The scheduler wakes up actors that have messages (in
by ndr 5y ago
I think you might not be able to write that program, there simply is no way to block in Pony (modulo FFI).
The scheduler wakes up actors that have messages (in their local/private queue) to process, all actors can do is to consume their queue and send (wait-free) messages to other actors if they want to.
From your example "read X" would be reading from the actor's queue, so it would not be blocking. If the message queue is empty that actor won't be scheduled, no blocking there.
That "while true" would not be writeable as such, you'd have to have two "behaviors" (in Pony terms, you can imagine it's an event handler) one that process the writing of s1 and one for the writing of s2, and "on read" they'd do the write. There'd be no "while true".
> I'm not going to learn pony for the sake of an example ...
> edit2: and of course, if one were to show that the above program is in fact not expressible in pony, it would be a great result and I would want to know about!
I might have misunderstood what your example was supposed to do, but I suspect you'd find it interesting to try it out.
- gpderetta 5y agoThe async_{read,write} variant never blocks nor has a while loop, it is just a four continuations recursively tail calling each other. Yet it deadlocks (as it is a purely mechanical transformation of the synchronous variant). It still might be possible that the precise pony scoping rules for closures prevent writing that variant, but I would be surprised.