Thread Scheduler with I/O

loop.thread.IOScheduler


Subclass of Scheduler that offers support for introduction of synchronous I/O operations integrated with the scheduler. This class offers support to implement I/O operations that switch execution for other threads until the I/O channel is ready. This class is useful for implementation of I/O operations integrated with the cooperative scheduling mechanism in order to maximize the processing time.

The instances of this class have two more lists mapping I/O channels (e.g. socket or file) to the suspended threads that should be resumed when the channel becomes ready for reading or writing. Additionally, it uses a provided function (e.g. socket.select function of LuaSocket package) to select I/O channels ready for access.

Behavior

Initialization

IOScheduler([object])
Executes the same initialization of its superclass Scheduler with value provided by object and additionally creates the lists used to map channels to blocked threads (i.e. reading and writing).

Fields

select [required]
Function that implements the same API of socket.select function of LuaSocket package but can select channels of any type supported by the IOScheduler instance.
sleep [required]
Function that suspends the execution of the application for the ammount of seconds given as argument. This function called when the scheduler is idle and no thread is blocked on I/O channels.

Methods

remove(coroutine)
Redefinition of superclass method in order to also remove the coroutine from the lists of I/O blocked threads.
register(coroutine)
Redefinition of superclass method in order to check if the registering coroutine is not already registered in the lists of I/O blocked threads.
step()
Redefinition of superclass method that also unblocks waiting threads when their I/O channels are ready for access.

Remarks

Examples

See class CoSocket.

Copyright (C) 2004-2008 Tecgraf, PUC-RioThis project is currently being maintained by Tecgraf at PUC-Rio.