swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The Case of the Disappearing Event


From: manor
Subject: The Case of the Disappearing Event
Date: Wed, 27 Aug 1997 18:06:55 -0400

Dear address@hidden,

I think I've stumbled on a reasonably stealthy bug in
the Swarm scheduling mechanism. My apologies if this
bug has already been reported - I'm taking the chance
of repeating a previous report because the bug is
quite treacherous and will cause programs to misbehave
in truly scary and unpredictable ways (basically events
will start disappearing from your schedule).

Here is a description of the bug followed by code which
reproduces it (I have personally witnessed it on a Linux
box and on a SparcStation, so I really don't think it is
platform specific)...

Assume two schedules A, B and assume that we activate both
of them within the same swarm. Now, if in the context of
executing an event on schedule A we dynamically schedule
an event E(a) on schedule B it turns out that E(a) will be
ignored... _unless_ some event scheduled on B also schedules
an event E(b) on B to occur at exactly the same time as E(a).

What makes this bug difficult to discover is that for
some reason (probably to do with the fact that indexes
are not safe), the relative _source_ of the event doing
the dynamic scheduling (from the same schedule vs.
different schedules) has an effect on the newly scheduled
event.

I stumbled on this bug because I had a combination of a
repetitive schedule of 'normal' events merged with an
absolute schedule of 'rare' events (which were generated
as a side-effect of the 'normal' events). Note: The example
code which reproduces the bug uses two simple schedules,
so the fact that one of the schedules was repetitive is
irrelevant...

Anyway, here is the example code:

======================= Makefile ============================

SWARMHOME=../swarm
APPLICATION=bug
OBJECTS=BugModelSwarm.o main.o
OTHERLIBS=
OTHERCLEAN=

include $(SWARMHOME)/Makefile.appl

BugModelSwarm.o: BugModelSwarm.m BugModelSwarm.h
main.o: main.m BugModelSwarm.h

=============================================================


======================= BugModelSwarm.h =====================

#import <simtools.h>

@interface BugModelSwarm : Swarm {

  int fix ;

  id firstSchedule;
  id secondSchedule;

}

-useFix ;

-buildActions;
-activateIn: (id) swarmContext;
-go ;
-stopRunning ;

-scheduleEventOnSecondScheduleAtNextTimeStep ;
-scheduleEventOnSecondScheduleAtTime10 ;
-sayHello ;

@end

=============================================================

========================BugModelSwarm.m =====================

#import "BugModelSwarm.h"

@implementation BugModelSwarm

+createBegin: (id) aZone {
  BugModelSwarm * obj;

  obj = [super createBegin: aZone];
  obj->fix = 0 ;

  return obj;
}

-useFix {
  fix = 1 ;
  return self ;
}

-buildActions {
  [super buildActions];

  firstSchedule = [Schedule createBegin: [self getZone]] ;
  [firstSchedule setAutoDrop: 1] ;
  firstSchedule = [firstSchedule createEnd] ;

  [firstSchedule at: 5
     createActionTo: self
            message: M(scheduleEventOnSecondScheduleAtTime10)];

  secondSchedule = [Schedule createBegin: [self getZone]] ;
  [secondSchedule setAutoDrop: 1] ;
  secondSchedule = [secondSchedule createEnd] ;

  if(fix){
    [secondSchedule at: 1
        createActionTo: self
               message: M(scheduleEventOnSecondScheduleAtNextTimeStep)];
  }

  [secondSchedule at: 15
      createActionTo: self
             message: M(stopRunning)];

  return self;
}

-activateIn: (id) swarmContext {

  [super activateIn: swarmContext];

  [firstSchedule activateIn: self];
  [secondSchedule activateIn: self];

  return [self getSwarmActivity];
}

-go {
  fprintf(stderr,"t0:\tStarting simulation...\n");
  [[self getActivity] run];
  return [[self getActivity] getStatus];
}

-scheduleEventOnSecondScheduleAtNextTimeStep {

  fprintf(stderr,
"t%ld:\tScheduling event from second schedule to second schedule for t%ld\n",
  getCurrentTime(), getCurrentTime() + 1) ;

  [secondSchedule at: getCurrentTime() + 1
      createActionTo: self
             message: M(scheduleEventOnSecondScheduleAtNextTimeStep)] ;

  return self ;
}

-scheduleEventOnSecondScheduleAtTime10 {

  fprintf(stderr,
  "t%ld:\tScheduling event from first schedule to second schedule for t10\n",
  getCurrentTime()) ;

  [secondSchedule at: 10
      createActionTo: self
             message: M(sayHello) ];

  return self;
}

-sayHello {

  fprintf(stderr,"t%ld:\tHello!!!\n",getCurrentTime()) ;

  return self ;
}

-stopRunning {

  fprintf(stderr,"t%ld:\tStopping Simulation...\n",getCurrentTime()) ;
  [getTopLevelActivity() terminate] ;

  return self ;
}
@end


=============================================================

========================== main.m ===========================

#import <simtools.h>
#import "BugModelSwarm.h"

int main(int argc, char ** argv) {
  id theSwarm;
  int i ;

  initSwarm(argc, argv);

  theSwarm = [BugModelSwarm create: globalZone];

  for(i = 0 ; i < argc ; i++)
    if(!strcmp(argv[i],"-useFix"))
      [theSwarm useFix] ;

  [theSwarm buildActions];
  [theSwarm activateIn: nil];
  [theSwarm go];

  return 0;
}

=============================================================

If no command line argument is provided this is the output that I get:

t0:     Starting simulation...
t5:     Scheduling event from first schedule to second schedule for t10
t15:    Stopping Simulation...

However if I continuously generate events on the second schedule
(by specifying -useFix as a command line argument) this is what I get:

t0:     Starting simulation...
t1:     Scheduling event from second schedule to second schedule for t2
t2:     Scheduling event from second schedule to second schedule for t3
t3:     Scheduling event from second schedule to second schedule for t4
t4:     Scheduling event from second schedule to second schedule for t5
t5:     Scheduling event from first schedule to second schedule for t10
t5:     Scheduling event from second schedule to second schedule for t6
t6:     Scheduling event from second schedule to second schedule for t7
t7:     Scheduling event from second schedule to second schedule for t8
t8:     Scheduling event from second schedule to second schedule for t9
t9:     Scheduling event from second schedule to second schedule for t10
t10:    Hello!!!
t10:    Scheduling event from second schedule to second schedule for t11
t11:    Scheduling event from second schedule to second schedule for t12
t12:    Scheduling event from second schedule to second schedule for t13
t13:    Scheduling event from second schedule to second schedule for t14
t14:    Scheduling event from second schedule to second schedule for t15
t15:    Stopping Simulation...

The problem is that in the initial run the "Hello!!!" event never got
executed...

Regards,

Manor.


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]