views:

35

answers:

1

I'm using the Snack audio processing kit along with TCL. I want to cut up part of the sound and give this section to another thread to work with.

My question is how to pass something by reference, between threads in TCL.

proc a {} {  
    snack::sound snd  
    thread::send -async $Thread [list B snd]
}

set Thread [thead::create { 
    proc B{snd} { 
    ... do something with snd
    }
}
+1  A: 

That's not going to work. Tcl threads are designed to be strongly isolated from each other since it massively reduces the amount of locking required for normal processing. The down-side of this is that passing things between threads is non-trivial (other than for short messages containing commands, which audio data isn't!) But there is a way forward…

If you can send the data as a chunk of bytes (at the script level) then I recommend transferring it between threads using the tsv package, which is parceled up with the thread package so you'll already have it. That will let you transport the data between threads relatively simply. Be aware that the snack package is not thread-aware in its script-level interface, so the data transfers are still going to involve copying, and Tk (like a great many GUI toolkits, FWIW) does not support multi-threaded use (well, not without techniques for another time) so if you're doing waveform visualization you've got some work ahead. (OTOH, modern CPUs have loads of time to spare too.)

Donal Fellows