Threads were initially used for telephony systems where each request to connect could be given to a new thread to manage. The simplification was, in theory, dramatic. The programmer could just write the code for handling a single line, and the OS and network code would multiplex operation over 100,000 calls. The programmer does not have to worry about what operations block and delays. Imagine writing this same code using some sort of request queue. The only way to do it would be to make extensive use of asynchronous I/O, something that was uncommon when threads became popular. In fact, any multithreading design seems convertible into a single threaded design via use of asynchronous events and asynchronous I/O. But these methods are not noticeably easier than threads.
rcvm(fd, &buf, n, func); // call “func” when the data arrives – pass it the return val and arguments to read as well
then
while(1){
rcvm(fd,&ptr++,n,got);
if(noresources)wait();
}
got(fd,&p,n,code){
look at message
queue_response
return;
}
Worse or better?