lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I am sure you will be requoted many times. IMHO the way around the
thread problem is have the OS handle the threading for you. IO completion
ports and overlapped IO do this on Win32. For once MS almost got it right.
There is, I believe, a few *nix implementations of IOCPs.
Anyways, the IOCP model should not be tough to emulate on *nix and
it solves a *lot* of thread/mutex nightmares (tremble/shake).


[...]

You can get the best of both worlds by providing a simple coroutine
scheduler, and make versions of all the AIO primitives that block the
calling coroutine, and schedule a waiting coroutine by dequeuing the
IOCP.

It works beautifully ! The only catch is gethostbyname, for which there is no nonblocking support in windows. My solution is to have a background thread (pool) for nonblocking calls - only gethostbyname on winXP. This thread communicates with the main via iocp, so no mutexing is required, and all memory is handled by Lua.

Adrian