Using Futures in a thread other than the Morphic Thread

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Futures in a thread other than the Morphic Thread

Jeff Gonis
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

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Using Futures in a thread other than the Morphic Thread

Bert Freudenberg
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 -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Using Futures in a thread other than the Morphic Thread

Jeff Gonis
Thanks a ton Bert, that clears things up quite a bit.  I guess I was getting too wrapped up in considering Futures and Promises as being bound together rather than concepts I could use separately.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners