Re: Thread usage cases
[email protected] (Chaim Frenkel) 20 Aug 2000 01:14:08 -0400
| Newsgroups | perl.perl6.language.flow |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "BCW" == Bryan C Warnock <[email protected]> writes: >> 3. Subroutines >> >> sub foo { print "foo" } >> >> Thread1 Thread2 >> foo(); eval 'sub foo { print "bar" }'; >> >> This prints either "foo" or "bar". >> >> Thread2 replaces the coderef for &main::foo. This could happen *while* >> Thread1 is executing foo(). We can handle this by having Thread1 hold >> a reference count on the coderef while it is executing foo(). BCW> Hadn't considered this. Hmmm.... I'd claim, don't do that. And most likely that nothing bad will happen. Thread1 while in middle of executing the code will not even notice that the coderef that is _pointed_ at by ::foo has been replaced. The eval is building an optree and storing a pointer in the global namespace (or package perhaps.) BCW> (Assuming all program globals, of course.) BCW> Thread 1: $a = $b + $c; BCW> Thread 2: $d = $c / $a; BCW> Thread 1, doing statement locking, could lock these $a, $b, $c, while BCW> Thread 2 locks them $d, $c, $a. Potential deadlock between $a and $c. This really belongs on -internals. The visible language issues belongs here. <chaim> -- Chaim Frenkel Nonlinear Knowledge, Inc. [email protected] +1-718-236-0183