Re: [INFO NEEDED][SEMI-CODE] Event based queue

From: Erwin S. Andreasen (erwin@PIP.DKNET.DK)
Date: 11/01/97

On Fri, 31 Oct 1997, Gary Barnett wrote:

> > ->  <<time_data>> time_of_event_to_occur;
> >
> > The easiest way would be to just make it an integer and have
> > heartbeat() update the counter every second (or however slow/fast you
> > want it updated).

> By checking each entry in the queue for being a particular value you add
> one major difficulty. The value will eventually roll over due to
> variable size limitations.

I'm not sure what you mean here. With a 32-bit signed counter and say, 8
pulses per second it will take 8 years for the variable to roll over. I
personally reboot my MUD more often :)

> A routine that decrements the time left and then fires the event when
> the time has been reached avoids this problem. That's how I've
> implemented the various

But this misses the whole point of event-based programming. In a real
event-based system, you find out when you want the event to go off, add an
event at that time to the queue, and completely forget about it then. In a
classical Diku MUD, if you have say, a dozen mobs that are to do something
every second, like fight, you have to traverse the ENTIRE list of mobs
just for the sake of those few - basing combat on events avoids that.

There are currently 5606 events queued on my MUD, 43 are added/removed
each second ( If I were to decrease a
timer of each of those events 8 times per second.. ouch! :)

Anyway, the events are put into a hash table, based on the amount of
pulses they are to go off on (in absolute amount of pulses since the
server restarted). Then, collisions are resolved by a sorted linked list.

Each pulse, the appropriate hash bucket is examined, and as long as the
event at the head of the list is to go off right now, it is removed and

You can read some more about that implementation in the archives of the
Moderatored MUD Design mailing list, at:

You said BTW, Gary, that you have "event queues" - like in several? If so,

Erwin Andreasen   Herlev, Denmark <>  UNIX System Programmer
<URL:>         <*>           (not speaking for) DDE

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/08/00 PST