views:

44

answers:

3

Now here's something interesting. When I have more than one thread in Tcl invoking package require Expect, I get a seg fault.

e.g.

package require Threads  
package require Expect

set t [thread::create]

thread::send {package require Expect}

puts "blarg! Damned thing crashes before I get here"

This is not a good time. Any thoughts?

+2  A: 

Expect and Threads don't go together too well. Its the complexity you get from fork() + threads that can bite a lot there and lead to deadlocks and all kinds of uglyness. Usually not a good idea to combine the two.

If you really need Expect and the added concurrency a multi process approach with on multi threaded driver program and one single threaded expect process might work better. If you used tcllibs comm package the api's for sending commands are not that much different either (you mostly miss the tsv and tpool stuff if you used comm).

But it shouldn't segfault for sure. Which Expect/Threads/Tcl core combination did you use (e.g. ActiveStates ActiveTcl bundle or some self compiled stuff on an unusual platform?)

schlenk
A: 

It's all from the latest debian packages, Ubuntu 9.0.4, 64 bit.

One alternative is to organize the code such that one thread is dedicated to handling all expect calls...which isn't the most elegant, generic solution but it might have to do.

A: 

The C code of the expect library (loaded with package require Expect) is not thread-safe (it probably uses global variables or else). I tried a lot to work around this limitation because I wanted to have a load balancing algorithm based on the Thread library which would pilot some expect code launching builds on a pool of slave machines. Unless you are very good at C and want to enhance expect, I would rather suggest to launch expect interpreters (in their own OS process) each time you need to use it from your Thread-enabled program. But of course I don't know your problem to solve, and this would only work if the "expect works" are unrelated.. Good luck anyway..

Cheers,
Christophe.

= At no time is freedom of speech more precious than when a man hits his thumb with a hammer. --Marshall Lumsden =

Christophe Muller