Linked by Hadrien Grasland on Fri 27th May 2011 11:34 UTC
General Development After having an interesting discussion with Brendan on the topic of deadlocks in threaded and asynchronous event handling systems (see the comments on this blog post), I just had something to ask to the developers on OSnews: could you live without blocking API calls? Could you work with APIs where lengthy tasks like writing to a file, sending a signal, doing network I/O, etc is done in a nonblocking fashion, with only callbacks as a mechanism to return results and notify your software when an operation is done?
Permalink for comment 474808
To read all comments associated with this story, please click here.
Yes, but it would be ugly
by tomz on Fri 27th May 2011 12:48 UTC
tomz
Member since:
2010-05-06

Particularly in the case of a semaphore or mutex.

One function of blocking is to give up the CPU when you can't do anything, and to queue for a resource.

It would turn simple code into something like the following, but the pastabilities are endless:

gotit=0;
waitforit() { gotit=1 }
func() {
...
getit(resource,waitforit);
while(!gotit) sched_yield; // heat-up, drain battery,etc.

Of course there might not be callbacks, but check-if-done functions,

while( !areWeThereYet(destination) ) burn();

Of course if it is truly asynchronous, the callback function will have a parameter specifying the callback which needs to be called when the first callback is completed.

I could live without blocking, but I could also live in a post-apocalyptic world as well, but it wouldn't be any more easy, simple, or pleasant.

Reply Score: 1