dcsimg
can u plz tell how to write code for inter-thread communication
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   umrao_jaan
Posted On:   Sunday, October 15, 2006 04:42 AM

Create two threads, each represents a car. Each car thread is given a speed in a random fashion (and this car will remain in this speed). After a certain interval (5 second, for example), each car asks the other car "I am Car 1 (or 2) , where are you?" and yield (waiting for an answer); the other car would answer "I am Car 2 (or 1), I am 300 miles (for example) from start." and then yield (for the first car to resume execution). Repeat the racing and communication for 5 minutes and then announce (output) the winner and each car's total traveling distance. Repeatedly run your program for 5 times, then compare the outputs and answer the following questions: if    More>>

Create two threads, each represents a car.
Each car thread is given a speed in a random fashion (and this car will remain in this speed).
After a certain interval (5 second, for example), each car asks the other car
"I am Car 1 (or 2)
, where are you?" and yield (waiting for an answer); the other car would answer
"I am Car 2 (or 1), I am 300 miles (for example) from start."
and then yield (for the first car to resume execution).
Repeat the racing and communication for 5 minutes and then announce (output)
the winner and each car's total traveling distance. Repeatedly run your program for 5 times,
then compare the outputs and
answer the following questions:
if one of the cars is assigned a higher speed than the other car,
is this car bound to win? Why?
Note: "inter-thread communication" needs only be simulated by proper screen output

   <<Less

Re: can u plz tell how to write code for inter-thread communication

Posted By:   WarnerJan_Veldhuis  
Posted On:   Sunday, October 15, 2006 03:05 PM

I am amazed by the arrogance of you, just dropping your homework in here... You didn't even ask a question, you didn't even show what you got so far... You just are completely in the dark about this aren't you? Unless you show some motivation, and start coding, then you can ask specific questions. If you're not able to do that, drop the CS class and go here

Re: can u plz tell how to write code for inter-thread communication

Posted By:   Robert_Lybarger  
Posted On:   Sunday, October 15, 2006 12:09 PM

You might try reading this lesson brought to you by the very creators of the language.
About | Sitemap | Contact