[Newbies] Using Futures in a thread other than the Morphic Thread

Bert Freudenberg bert at freudenbergs.de
Tue Jun 1 23:42:39 UTC 2010


On 02.06.2010, at 00:11, Jeff Gonis wrote:

> Hi everyone,
> 
> I am currently experimenting with using futures in squeak as a very convenient method for creating processes to do background work in, but a problem I am running into is that they run in the Morphic thread it appears.  This means that if I have a particularly long lived chunk of work I can end up blocking the UI thread and having an unresponsive GUI.  Ideally what I would like to do is create a future, dispatch it onto a process running at userBackgroundPriority, and then block the UI only when I try to get the value from the Promise that is returned.
> 
> I know that I can use a block closure and the forkAt: method to get a process running at the userBackgroundPriority, but this doesn't give me the nice behaviour of a Promise where I can block until completion when I actually need the value my process will generate.
> 
> So my question is, am I missing something obvious here, or is dispatching futures to a different thread something that is being worked on for a "future" squeak release?
> 
> Thanks for your help,
> Jeff G

Future messages by definition are executed in the main thread, just at a later time. But you don't need futures to create Promises, you can resolve them directly in your background process.

pr := Promise new.
[pr resolveWith: (... some lengthy computation ...)] forkAt: Processor userBackgroundPriority.
... do something else in foreground ...
result := pr wait.


- Bert -




More information about the Beginners mailing list