weird XPCE threading issue ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

weird XPCE threading issue ?

Carlo Capelli-2
Some time ago I answered this question (
http://stackoverflow.com/questions/12158293/xpce-for-prolog-in-compiled-files/12165153#12165153),
and wrote this snippet:

:- use_module(library(pce)).
:- use_module(library(plot/barchart)).
:- use_module(library(autowin)).

test_barchart :-
    new(W, picture),
    send(W, display, new(BC, bar_chart(vertical,0,200))),
    forall(member(Name/Height/Color,
              [x/100/red, y/150/green, z/80/blue, v/50/yellow]),
           (   new(B, bar(Name, Height)),
               send(B, colour(Color)),
               send(BC, append, B)
           )),
    send(W, open).

Now I tried again that code, and I was left to stare at a blinking cursor
on an empty line...

After some test I found that commenting out, in ~/.plrc

:- set_prolog_flag(xpce_threaded, true).

it worked again. I feel the problem it's over my head...

Carlo
-------------- next part --------------
HTML attachment scrubbed and removed
_______________________________________________
SWI-Prolog mailing list
[hidden email]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: weird XPCE threading issue ?

Jan Wielemaker-5
On 04/07/2014 11:54 AM, Carlo Capelli wrote:

> Some time ago I answered this question (
> http://stackoverflow.com/questions/12158293/xpce-for-prolog-in-compiled-files/12165153#12165153),
> and wrote this snippet:
>
> :- use_module(library(pce)).
> :- use_module(library(plot/barchart)).
> :- use_module(library(autowin)).
>
> test_barchart :-
>      new(W, picture),
>      send(W, display, new(BC, bar_chart(vertical,0,200))),
>      forall(member(Name/Height/Color,
>                [x/100/red, y/150/green, z/80/blue, v/50/yellow]),
>             (   new(B, bar(Name, Height)),
>                 send(B, colour(Color)),
>                 send(BC, append, B)
>             )),
>      send(W, open).
>
> Now I tried again that code, and I was left to stare at a blinking cursor
> on an empty line...
>
> After some test I found that commenting out, in ~/.plrc
>
> :- set_prolog_flag(xpce_threaded, true).
>
> it worked again. I feel the problem it's over my head...

XPCE isn't very good at threading.  Worse, the problems are quite
different on Windows and X11, while the Mac has its own problems ...
So, run it in a single thread and communicate with it using
in_pce_thread/1 and in_pce_thread_sync/1 from other threads.

If you use the xpce_threaded flag, it will settle itself on a
thread named `pce`, which is great for development as the development
system remains responsive while your application runs.  If you want to
do *xpce development*, it is probably wiser to keep xpce in the main
thread.  Once you are finished, you can revert to threaded mode and
use ?- in_pce_thread(start_my_app). to launch the application.

Hope this clarifies a bit.  My $0.002: write graphical applications
as web applications.  Looks better, good portability, network
transparency if you need it, etc.

        Cheers --- Jan


>
> Carlo
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [hidden email]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>

_______________________________________________
SWI-Prolog mailing list
[hidden email]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: weird XPCE threading issue ?

tushar
This post has NOT been accepted by the mailing list yet.
In reply to this post by Carlo Capelli-2
I am facing a similar issue in Windows platform. I have a piece of code here:

create_person_dialog :-
    node_name(_,Name),
    string_concat('I can sense Darth Vader here at:', Name, SENSE_STR),
    new(D, dialog(SENSE_STR)),
    assert(mydialog(D)),
    send(D, append, new(label)),    % for reports
    send(D, append, new(Code, text_item(code2Terminate))),
    send(D, append,button(try, message(@prolog, create_person,Code?selection))),
    send(D, default_button, try),
    send(D, open).

Now if I call create_person_dialog in the main thread, there are no issues and a pop up dialog appears.

But if I call through thread_create e.g. thread_create(call(create_person_dialog),ThreadId,[]),

the dialog appears for a fraction of second such that it is barely visible and then suddenly disappears. There are no errors as such and a true is returned.

I tried searching for set_prolog_flag(xpce_threaded,true) but couldn't find it as there are a lot of files.

Please help me in the same.

Thank you.
Loading...