Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
TCL thread problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
py  
View profile  
 More options May 24 2011, 3:53 pm
Newsgroups: comp.lang.tcl
From: py <pyj...@shaw.ca>
Date: Tue, 24 May 2011 22:53:20 +0300
Local: Tues, May 24 2011 3:53 pm
Subject: TCL thread problem
Hi,

I had been using thread structure like this on my tcl8.4, win2k8 R2 64b
platform

set var 3
set tid [thread::create {
   #1
   #initialization code for aux thread
   proc pro1 def {} {
     #blah
   }
   thread::wait

}]

#2
set waiting 1
after 10000 {set waiting 0}
vwait waiting

#other stuff here

#3
thread::send -async $tid [list proc1]

Once every so often (let say 2/100 execution cycle), when the code gets
to #3, tcl pops up an error that says "proc1" is undefined.

Now, as I understand, this is happening because there is no guaranteed
that #1 is executed before #3. thread::create returns as soon as the
thread is created, without executing all the aux thread initialization
code. So #2 is bought in as a stop gap. It gives some breathing room for
the thread finish initialization and move to event loop. I don't really
like this workaround, since it doesn't scale with the evolving
initialization code. So if the wait time is not large enough, I would
still see the proc not define error. What other option do I have?

Also, is there any way to pass a parameter from the main thread to the
spawn thread (the var variable) during thread::create?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ralf Fassel  
View profile  
 More options May 25 2011, 4:35 am
Newsgroups: comp.lang.tcl
From: Ralf Fassel <ralf...@gmx.de>
Date: Wed, 25 May 2011 10:35:30 +0200
Local: Wed, May 25 2011 4:35 am
Subject: Re: TCL thread problem
* py <pyj...@shaw.ca>
| set tid [thread::create {
|   #1
|   #initialization code for aux thread
|   proc pro1 def {} {
|     #blah
|   }
|   thread::wait
| }]
--<snip-snip>--
| Once every so often (let say 2/100 execution cycle), when the code
| gets to #3, tcl pops up an error that says "proc1" is undefined.

| Now, as I understand, this is happening because there is no guaranteed
| that #1 is executed before #3. thread::create returns as soon as the
| thread is created, without executing all the aux thread initialization
| code.

As I understand tcl::threads, the thread::send from #3 will only get
handled by #1 when the event loop is entered in #1.  This is done by
thread::wait only after the proc has been defined, so there is no way
that #1 reacts to the thread::send before the proc has been defined.
Note that there is an obvious typo in the proc name ('pro1' vs 'proc1')
in the code you've posted which might be the cause of the problem.

R'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre Ferrieux  
View profile  
 More options May 25 2011, 4:37 am
Newsgroups: comp.lang.tcl
From: Alexandre Ferrieux <alexandre.ferri...@gmail.com>
Date: Wed, 25 May 2011 01:37:02 -0700 (PDT)
Local: Wed, May 25 2011 4:37 am
Subject: Re: TCL thread problem
On 24 mai, 21:53, py <pyj...@shaw.ca> wrote:

That's strange. This race condition should happen only if your
"initialization code for aux thread"calls the event loop (with
[update], [vwait], [thread::wait], sync [http::geturl] or similar
package doing it under the scenes). Please clarify, or better try to
reduce the code and see if you still get the bug.

> Also, is there any way to pass a parameter from the main thread to the
> spawn thread (the var variable) during thread::create?

Thread::create's argu;ent is a string, you can manipulate it.
Typically:

 set initcode {
    # blah
    proc ...
    proc ...
    set params }

 append initcode [list $params] \n

-Alex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
py  
View profile  
 More options May 25 2011, 2:24 pm
Newsgroups: comp.lang.tcl
From: py <pyj...@shaw.ca>
Date: Wed, 25 May 2011 21:24:03 +0300
Local: Wed, May 25 2011 2:24 pm
Subject: Re: TCL thread problem
Thanks guys. You are right, there are "update" in my initialization code
that make the thread enter event loop prematurely. I was aware of vwait
and thread::wait, didn't know about "update". After I made the change,
the race condition is gone

On 5/25/2011 11:37 AM, Alexandre Ferrieux wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »