> I dunno, that ParameterizedThreadStart doesn't give you much type-
> safety (objParm can't be verified at compile),
Hey, I know the drivers wear helmets and fire suits, but no one ever said
racing was _safe_. :p
> so as a
> "fix" (cough)... plus it starts the "race" earlier, and now the
> competition can be won by a car that wasn't even competing!
Yes, I do like that your code has the possibility that all the cars that
start will be #4, with 0, 1, and 2 left out of the race entirely. :) I'm
not sure I see how it starts the race "earlier" though.
Pete
Marc Gravell - 23 May 2008 22:51 GMT
> not sure I see how it starts the race "earlier" though.
Because the (thread) race can happen before any of the cars even start
their engines ;-p
With the original code I can see that multiple cars can win, and I can
see some randomness in the Vroom / moorV, but neither can happen
until at least 2 cars are moving ;-p
Marc
Peter Duniho - 24 May 2008 00:18 GMT
>> not sure I see how it starts the race "earlier" though.
>
[quoted text clipped - 3 lines]
> see some randomness in the Vroom / moorV, but neither can happen
> until at least 2 cars are moving ;-p
How does your proposal change the behavior of the original code? With
either code, as near as I can tell, you can have a winner with only one
car "moving", and you only get "randomness" with two. How does calling
the ThreadProc method through an anonymous method rather than directly via
a delegate make things different?
And by "I can see" are you telling me that you actually compiled and ran
the code? It never occurred to me to try that. :p
Pete
Marc Gravell - 24 May 2008 09:48 GMT
No - with the race condition introduced by the captured variable, you
can get randomness with one car - because it can start as either car 0
or car 1 [in reality I wouldn't expect to see many 0s, but it is
possible]
And the "I can see" was based on looking at the code, not running
it... funny thing about race conditions is that they are a pain to
reproduce on demand ;-p
I guess you could say that the captured variable changes which cars
make it to the starting grid, where-as the bools affect the in-race
behavior. Just thought - you could make it even more interesting* by
removing the volatile - then it is up to the compiler whether it still
has the bool cached...
*=for small values of interesting
I'm thinking we're probably taking this too seriously, though ;-p
Marc
Peter Duniho - 24 May 2008 18:08 GMT
> No - with the race condition introduced by the captured variable, you
> can get randomness with one car - because it can start as either car 0
> or car 1 [in reality I wouldn't expect to see many 0s, but it is
> possible]
Ahh...I see. We have a terminology disconnect. I was viewing the number
passed as the stencil put on the side of a given car (which would possibly
then be erroneous for one or more cars...and most likely would be :) ),
with the thread representing the car. You are viewing the number as the
car itself.
Now everything makes sense.
> [...]
> I'm thinking we're probably taking this too seriously, though ;-p
"Too seriously" for what? What good is a joke if you can't beat it to
death? :)
Pete
Marc Gravell - 25 May 2008 09:15 GMT
> "Too seriously" for what? What good is a joke if you can't beat it to
> death? :)
;-p