Thanks. Juan Carlos
Tcl 8.1 is thread-safe in the sense that each thread can have it's own
interpreters and the Tcl library won't stomp all over itself. Each
interpreter can only be accessed by ONE thread.
However, there are mechanisms to post events to other threads'
(synchronously or asynchronously). This is really what you want.
You create a single thread that puts the interpreter into the event
loop and talk to it from all your other threads.
See the code in tclThreadTest.c for an example ("testthread send"
DO NOT USE 8.0.x with multiple threads! It is NOT thread-safe.
David Gravereaux wrote:
> Scott Redman <red...@scriptics.com> wrote:
> >DO NOT USE 8.0.x with multiple threads! It is NOT thread-safe.
> Scott, I do it all the time.
> Rather than expect 8.0.5 to be thread-safe, I sync my own threads to
> work with Tcl's singlethreaded core. Which for me, works fine. I'm
> quite happy with a singlethreaded core.
> * David Gravereaux *
> Tomahawk Software Group
> Mahalo Aloha from Maui, Hawai'i
(for comp.lang.tcl readers)
This will work, but you need to be careful not to call the interpreter
or _any_ Tcl API fn's from more than one thread at a time (you need
to guard ALL calls to Tcl_* with mutexes or semaphores from your code).
Another way (8.0.x) is to guarantee that only one thread ever calls
the Tcl_* functions. Using 8.0.4, I wrote a simple queue where other
threads placed scripts to execute in the interepreter into the queue,
and I used events (Win32's CreateEvent()) to synchronize. Data
returned was always copied as a string and the return value.
This worked fine. But, 8.1 has this functionality built-in,
plus it allows you to keep the result in TclObj form and
call Tcl_ functions.
If you haven't already worked around the lack of thread safety
in 8.0.x, I'd highly recommend using 8.1 with --enable-threads
turned on (on Windows, change the makefile.vc to uncomment the
-- Scott Redman
Well, really i am in a mess. May I invoke Tcl_Eval concurrently in
different threads of control under Tcl 8.1b3 or not? I have searching
the scriptics site for the key thread and I haven´t still found a
definitive documentation on this issue. Any help???
With 8.1b3, you can call Tcl_Eval concurrently from two different
threads with (and only with) two separate interpreters. Basically,
each interp should be "owned" and used by one and only one thread.
You can use the new Tcl C-level APIs to send scripts to another
thread (synchronously or asynchronously) if you want two threads
to use the same interp concurrently. The examples are in
-- Scott R.
Scott, do you know whom you're talking to ?
David is the one who enlightened our tedious approaches to pre-8.1
thread safety, mainly with the AsyncMark/PostMessage trick. Where you in
hibernation when there was this long but informative exchange with Robin
and Gordon ?
(it was also mentioned in Tcl-URL, Feb 15th. But the pointer there is a
DejaNews thread-URL, which are well known to be broken these days)
> > (for comp.lang.tcl readers)
Although probably not as clear as I meant it to be,
that post was for c.l.t. readers, not David.
> > This will work, but you need to be careful not to call the interpreter
> > or _any_ Tcl API fn's from more than one thread at a time (you need
> > to guard ALL calls to Tcl_* with mutexes or semaphores from your code).
> > Another way (8.0.x) is to guarantee that only one thread ever calls
> > the Tcl_* functions.
I guess you didn't read the next paragraph (missing from your response):
> Another way (8.0.x) is to guarantee that only one thread ever calls
> the Tcl_* functions. Using 8.0.4, I wrote a simple queue where other
> threads placed scripts to execute in the interepreter into the queue,
> and I used events (Win32's CreateEvent()) to synchronize. Data
> returned was always copied as a string and the return value.
> This worked fine. But, 8.1 has this functionality built-in,
> plus it allows you to keep the result in TclObj form and
> call Tcl_ functions.
I too, got it working just fine. But, for someone who is just getting
into using Tcl/Tk in a multithreaded app, 8.1 makes things easier.
Speaking from EXPERIENCE, I do not recommend using 8.0.x with threads
(unless you're pretty bright and daring, or simply MUST use 8.0.x).
> Scott, do you know whom you're talking to ?
> David is the one who enlightened our tedious approaches to pre-8.1
> thread safety, mainly with the AsyncMark/PostMessage trick. Where you in
> hibernation when there was this long but informative exchange with Robin
> and Gordon ?
> (it was also mentioned in Tcl-URL, Feb 15th. But the pointer there is a
> DejaNews thread-URL, which are well known to be broken these days)
Do you know who you're talking to? No....and I don't expect you to.
I started at Scriptics in January, and didn't really start reading
c.l.t. until March. After 5 years away from Tcl, I picked it up again
a year ago at my last job, immediately embedded it (with great success)
into a multi-threaded application that used MFC and ObjectStore and
successfully ported the code to UNIX (including the MFC code and Tcl)
using the MainWin Win32 libraries. I even had our DCOM code feeding
scripts into the Tcl interpreter (even on UNIX).
David's approach and mine are two different ways to work around
the same problem: lack of thread-safety in 8.0.x. Having been through
that experience, I would highly recommend using 8.1. David's
contribution to the Tcl community is a great one, and I do respect
that (contrary to your belief). However, 8.1 is thread-safe, need
I say more?
-- Scott Redman
Wrong guess; the heart of David's scheme (like Gordon's) is also to use
events so that only the main Tcl thread eventually calls true Tcl_*
routines, as anybody can decipher by reading (say) 10% of the thread...
> Do you know who you're talking to? No....and I don't expect you to.
> I started at Scriptics in January, and didn't really start reading
> c.l.t. until March.
So what ? Does this mean that every time Scriptics hires a new guy, his
'history' will not go back before the day of his hiring ? What about
DejaNews ? What about the other guys at Scriptics ? Did they tell you
'Hey Scott, this is day One of the creation. Everything needs to be done
from scratch. Go ahead.' ?
Seriously, the one thing that drives me (along with a bunch of others)
out of my mind about Scriptics is that totally inconsistent attitude
about *history* (see the ongoing bug database issue). With DN alone and
(say) one hour a day reading clt, I have the sad feeling that I have a
more exhaustive vision of the collective wisdom of the community than
all of you at Scriptics.. This is sad because it means that you are
scarcely tapping the (Free !) work of this community, while you should
save every single drop, considering your well-known resource constraints
The thread code I wrote wasn't as clean as I'd like. After more
discussion with David, his model is cleaner. Both models should
still work in 8.1 though (mine was intended to be removed when 8.1
OK, the fun part: since Alexandre doesn't seem to like my posting
to c.l.t., should I continue posting or not? I don't have enough
time during the day to keep up with every thread (or do enough
research to accurately post, as apparently shown earlier in this
thread), and I may shoot my mouth off every once in a while. Is
that fine with everyone? Or should I just go back into the
Scriptics cave and continue hibernating?
Scott please don't hibernate! Keep shooting off!
The sometimes heated nature of the comments derives from people who have
1) A passion for Tcl and it's continuing success
2) Often a great deal of real-world experience of using Tcl
3) Often a very detailed understanding of the issues and in many cases a set
of creative solutions
4) A large degree of frustration at seeing Tcl crawling along - in part
because of a perception that Scriptics (and the Sun team before it)
subscribe to the wide spread disease that aflicts our industry - namely NIH
(Not invented here)
5) Don't like being regarded as lesser beings (perception or reality doesn't
I am certainly guilty of 1-4 inclusive, as are many others. We need to find
a less combative and more constructive means of opening up access to the Tcl
Core to get more :-
i) People (resources)
ii) Talent (more brains, more eyeballs)
I have been using Tcl in production systems since 1991/2 - and one of the
most time consuming things has been maintaining the Tcl Core - fixing bugs -
only to have to "fix" them again and again and again.
I would like to see a forum where the Tcl Core (lets ignore Tk for
simpicity) is broken down into a number of sub-systems, with one person who
may or may not work for Scriptics, "owning" or "overseeing" any changes to
that sub-system. We can acheive this by making the source accessable via CVS
with moderated commit enabled. There are at least 6 or 7 sub-systems that
could be readily identified.
This way we can start to build a real network of talented people working
towards a common goal - "A successful and stable Tcl environment for every
man, woman and child on the planet" [opps included a bit of my manifesto for
Seriously though it is an important issue and requires a much more
collabrative model than the one in place today. I can think of at least 20
people outside Scriptics (probably nearer 30-40) that could be harnessed in
this manner if the structure was condusive, which would dramatically
increase the quality, completeness, time-to-market etc.
It is time for Tcl to grow up - its potential is enormous, but will remain
largely untapped if these issues are not resolved.
Managing Director, Sensus Consulting Ltd.
Architect, Novadigm Inc.
DISCLAIMER: Any opinions herein are mine alone - I dare anyone to say
otherwise ! :-)
'Ts my position, too. I always like postings
from scriptics.com. Sometimes I want something
different from you-all; sometimes I let you
know. That's nothing at all like wanting to
hush you up.
Myself, I think the message you should get is
that you're in a job where a lot of smart,
energetic people care a bunch about what you
do. As that kind of fellow yourself, I figure
you'll like the challenge.
Take it easy, man :)
I do appreciate your posting to clt, as I do appreciate *any* kind of
manifestation of Scriptics on the newsgroup, after a scary period of
silence. What I'm reacting to is the internal organizational defaults of
Scriptics that your last posting just happened to bring to light.
Pointing them out is IMO a key to solving them; several of us have
already made constructive suggestions in that regard.
I feel total sympathy with the feeling expressed by Cameron and Matt in
this thread: the cooperation model Scr/clt needs to be revamped. But
please don't consider it as a 'request from non-paying customers' ! On
the contrary, it is an opportunity for Scriptics to stop wasting a
resource that is pretty scarce in a company of this size...
> OK, the fun part: since Alexandre doesn't seem to like my posting
> to c.l.t., should I continue posting or not? I don't have enough
> time during the day to keep up with every thread (or do enough
> research to accurately post, as apparently shown earlier in this
> thread), and I may shoot my mouth off every once in a while. Is
> that fine with everyone? Or should I just go back into the
> Scriptics cave and continue hibernating?
It's almost spring time, hibernation time is over :)
FWIW, I really like your posts and I really like the fact that you're
presenting a recurring peek inside how Scriptics feels about things.
To chime in with Matt Newman: even the occasional unfriendly discharge
is a sign of people meaning well and wanting the best for Tcl.
At Metrowerks, the compiler company, there's someone I've come to
remember as "MW Ron". He has consistently been representing MW for
years, in several newsgroups (now also Linux, and it's not easy to be
there, judging by the amount of beating taking place). I think Ron
probably is doing half the promotion by just being there, listening, and
responding in a calm and consistent manner.
You could perhaps post as "S Scott" :)
In any case, now that we've both blown off a little steam, let's
just put an end to it. Your comments about Scriptics and c.l.t.
are well taken (and those changes are in the works). We had
decided that anyone here that wanted to jump into threads
on c.l.t. should feel free to do so....that's why I'm posting
at all. For some (yet unknown) reason, people at Scriptics
were a little leary about posting. I think it had to do with
not causing trouble with comments like Alex's...personally I think
it's good for us to get out and post. In fact, you'll see others
posting (Scott Stanton, Melissa Hirschl, Brent Welch, etc.), but
somehow the newbie (me) is posting more often, maybe I'm just
Cameron suggested that I post some "stories" about using MFC,
Tcl/Tk, DCOM, and ObjectStore....look for those threads soon.
Alexandre Ferrieux wrote:
> Scott Redman wrote:
> > OK, the fun part: since Alexandre doesn't seem to like my posting
> > to c.l.t., should I continue posting or not? I don't have enough
> > time during the day to keep up with every thread (or do enough
> > research to accurately post, as apparently shown earlier in this
> > thread), and I may shoot my mouth off every once in a while. Is
> > that fine with everyone? Or should I just go back into the
> > Scriptics cave and continue hibernating?
Please do keep posting. It's refreshing to see a Scriptics presence.
Rens-se-LEER is a county. RENS-se-ler is a city. R-P-I is a school!
Ah, The Curse of Alex is upon us! :-)
> personally I think
> it's good for us to get out and post.
Yes it is. And it's nice to see daily postings from Scriptics. For a
long while, the only times we ever saw anything was when Melissa was
doing her PR thing or JO happened to drop by. It seemed like Scriptics
was content to just lurk. It gave the impression that Scriptics just
didn't care about Tcl as much as the community did. I think that annoyed
more than one person. Some are just more vocal about it. Heh heh heh!
> In fact, you'll see others
> posting (Scott Stanton, Melissa Hirschl, Brent Welch, etc.), but
> somehow the newbie (me) is posting more often, maybe I'm just
> more vocal.
Yeah, and don't stop!
I'm *reporting* to you that these subjects
are ones that interest a lot of readers.
They easily admit treatments that would fit
in well with the styles of www.scriptics.com,
the *Tcl Journal*, and other outlets. Maybe
Sarah will tell you that your job for this
week is to create good publicity by writing
up a success story. Maybe you'll work up a
piece for Stoian on your own time, 'cause
you're burning to tell how cool Tcl is.
Maybe you get *ENT* or developer.com to as-
sign you a slot for later this summer. My
recommendation is just that you think of
those as serious possibilities from which
you can choose.
> Yes it is. And it's nice to see daily postings from Scriptics. For a
> long while, the only times we ever saw anything was when Melissa was
> doing her PR thing or JO happened to drop by. It seemed like Scriptics
> was content to just lurk. It gave the impression that Scriptics just
> didn't care about Tcl as much as the community did. I think that annoyed
> more than one person. Some are just more vocal about it. Heh heh heh!
Believe me, we care about Tcl! We just don't all have time to read
the newsgroup. I'd just like to remark that I think the process of getting
bug fixes and patches into the core has improved considerably. The
last few 8.1 beta releases and the 8.0.* releases incorporate scores of
patches contributed by users. You can see just some of them listed at
Tcl is an incredibly reliable platform. I run it for months at a time
hosting www.scriptics.com using TclHttpd, http://www.scriptics.com/tclhttpd
No core leaks. No memory smashes. We have to be careful to maintain
this level of code quality, and it boils down to a Scriptics engineer
evaluating and adopting or rejecting patches. We use our best engineers
for this. Not to be snooty, but to say "We care!".
We care about the quality of Tcl and we know there are lot's of folks
that depend on it's success.
So, keep the dialog open, and the patches and bug reports flowing :-)
Tcl will continue to improve as we work together.
> > In fact, you'll see others
> > posting (Scott Stanton, Melissa Hirschl, Brent Welch, etc.), but
> > somehow the newbie (me) is posting more often, maybe I'm just
> > more vocal.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
As the engineering manager at Scriptics I can give a more acturate
answer: I had engineering team focused inteansly on shipping TclPro 1.0.
You may not realize it but Scriptics currently has only 4 engineers
in it's engineering team (at Sun Labs we had over 10 engineers and all
we did was work on the core!) If we are to survive as a company I
often have to have our team focus on product which certainly correlates
to the quite periods you've been talking about.
We are working on some of the things people have suggested for improving
communication with c.l.t. I think you will notice a big difference by
the end of the year. However, the biggest problem we have are resources.
We plan to raise head count to 12 by the end of the year which should
make a huge difference all by it self. The way you could help us the
most is to either apply to jo...@scriptics.com or tell your friends to
I will say this though. We do listen! Where we look the most is through
the bug database and the patches pages on the Scriptics site. For the
8.1b3 release we addressed over 100 bugs in 8.1b2. We also added support
for stubbs which was an idea (and implementation) that came straight
from people on c.l.t. We have heard some feedback that we don't toot
our horn (or the horns of those who supplied patches) enough. We added
the notion of an "acknolodgement" notice for each new release to help
in this area. We are also looking into ways to announce when bugs are
fixed and to eventually make the entire bug database public. Some of
these effots will take time - but they will happen.
>> Yes it is. And it's nice to see daily postings from Scriptics. For a
>> long while, the only times we ever saw anything was when Melissa was
>> doing her PR thing or JO happened to drop by. It seemed like Scriptics
>> was content to just lurk. It gave the impression that Scriptics just
>> didn't care about Tcl as much as the community did. I think that annoyed
>> more than one person. Some are just more vocal about it. Heh heh heh!
In response to that, Ray Johnson and Brent Welch stepped up to the plate to
speak on behalf of Scriptics, which is great. Let's just note that I
specifically said "it seemed like" and "it gave the impression that". I didn't
mean to imply that it was the reality of things.
Reminds me of a story: this man is raking his yard when he sees another man
across the street run smack into a little kid and levels the kid to the
gruond. Outraged, the first man drops his rake and runs across the street,
ready to deck the second man. He gets to the other side of the street, and
he's about to give a piece of his mind when he notices that the man is
standing all contrite, holding his white cane.... It's all about perception.