Re: simple scotty script question

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Tue, 21 Feb 1995 20:52:56 +0100

Hi!

On Mon, 20 Feb 1995 21:07:49 -0500 (EST),
andy@is.net (Andy Shelley) said:

Andy> ### Now, the above all works fine. It's the below that kills me...
Andy>
Andy> job create {puts stderr [$pm1 get "sysUpTime.0"]} 5000
Andy> puts stderr "printing joblist"
Andy> puts stderr [job list]

Andy> The job list that it returns is:
Andy> {job0 {puts stderr [$pm1 get "sysUpTime.0"]} 5000 1236758806 0 waiting}

Andy> That's one hell of a remaining time.

Andy> If I run this one line at a time (excepting kludge, of course) into
Andy> scotty running interactively, it works fine.

This one was a nice bug. Here is what actually happend: The job create
command creates a new job which is marked to get scheduled. If running
an interactive session, this will most likely happen once you have
entered the job create command and before you enter the job list
command.

If running from a file, the event loop will invoke the job after the
whole file has been evaluated. In this situation, job list is called
before the job was executed the first time. Unfortunately, this caused
the remaining time until the next scheduling point to be calculated
from the last scheduling time which was not initialized as no job has
been executed yet. (The remaining time was set to 0 - the number of
seconds since 1970.)

Below is a diff against scotty-1.2.2 that fixes this problem.

Juergen

diff -Nrc /tmp/scotty-1.2.2/ChangeLog scotty-1.2.3/ChangeLog
*** /tmp/scotty-1.2.2/ChangeLog Tue Feb 21 20:31:53 1995
--- scotty-1.2.3/ChangeLog Tue Feb 21 20:27:28 1995
***************
*** 1,3 ****
--- 1,11 ----
+ Tue Feb 21 20:16:13 1995 Juergen Schoenwaelder <schoenw@data>
+
+ * job.c:
+ Fixed a bug reported by andy@is.net (Andy Shelley). An
+ uninitialized last scheduling time was substracted if
+ job list was called before the first job had a chance
+ to run.
+
Mon Dec 19 15:50:20 1994 Juergen Schoenwaelder <schoenw@data>

* scotty-1.2.0
diff -Nrc /tmp/scotty-1.2.2/job.c scotty-1.2.3/job.c
*** /tmp/scotty-1.2.2/job.c Sat Dec 3 15:24:24 1994
--- scotty-1.2.3/job.c Tue Feb 21 20:15:43 1995
***************
*** 57,63 ****

/* The last time the scheduler completed operation */

! static struct timeval sched_time;

/* The pointer to the currently running job */

--- 57,63 ----

/* The last time the scheduler completed operation */

! static struct timeval sched_time = {0, 0};

/* The pointer to the currently running job */

***************
*** 142,147 ****
--- 142,152 ----
int delta;
Job *p;

+ if (! sched_time.tv_sec && ! sched_time.tv_usec) {
+ (void) gettimeofday (&sched_time, (struct timezone *) NULL);
+ return;
+ }
+
(void) gettimeofday(&time, (struct timezone *) NULL);

delta = (time.tv_sec - sched_time.tv_sec) * 1000
***************
*** 496,510 ****
job_schedule (interp)
Tcl_Interp *interp;
{
- static int active = 0;
int time;
Job *p, *q;

- if (!active) {
- active++;
- (void) gettimeofday (&sched_time, (struct timezone *) NULL);
- }
-
/* Flush the queue of pending ined commands */

inedFlush (interp);
--- 501,509 ----
***************
*** 574,580 ****
/* tell the event manager to call us again if needed */

if (time < 0) {
! active = 0;
} else {
job_nextschedule (interp, time);
}
--- 573,580 ----
/* tell the event manager to call us again if needed */

if (time < 0) {
! sched_time.tv_sec = 0;
! sched_time.tv_usec = 0;
} else {
job_nextschedule (interp, time);
}
diff -Nrc /tmp/scotty-1.2.2/scotty.h scotty-1.2.3/scotty.h
*** /tmp/scotty-1.2.2/scotty.h Tue Feb 21 20:32:19 1995
--- scotty-1.2.3/scotty.h Tue Feb 21 19:20:37 1995
***************
*** 20,26 ****

#include <tcl.h>

! #define SCOTTY_VERSION "1.2.2"

/*
* This is the scotty initialization function that may be used
--- 20,26 ----

#include <tcl.h>

! #define SCOTTY_VERSION "1.2.3"

/*
* This is the scotty initialization function that may be used