. .

st4u

ST 4U 184: Processes in VA Smalltalk

January 23, 2012 8:22:36.626

Today's Smalltalk 4 You looks at processes (and the process model) in Smalltalk, using VA Smalltalk as our example. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Processes.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll look at processes in VA Smalltalk. That will involve looking at two classes: Process and ProcessScheduler. Class Process is displayed below:

Process

Creating a process is pretty simple - you use a Block, which we looked at in a recent tutorial. You can see the code we used to play with processes below:


"create a process"

cond := 1.
block := [[cond < 10] 
	whileTrue: [Transcript show: 'Condition is: ', cond printString; cr.
						cond := cond + 1]].
block fork

cond := 1.
block := [[cond < 10] 
	whileTrue: [Transcript show: 'Condition is: ', cond printString; cr.
						cond := cond + 1]].
block forkAt: Processor userInterruptPriority

		

To create a process, simply encapsulate the desired code in in a block. Then, rather than executing it with #value (et. al.), fork off the process, as you can see above. In VA Smalltalk, there are 8 priority levels (ranging from 1 to 8 as numeric values) - but you should use the named levels, which you'll find in class ProcessorScheduler:

Priority Levels

The reason you should avoid the named levels can be seen in what's happened in other Smalltalk implementations. VisualWorks originally had 8 priorities, ranging from 1 to 8. At some point, the engineering team at Cincom changed that to 100 levels, and remapped the named levels within the new range. Instantiations could do the same with VA; it's best to avoid future problems by using the API.

To see a process execute, try highlighting the code blocks above - you should end up with something like this in the Transcript:

Processes

Another thing to keep in mind - the Smalltalk process model uses green (lightweight) threads. That means that each Smalltalk process exists only within the context of the heavyweight VM process; a Smalltalk process is neither an OS level process nor an OS level thread. Additionally, the model is one of cooperative multi-tasking - processes at the same priority level will not yield to other processes of the same priority.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u184-iPhone.m4v ( Size: 7981008 )]

posted by James Robertson

Comments

Re: ST 4U 184: Processes in VA Smalltalk

[web site optimization] January 23, 2012 10:45:38.948

There are some interesting points in time in this article but I don't know if I see all of them center to heart. There is some validity but I will take hold opinion until I look into it further. Good article , thanks and we want more! Added www.jarober.com to FeedBurner as well

 Share Tweet This