This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with output of The Code

 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the following code , the ds.g() is getting called first after that the thread named ds.f() is being started but according to the code, the thread should get called first.



 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the following code , the ds.g() is getting called first after that the thread named ds.f() is being started but according to the code, the thread should get called first.


Not true. Once the new thread is started, it is now running independent of the main thread. So, whether the f() method or the g() method gets called first depends on the processor, the OS, priority, etc. These two threads are now racing each other, and on some OSes, f() will be called first, on others, g() will execute first.

Henry
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic