home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / smalltal / 2323 < prev    next >
Encoding:
Text File  |  1992-11-18  |  5.4 KB  |  121 lines

  1. Newsgroups: comp.lang.smalltalk
  2. Path: sparky!uunet!gatech!news.byu.edu!hamblin.math.byu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!ticipa!ticipa.pac.sc.ti.com!tomb
  3. From: tomb@ticipa.pac.sc.ti.com (Thomas Burns)
  4. Subject: Re: Restarting contexts in V/286
  5. In-Reply-To: hinkle@cs.uiuc.edu's message of Tue, 17 Nov 1992 22: 25:29 GMT
  6. Message-ID: <TOMB.92Nov18124446@ticipa.pac.sc.ti.com>
  7. Sender: usenet@ticipa.pac.sc.ti.com (USENET News System)
  8. Organization: Texas Instruments Manufacturing Technology Center
  9. References: <BxvsyI.CIJ@cs.uiuc.edu>
  10. Date: Wed, 18 Nov 1992 18:44:46 GMT
  11. Lines: 108
  12.  
  13. In article <BxvsyI.CIJ@cs.uiuc.edu> hinkle@cs.uiuc.edu (Bob Hinkle) writes:
  14.  
  15.    Newsgroups: comp.lang.smalltalk
  16.    Path: ticipa!tilde.csc.ti.com!csc.ti.com!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!hinkle
  17.    From: hinkle@cs.uiuc.edu (Bob Hinkle)
  18.    Sender: news@cs.uiuc.edu
  19.    Organization: University of Illinois at Urbana-Champaign
  20.    Date: Tue, 17 Nov 1992 22:25:29 GMT
  21.    Lines: 41
  22.  
  23. Well Bob, you've stumbled into a hornet's nest.  Luckily, there are
  24. ways out without getting too badly stung.  I too have written an
  25. exception handler for V/286, and mine is about 98% compatible with that
  26. found in St80.  Now, to your questions...
  27.  
  28.       I'm almost done implementing an exception handler for V/286,
  29.    but I'm still having one problem:  I can't seem to restart 
  30.    the current process at a different context using the
  31.    Process>>restartAt: method.  I *can* restart one (suspended)
  32.    process from another, much like what the Debugger does, but I also
  33.    want to be able to restart the current one.  The solution I came
  34.    up with, and the one Digitalk's technical support suggested, is:
  35.  
  36.    restart: aContext
  37.        | index process |
  38.        "Restart the #handle:do: context."
  39.  
  40.        process := Process copyStack. 
  41.        index := process indexOfContext: aContext.
  42.        process restartAt: index 
  43.  
  44.    Process>>copyStack is supposed to create a copy of the CurrentProcess,
  45.  
  46. This is the first place you went awry.  There is much confusion
  47. surrounding copyStack, and it took me a series of about 6 phone calls
  48. to an expert to get it all straightened out.  The copyStack does NOT
  49. copy the process.  What it does do is copy the stack of the currently
  50. executing process (regardless of what's in the CurrentProcess global)
  51. from the internal machine stack INTO the stack of the Smalltalk
  52. process pointed to by the CurrentProcess global.  As an aside, a
  53. simple way to create a snapshot of a running process is to turn all
  54. interrupts off (VERY important), save CurrentProcess somewhere, set
  55. CurrentProcess to Process new, do 'Process copyStack', save the newly
  56. created process in your favorite storage location, restore
  57. CurrentProcess to its previous value, then reenable interrupts.
  58.  
  59.    so we should be able to manipulate it without messing things up.
  60.  
  61. Along with what I mentioned above, manipulating the stack of the
  62. process returned from #copyStack is like a doctor performing open
  63. heart surgery on himself.  If a task switch should occur before you
  64. are done, watch out, anything can happen.  From walkbacks complaining
  65. of indexes out of range to toasting your image entirely.
  66.  
  67.    Process>>indexOfContext: is a method we added that returns the
  68.    frame index of a given context, and it works correctly based on
  69.    independent tests.  But the result of running this method is
  70.    always an error in which the process' index into its indexed instance
  71.    variable is negative.  Checking things out, I added the following
  72.  
  73. Ah.  Just what I mentioned above.
  74.  
  75.    test:
  76.  
  77.    restart: aContext
  78.        | index process |
  79.        "Restart the #handle:do: context."
  80.  
  81.        process := Process copyStack. 
  82.        process == CurrentProcess ifTrue: [self halt].
  83.        index := process indexOfContext: aContext.
  84.        process restartAt: index.
  85.  
  86.    When this method is run, the halt in the block is activated, which
  87.    tells me that while Process>>copyStack has some side effects, it's
  88.    still returning the current process, rather than the non-active 
  89.    identical copy of the current process that I think I need.  Does
  90.    anyone out there have insights into this problem?
  91.  
  92.                        Bob Hinkle
  93.  
  94. Another side effect of copyStack is that it is allowed to return
  95. twice.  The first time it returns it answers a pointer to the
  96. CurrentProcess.  If no task switch has occurred, you can do a
  97. 'CurrentProcess resume' and the copyStack method will return a second
  98. time and the return value will be the Process class.  Nifty, huh!  For
  99. an example, take a look at ProcessScheduler>>#fork:at:.  This method
  100. contains everything mentioned earlier.  It uses copyStack to create a
  101. new process, checks its return value to see if it is the first or
  102. second return from the #copyStack method, etc.
  103.  
  104. I don't know how deep you want to get into V exception handling, but
  105. it took me about 4 months to come up with a reasonably bug free
  106. version that was nearly compatible with St80.  We have code that must
  107. run under both V and 80, so an exception handler was imperitive.  I
  108. have considered trying to get the code out into the public domain as I
  109. am sure many would find it useful, I just haven't addressed doing that
  110. yet.
  111.  
  112. If you have more questions, feel free to ask.
  113.  
  114. tom
  115.  
  116. --
  117. Tom Burns                       Domain:    tomb@spdc.ti.com
  118. Texas Instruments               TI MSG:    THOS
  119. P.O. Box 655012, M/S 463        Voice:     (214) 995-9707
  120. Dallas, TX   75265              FAX:       (214) 995-1916
  121.