Threads and synchronous IPC: non-sense?
Posted: Mon Jul 28, 2003 7:22 am
In my quest for simple and clear semantics for my microkernel, multi-server OS, I've come to a new problem.. which has to do with the concept of signals, which I've decided to separate from the (CPU) exceptions.
Now, my logic goes like this: Signals should be delivered to mailboxes, be those for threads or objects. Doesn't matter really, since one can redirect signals from an object to a thread that has indicated willingness to handle them. It's easy enough to poll the mailbox once in a while, which is safely implemented in pretty much any language. But there's a problem: I was going to use synchronous IPC (RPC) calls.
So, if I have my thread waiting for an IPC call to finish, I have two options. Either I deliver the signal, interrupting the IPC action, which might lead to consistency problems with the other end of the connection and various undefined states, or I just wait for the completion, which might take a long time and has to do with the all to well known trouble of thread cancellation.
So it seems the only reasonable solution is doing asynchronous IPC instead, and have finished IPC calls drop a signal (or event) into a mailbox. This way if thread get some other signal, it can either handle that, or notify the other end of IPC that it doesn't care about the call anymore, if supported by the service. No need for kernel to know when to interrupt, when to not, since interrupting the calling thread doesn't disturb the IPC process.
This means more or less going to a fully event-based model, which makes sequential programming languages like C pain to use.. but might it be worth it?
Now, I've seen people claim that Windows uses asynchronous I/O because it suits multi-threaded environment better than synchronous. I've finally starting to see reasons behind it..
Makes me wonder if the whole idea of doing multi-threading POSIX-style is flawed. Seems like UNIX is good for combining small programs by scripting and piping and that's about it, the monolith-kernel, half a million special cases and good luck being the only things that make it work at all.
Or is it just a problem with my head...
Now, my logic goes like this: Signals should be delivered to mailboxes, be those for threads or objects. Doesn't matter really, since one can redirect signals from an object to a thread that has indicated willingness to handle them. It's easy enough to poll the mailbox once in a while, which is safely implemented in pretty much any language. But there's a problem: I was going to use synchronous IPC (RPC) calls.
So, if I have my thread waiting for an IPC call to finish, I have two options. Either I deliver the signal, interrupting the IPC action, which might lead to consistency problems with the other end of the connection and various undefined states, or I just wait for the completion, which might take a long time and has to do with the all to well known trouble of thread cancellation.
So it seems the only reasonable solution is doing asynchronous IPC instead, and have finished IPC calls drop a signal (or event) into a mailbox. This way if thread get some other signal, it can either handle that, or notify the other end of IPC that it doesn't care about the call anymore, if supported by the service. No need for kernel to know when to interrupt, when to not, since interrupting the calling thread doesn't disturb the IPC process.
This means more or less going to a fully event-based model, which makes sequential programming languages like C pain to use.. but might it be worth it?
Now, I've seen people claim that Windows uses asynchronous I/O because it suits multi-threaded environment better than synchronous. I've finally starting to see reasons behind it..
Makes me wonder if the whole idea of doing multi-threading POSIX-style is flawed. Seems like UNIX is good for combining small programs by scripting and piping and that's about it, the monolith-kernel, half a million special cases and good luck being the only things that make it work at all.
Or is it just a problem with my head...