discrete event simulation question



Hi,

I've been working on an Discrete event simulation problem using linked
lists. The algorithm looks as follows:

struct linkedlist
{
int event;
int queue; //FIFO on which the event acts
double timer; // time value embedded in each node in the LL on
which the LL is sorted.

};

/*basic event simulation algorithm */
while(1)
{
ptr = ptr->next ( advance the linked list)
execute ptr->event on ptr->queue
get time from gettimeval (global_time)
add time taken for exec. of one event to global time /*using
system_clock for global_time*/
create new node with another event, the queue on which the event
acts and the time value.
Add the new node to the linked list based on time (The list is
ordered based on increasing time)
get time from gettimeval (global_time)
sleep(ptr->time - global_time)
}

Now, I am not sure if this is the way I should set time. How do I
manage global time?
The reason why I ask this is I am using system clock as the global time
and assigning the due_time to each node in the Linkedlist based on the
following value:

due_time_for_event => current_system_clock_time +
time_taken_for_one_event.

( In my case, the event is consumption of data by a FIFO. Hence the
time_taken_for_one_event i.e., consumption would be
(1/Consumption_rate_of_FIFO)).

But, because of this, some times(infact many times) its so happening
that the due_times of 2 adjacent nodes are overlapping. Due to this,
, the event's execution is still going on when the next event's
due_time has already elapsed and its due. How do I deal with this in a
sequential program? How do I maintain global time? What is its relation
to system clock time? How to I use to set the due_time in each node so
that each event gets its due_time as atleast greater than the previous
event's due_time by "time_taken_for_one_event"?

.