T
Thomas B.
Hello. I had the following code and it worked in Ruby that came with
some old Windows One-Click Installer (now I don't know which version it
was):
m=Mutex::new
m.lock
Thread:new\
{
# something1
m.unlock
# something2
}
m.synchronize{}
The main thread was supposed to create a new thread, and then wait for
this thread to complete executing something1. But now (RUBY_PATCHLEVEL
#=> 287) the unlock done from the new thread raises ThreadError: not
owner.
OK, that's true that I try to lock and unlock the mutex in two distinct
threads, but is it that bad? Now I need some other way to synchronise
the threads.
I cannot take something1 out of the second thread, because the whole
content of the second thread is in fact wrapped in some begin rescue
clauses, and I don't want to break the scoping, too. The only solution I
can think of now is this:
Thread:new\
{
# something1
Thread.main.wakeup
# something2
}
sleep
But now I risk calling wakeup before the main thread gets to the sleep
command, which will break the whole thing. Of course I could set up some
flag or something...
Are there any better ideas around? Thanks.
TPR.
some old Windows One-Click Installer (now I don't know which version it
was):
m=Mutex::new
m.lock
Thread:new\
{
# something1
m.unlock
# something2
}
m.synchronize{}
The main thread was supposed to create a new thread, and then wait for
this thread to complete executing something1. But now (RUBY_PATCHLEVEL
#=> 287) the unlock done from the new thread raises ThreadError: not
owner.
OK, that's true that I try to lock and unlock the mutex in two distinct
threads, but is it that bad? Now I need some other way to synchronise
the threads.
I cannot take something1 out of the second thread, because the whole
content of the second thread is in fact wrapped in some begin rescue
clauses, and I don't want to break the scoping, too. The only solution I
can think of now is this:
Thread:new\
{
# something1
Thread.main.wakeup
# something2
}
sleep
But now I risk calling wakeup before the main thread gets to the sleep
command, which will break the whole thing. Of course I could set up some
flag or something...
Are there any better ideas around? Thanks.
TPR.