[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: PIL book - OS blocking calls
- From: David Given <dg@...>
- Date: Thu, 23 Mar 2006 11:01:32 +0000
-----BEGIN PGP SIGNED MESSAGE-----
> I've been reading the PIL book, and on the above page, the author says that it is possible in most cases to use coroutines instead of 'classic' threads such as offered by the operating system. I agree, if the OS API gives the programmer the option of specifying a timeout for a call. But what if one is using an OS API that contains a blocking call, and there is no way to specify a timeout? Normally, this would be handled by making this blocking call in a thread. I don't see how this could be done with coroutines. am I missing something?
Sorry, but this is something we've dealt with *extensively* for our OS.
And it's a rate pain in the arse, excuse my Klingon.
Couroutines allow you to have a particular Lua task to pretend to block
for a particular I/O operation. However, your Lua VM has to be able to
use true asynchronous host OS primitives in order to implement the
underlying functionality. From the point of view of the host OS, the
entire Lua VM is just a single application.
If you don't have these asynchronous primitives... well, life becomes
A good example, and one that is always annoying, are the DNS functions.
The standard DNS routines are always synchronous. This means that if
your Lua VM calls one, your entire VM grinds to a halt until it returns.
There are a variety of ways round this, but they're all painful. One
approach is to use a helper process to do the blocking operations, which
then communicates with your VM via some form of IPC (we use pipes). This
allows the helper process to block without stalling the VM. But these
rapidly become painfully complex and error-prone.
Luckily for us, most Unices support a certain amount of asynchronous I/O
inherently (SIGIO in this case). Some embedded operating systems don't
support any, such as VxWorks. Life there is even more painful...
+- David Given --McQ-+
| email@example.com | "Those that repeat truisms, are also forced to
| (firstname.lastname@example.org) | repeat them." --- Anonymous from Slashdot
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----