Re: help!

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi Carlo,

On 01/21/2014 10:28 AM, Carlo Capelli wrote:
> Hi Jan
>
> Sorry to bother you, but I was trying to understand why I can't catch
> exceptions when calling on background thread, and stumbled upon a weird
> behaviour of the standard - not Qt - console.
>
> Briefly, ?- help. hangs.
>
> carlo@ubuntu-carlo-64:~$ swipl
> % .plrc compiled 0.07 sec, 1,574 clauses
> Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.5-DIRTY)
> Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam
> SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
> and you are welcome to redistribute it under certain conditions.
> Please visit http://www.swi-prolog.org for details.
>
> For help, use ?- help(Topic). or ?- apropos(Word).
>
> ?- help.
> ^C^C
> [forced] Action (h for help) ? goals
>   [23] pce_principal:send(@2182115/pui_toc, root(toc_folder('Manual',
> manual, resource(manual), resource(book))))
>   [20] pce_principal:new(_G6283, pui_toc)
>   [19] Send-method on @pui_help_window/pui_manual:
> pui_manual->table_of_contents
>   [17] pce_principal:send(@pui_help_window/pui_manual, table_of_contents)
>   [14] pce_principal:send(new(@pui_help_window/pui_manual, pui_manual), open)
>
> [forced] Action (h for help) ?
>
> Note the double ^C...

I can't reproduce that.  Looks like a deadlock.  Note that xpce is not
multi-threaded.  It has a big lock around all its operations to make it
thread-safe.  There is in_pce_thread/1 to run asynchronously in the
pce thread.

If the default behaviour is as above, either your compilation is 
corrupted or you have something in your ~/.plrc that breaks this.

> In Qt console, win_menu:help, called on background, hangs, and the main
> thread got confused, hangs itself... It's a bit unfortunate, as this is
> probably one of the first menu a casual user will try...

I submitted a patch for xpce to use in_pce_thread/1 for help/0 and quite
a few others.  This might fix this.

> Since I hope the problems are (at least loosely) related, I wonder if some
> setting from C side could inhibit exceptions from working. Seems related to
> threading, since try {} catch {} works as expected in a simple setting
> (let's say, from main).
>
> BTW, the reason ?- help. doesn't work get explained after two abort...
>
> [forced] Action (h for help) ? abort
> ERROR: pce(object) `@pui_help_window' does not exist
>     Exception: (6) online_help:help ? abort
> % Execution Aborted
> ?- help.
>
> SWI-Prolog [thread 1]: received fatal signal 11 (segv)
> Stack trace labeled "crash":
>    [0] crashHandler+0x36
>    [1] dispatch_signal+0x44d
>    [2] __restore_rt+(nil)
>    [3] pthread_cond_signal+0xa
> Annullato

Using ^C sends a Prolog signal.  These are handled synchronously at
a safe point in the execution.  Some foreign code simply blocks and
does not handle (Prolog) signals.  Now, if you hit ^C the second
time before the first one was honored, it will say [forced] and
call the interrupt handler directly from the C signal function
rather than through the Prolog signal handler.  If you abort, you
basically do a longjmp() out of the current environment, leaving
the system in an unknown state.  Anything may happen, in particular
if you break forcefully out of thread synchronization primitives
because these are not signal-safe.

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.