Michael Malone
3/9/2009 3:24:00 AM
>
> I'm really not sure what you're asking. All you get from Queue#pop is
> child threads. The thing is that the operating system decides (and it is
> quite out of your control) which thread will have a chance to execute
> next. So apparently Ruby 1.8 always chose to let the child threads have a
> chance before you reached the THREADS.times loop. Ruby 1.9, on the other
> hand isn't giving the child threads a chance to run any code until you
> hit the th.join() call. Thus, when you try to access th[:index] and th
> [:n], the child threads haven't had a chance to update them yet. Once you
> run thread 0, that takes long enough that the other threads also get a
> chance to execute and set values for th[:index] and th[:n], and that's
> why those values are available.
>
> But there's no guarantees about who gets to execute when, and you
> shouldn't count on any. This is not a bug.
>
> Unfortunately, I don't have any ideas about a good way to ensure that the
> threads execute far enough to have set th[:index] and th[:n] before you
> print them.
>
>
Ahhh, now I understand and yes, you're quite right. Sigh. If I join
the thread before printing the index, then everything works as
expected. Back to square one with my other problem.... But I haven't
come up with something simple that displays the right behaviour, so I'll
give that a bit more thought before I post that question. Thanks for
your help.
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
=======================================================================