• Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Dumb question about threads

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a(), b() and c() at any time?

A. i.v is guaranteed always to be 0 or 1.
B. j.v is guaranteed always to be 0 or 1.
C. k.v is guaranteed always to be 0 or 1.
D. j.v will always be greater than or equal to k.v at any give time.
E. k.v will always be greater than or equal to j.v at any give time.

ANSWERS: A, B
Why A is correct? Assume that one thread executes method's a() i.inc(), after that another thread executes method's b() i.inc().
Value of i.v will be 2, isn't it ?
Where am I mistaken ?
[ November 12, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Result of searching for same question
 
My, my, aren't you a big fella. Here, have a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic