Re: Threads



There are dozens if not hundreds of "examples" of this - any JACK client with a GUI.

But to get an idea of the basic idea, take a look in the JACK example clients and/or tools. jack_capture would be a good place to start, since it faces the problem of handing over incoming (audio) data to another thread.

And no, you are not writing "the data" to a pipe from the JACK callback. The key ideas are (a) to move the data to another thread you need to use a lock-free data structure (b) if you need to wake the other thread (i.e. because it doesn't simply wake up periodically and use whatever new data you've delivered), you need to use the *most* RT-safe method you can. There are no absolutely RT-safe methods. A semaphore (on Linux anyway) is the best, writing a byte to a pipe is the 2nd best.

You cannot make calls from the JACK callback that may block - you cannot write to disk, read from disk, take locks, etc, etc.

This really should not be going to the gtk-list anymore. It has roughly nothing to do with gtk and more or less everything to do with JACK.

--p




On Sat, Oct 19, 2013 at 3:08 AM, Craig Bakalian <craigbakalian verizon net> wrote:
On 10/18/2013 11:12 PM, Paul Davis wrote:

On Fri, Oct 18, 2013 at 11:04 PM, Craig Bakalian <craigbakalian verizon net> wrote:
Hi Paul,

Okay, I have a design flaw.  I am the only one who uses this app, so no harm done.  But I am still confused by the conversation here.  If I cannot use gdk_threads_idle_add()  then what can I do. 

I am confused because, I imagine, anticipate that creating a thread in the jack callback and running it calling an function that inserts text into a textbuffer will not work because I can only act on the main thread?

A simple code example of a solution would be helpful.

all GTK GUIs should be unithreaded anyway.

from the JACK callback, queue whatever data you want in to jack_ringbuffer_t (which is a single-reader, single-writer lock free object), then use a semaphore to signal some other thread. easier than a semaphore, but not quite as RT safe: write to a pipe. the GUI thread can add the other end of the pipe to its event loop so that it will wake up when writing is done.

--p
 

Hi,

Is there a code example that does what you are saying?  Forgive me, I still don't understand what you are saying.  Are you telling me to write data to a pipe in the JACK callback?  If so, how do I get the pipe to send data to a GtkTextBuffer?

Craig Bakalian




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