Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What will be the output of following code ?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In one of the mock exam,

[DELETED]

When I performed a dry run on code ,I assumed output to be as main worker.And when I ran this code in IDE,it too printed main worker.
But ans to above Q in mock exam is indeterminate .

What is the correct ans ?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
What did you get when you ran it? Whatever it outputs would be the correct answer.

[edit - i should read the entire post before I reply]

Programming threads can create what is known as a 'race condition'. Two things are competing to do something, and whichever one finished first 'wins'. You could run threaded code 1000 times and get the same result each time, then the 1001st time get something different.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic