Threads, IO handling, and Event Queues
Nathan Yospe
yospe at hawaii.edu
Wed Mar 5 16:10:00 CET 1997
OK, I'm gonna throw in a new topic here. This was actually started rather
innocently, in, of all places, r.g.m.diku.
The thread there is something like Event Driven vs. Loop Driven. Sadly,
its location has kept it rather limp.
The discussion subject is: What is a good scheme for multithreading an
action oriented MUD?
My scheme, as posted there, follows:
Thread the mud at the rooms. Also thread the connections. The system is as
follows:
p - read socket l - update local clock a - update clock g - update clock
l - parse input o - parse event queus r - update state l - synchronize
a - buffer game c - kill dead events e - send locates o area clocks
y commands a - run current events a new objects b (optional)
e - run nongame t - update local objects s a - update global
r commands i - get new events from l states
- read outbuf o local objects s - add players
- send socket n - queue local events
The four sets of threads work together, but not on synchronous clocks. The
global thread buffers events for the areas, which buffer events for the
rooms. Rooms can (and some will, deliberately) ignore some events... I
have even created rooms that deliberately don't update their clocks every
other cycle through, thus making age factors half normal in these
places... but the general system is quite fluid. The players' commands
are all buffered in their characters, waiting for the location's clock to
update and run them into the local event queus. A character that leaves a
location takes along the command buffer... some commands may be lost, if
they pertained to local objects. Kill goblin; kick goblin; flee north;
rest; results in, if the flee precedes the kick, the character fleeing
and resting, forgetting all about kicking the goblin. As it should be.
(Actually, "flee" kills the entire combat queue, but that is beside the
point.)
In any case, I would be interested to see how the rest of you implemented
event queues, multithreading, etc...
__ _ __ _ _ , , , ,
/_ / / ) /_ /_) / ) /| /| / /\ First Light of a Nova Dawn
/ / / \ /_ /_) / \ /-|/ |/ /_/ Final Night of a World Gone
Nathan F. Yospe - University of Hawaii Dept of Physics - yospe at hawaii.edu
More information about the mud-dev-archive
mailing list