Process Scheduling in VA

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Process Scheduling in VA

Postby ewinger » Tue Sep 16, 2008 8:34 am

I feel like I'm missing something basic, but this seems wrong. Running VA 7.5.2. It's a Plain Vanilla abt image. I'm running the code below in a workspace as an example.

| counter forkedProc |
counter := 0.

Transcript cr; show: '-------------------'.
forkedProc := [[counter > 50] whileFalse:[Transcript cr; show: counter printString. counter := counter + 1. (Delay forMilliseconds: 100) wait]] forkAt: Processor userInterruptPriority.

[counter > 50] whileFalse:[Transcript cr; show: 'main thread '; show: counter printString. counter := counter + 1. (Delay forMilliseconds: 100) wait.].
Transcript cr; show: 'done fnoodling'.


It produces the output below.
-------------------
main thread 0
main thread 1
main thread 2
main thread 3
main thread 4
main thread 5
<snipped for brevity, no output from forked process appears>
main thread 46
main thread 47
main thread 48
main thread 49
main thread 50
done fnoodling
51



Regardless of the priority of forkedProc, it never seems to get any time until after the main thread is done. I would have expected something more mixed such as:

0
main thread 1
2
main thread 3
4
main thread 5
...

Anyone have any ideas? Or perhaps someone has a link to some documentation on how the process scheduler works in regards to the UI Process & Delays? And perhaps would know if this is a change in recent versions of VA or VisualAge? ..

As an aside, if I fork the second #whileFalse: loop, regardless of priority, I do see intermixed output.

thx

eric
ewinger
 
Posts: 4
Joined: Tue Sep 16, 2008 7:29 am

Re: Process Scheduling in VA

Postby marten » Tue Sep 16, 2008 8:47 am

ewinger wrote:[counter > 50] whileFalse:[Transcript cr; show: 'main thread '; show: counter printString. counter := counter + 1. (Delay forMilliseconds: 100) wait.].


Never, ever do considering "(Delay forMilliseconds: 100) wait" in the GUI process - it leads to 100% CPU usage and makes problems everywhere. Just do:

[[counter > 50] whileFalse:[Transcript cr; show: 'main thread '; show: counter printString. counter := counter + 1. (Delay forMilliseconds: 100) wait.]] forkAt: Processor userBackgroundPriority.

and look for the result ....

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Process Scheduling in VA

Postby ewinger » Tue Sep 16, 2008 9:31 am

Ok, thanks. I didn't realize that the UI thread had such dictatorial powers.
ewinger
 
Posts: 4
Joined: Tue Sep 16, 2008 7:29 am

Re: Process Scheduling in VA

Postby tc » Wed Sep 17, 2008 10:18 am

This is a brief excerpt from an old book, 'IBM Smalltalk Programming':

Let's take a quick look at a few playful examples of multiprocessing implementations. In a Workspace, type and execute the following lines:

Code: Select all
[Transcript show:  ' Smalltalk ' ] fork. 
Transcript show:  'Programming': cr.

We expect the Transcript to display as a result the words "Smalltalk Programming." However, we got:

    Programming Smalltalk
What gives? Shouldn't the forked process run first? Well yes, except this is an example of mutex. The Transcript (and Workspace) is treated by IBM Smalltalk as a mutually exclusive resource and the UlProcess gets first crack at this resource. The forked process has to wait until the UlProcess completes.

[ . . . snippage . . . ]

By changing the order of the processes we can use mutex to display the correct sequence like this (enter the text and execute it):

Code: Select all
Transcript cr.

[0 to: 10 by: 2 do: [ :i  | Transcript show: i printString ]]
forkAt: Processor userSchedulingPriority.

[1 to: 10 by: 2 do: [ :i | Transcript show: i printString]]
forkAt: Processor userSchedulingPriority

How about that, the correct order! Remember, mutex is a semaphore, so although we have never actually created a semaphore, the Transcript runs off of one. In the next set of examples we will work with semaphores of our own creation.

So, I think the issue has more to do with the forking of processes rather than the use of Delay. Here is an example of a time based semaphore from the book (which is what your code is attempting):

Code: Select all
"Process Watcher window demo"
| ws |
ws := EtWorkspace new open.
(
   [
      | st p ps | 
      
      st := Time now.   
      [ (Time now subtractTime: st )  minutes >10 ]
          whileFalse: [
             p := UIProcess currentUI.
            ps :=Processor allProcesses.
            ws textWidget setString: '-----------------------------'.
            1 to: ps size do: [ :i |
               ws
                  cr;
                  show: (ps at: i) printString ].
              p queueInterrupt:  [
               ws
                  cr;
                  show: 'Interrupt: ', p printString].
             (Delay forSeconds: 1) wait ].
      ws close
   ]  forkAt: Processor lowIOPriority
) name: 'Process Watcher'.


--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest