Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with vwait

27 views
Skip to first unread message

Roy Nurmi

unread,
Oct 29, 2001, 9:31:57 AM10/29/01
to
I am a trying to simulate semaphores in event driven environment using
vwait. This does not work in a way I am trying it, and I am confused why
not.

Example code:
----------------------------------------------
set state idle
proc test {i} {
global state
global response

puts "starting $i"

# waitfor idle state
while {[string compare $state idle]} {
vwait state
}

set state doing
puts "doing $i"

# waitfor response
vwait response
puts "done $i"

# set state back to idle
set state idle

return $response
}

foreach i {1 2 3} {after 0 "test $i"}
----------------------------------------------

Idea is pretty clear. Some processing should be allowed for single event
handler at the time. The processing involves event-driven socket-i/o, where
file events are used for finally writing variable response, which should
allow the first handler to continue, but...

% foreach i {1 2 3} {after 0 "test $i"}
starting 1
doing 1
starting 2
starting 3
% set response OK <<<<< this should trigger "done 1" but it does not?
OK
% set state idle <<<<< this allows handler #3 to continue
idle
doing 3
% set response OK <<<<< and this even allows the handler #3 to finalize
OK
done 3
doing 2

For some queuing reasons or whatsoever, setting the variable "response" does
not trigger the first handler to continue, while it waits some other pending
events to finish before it can continue. I must be missing something
important here, but what?

-- Roy


Chris Nelson

unread,
Oct 29, 2001, 1:28:39 PM10/29/01
to
Roy Nurmi wrote:
> ...

> For some queuing reasons or whatsoever, setting the variable "response" does
> not trigger the first handler to continue, while it waits some other pending
> events to finish before it can continue. I must be missing something
> important here, but what?

Multiple vwaits nest, they do not happen in parallel. The outermost
vwait cannot complete until all others return. It's clear if you look
at the implementation of [vwait] but I find it hard to describe better
than I have above. HTH.

Chris
--
Never doubt that a small group of thoughtful, concerned citizens
can change the world. Indeed, it's the only thing that ever has.
--Margaret Mead

0 new messages