octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: interrupt handing and the GUI (bug #37672)


From: Daniel J Sebald
Subject: Re: interrupt handing and the GUI (bug #37672)
Date: Mon, 11 Nov 2013 23:12:12 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 11/11/2013 01:47 AM, Daniel J Sebald wrote:
On 11/11/2013 12:35 AM, John W. Eaton wrote:
On 11/10/2013 10:45 PM, Daniel J Sebald wrote:

The last answer at this link seems to know more than the rest of us:

http://stackoverflow.com/questions/12820765/can-i-send-signals-to-different-threads



Maybe there is something there.

Yes, it mentions pthread_kill. That appears to allow us to direct a
signal to a particular thread.

I'm attaching a patch that seems to at least partially work for me.
At least interrupts seem to work now inside sleep and long running
functions like "inv (large_matrix)", but now I also get random
segfaults when typing Ctrl-C in the command window after a few
interrupts have been processed (it seems random).

There is a lot there. The only thing that seems somewhat suspicious from
first glance is the fact that

+ interpreter_thread = pthread_self ();
+

I.e., the fact that a thread might be interrupting itself. On the other
hand, the pthread documentation says that is fine, but more than that it
looks like the GUI thread is actually initiating the pthread_kill()
using the above pointer so the thread really isn't interrupting itself.

I'm not sure what the problem might be for the random seg fault, and yes
pthread_kill might not be portable.

Here's a "maybe" scenario.  This article:

http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

gives a word of caution about allocating heap objects in the constructor of the QObject because that memory will reside in the main thread, not the "worker" thread. That isn't something you've quite done, but maybe close:

octave_interpreter (new octave_main_thread ())
+{
+  connect (this, SIGNAL (execute_interpreter_signal (void)),
+           octave_interpreter, SLOT (execute_interpreter (void)));
+
+  connect (this, SIGNAL (interrupt_interpreter_signal (void)),
+           octave_interpreter, SLOT (interrupt_interpreter (void)));
+
+  octave_interpreter->moveToThread (main_thread);

octave_interpreter is being passed a pointer to something created in one thread and is then moved to another thread. Just a guess.

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]