[concurrency-interest] Synchronizing on AtomicBoolean safe?

Nikolai V. Chr. nikolai at ifad.dk
Thu Jun 30 09:57:25 EDT 2005

Tim Peierls wrote:

> This will work, but why use AtomicBoolean at all?

Sometimes I wish to just set a value on it, using set(). And I was 
hoping that while I was synchronizing on the AtomicBoolean, I was 
synchronizing on the same same object that AtomicBoolean was 
synchronizing on.

Just like doing this would do:

SynchronizedBoolean protocolSupportEnabled = new 

synchronized(protocolSupportEnabled.getLock()) {
  old = protocolSupportEnabled.set(enable);
  if(enable) {

  } else {

And someshwere else I would do this at the same time:


And then expect them to lock on the same Object. The question is, will 
the previous posted code do the same?

Nikolai V. Christensen, Computer Engineer,
Simulation and Training department
IFAD TS A/S, Østre stationsvej 43 2.tv, DK-5000 Odense C
Denmark, EU
Phone: +45 63 11 02 11  Fax: +45 65 93 29 99
WWWeb: http://www.ifad.dk
e-mail: Nikolai.V.Christensen at ifad.dk

More information about the Concurrency-interest mailing list