[MUD-Dev] Threading idea

Smith Smith
Thu Jun 20 07:17:19 CEST 2002


From: Zach Collins

> I'm sure the concept of microthreads translates to / is supported
> by other languages as well.

<nods>

What the article seemed to boil the concept down to was a
"scheduler" with which a set of tasks could be queued, and which
would execute the tasks on command.

In a more strongly OO language, I'd say that this type of role could
be filled by a "monitor object" which is a thread-safe passive
object, but a much better description can be found at:

  http://www.cs.wustl.edu/~schmidt/PDF/monitor.pdf

(obvious warning: PDF).

One use I've found for this type of object is in queuing actions
found to be required to be performed during a traversal of some
collection. At the end of the traversal, the object is commanded to
run all the queued actions to completion. This allows a bounded
complexity traversal (since the traversal usually means a non-fine
grained thread-safe locking) without placing requirements on the
complexity of the queued operations.

Additionally, since the monitor pattern is so closely related to the
active object pattern, it's relatively simple to restructure the
code to lazily evaluate the queued operations in a thread running
concurrently "within" the monitor (essentially making the
"scheduler" its own thread). In this way, the OS's context switching
only occurs once, and the user context switching ammounts to the
same state- gathering that the queued methods would have been
required to accomplish regardless.

-Dave

_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the mud-dev-archive mailing list