c#

  • Thread starter Thread starter mide
  • Start date Start date
A small bug fix :


Console.Write("Vroom,Vroom,Vroom");


But other than that, you really nailed the requirements document. Good
work!
 
LOL

And here I am thinking the nerds don’t have a sense of humor :)
 
A one car race seems very boring to me... Obviously each car should be in
it's own thread and fight for a shared resource (aka, a race condition :)
 
I dunno, that ParameterizedThreadStart doesn't give you much type-
safety (objParm can't be verified at compile), 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!

ThreadStart start = delegate { ThreadProc(icar); };
new Thread(start).Start();
Marc
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top