Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 368
Joined: 14 Nov 2002 0:01

Suspension and the GUI

Post by Martin Meyer »

Hello Thomas,

in a new GUI project, I insert the following for onFileNew:

Code: Select all

predicates     onFileNew : window::menuItemListener. clauses     onFileNew(_Source, _MenuTag) :-         _Future = pfc\asynchronous\future::submit_unit(workLots),         stdIO::write("submitted").   class predicates     workLots : () suspending. clauses     workLots() :-         std::repeat(),         fail.       workLots().
When I execute the project and click on the "New" icon, the text "submitted" is not displayed, and the task window becomes unresponsive.

However, my intention is to allow the user to continue working with the GUI while workLots runs in the background.

I suspect I need to use a different execution context to achieve the desired behavior, but I cannot figure out how to do it. Please help.
Regards Martin
Martin Meyer
VIP Member
Posts: 368
Joined: 14 Nov 2002 0:01

Re: Suspension and the GUI

Post by Martin Meyer »

That way it works better in my tests:

Code: Select all

predicates     onFileNew : window::menuItemListener. clauses     onFileNew(_Source, _MenuTag) :-         _Future = pfc\asynchronous\future::submit_unit({  :- workLots_susp(0) }),         stdIO::write("submitted\n").   class predicates     workLots_susp : (integer Cnt) suspending. clauses     workLots_susp(Cnt) :-         stdIO::write(Cnt, "\n"),         pfc\asynchronous\executionContext::yield(),         Cnt1 = if Cnt = upperBound(integer) then 0 else Cnt + 1 end if,         workLots_susp(Cnt1).
So, does workLots_susp actually need to be repeatedly suspended to keep the task window responsive? Is the above pattern (i.e., inserting calls to yield) suitable for use in my "real" applications, or are there other aspects to consider? Do I need to worry about execution contexts, or is that usually unnecessary?
Regards Martin
Martin Meyer
VIP Member
Posts: 368
Joined: 14 Nov 2002 0:01

Re: Suspension and the GUI

Post by Martin Meyer »

In my real application, the long-running process that I want to run in the background is a call to an Earley parser.

If I would insert calls to yield into the parser's routines, I needed to turn at least the parser's top-level routines into suspending predicates. However, that does not seem elegant to me. Is there a way to keep suspension issues outside of the parser's code while still ensuring the responsiveness of the task window?
Regards Martin