Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22732

Re: synchronized methods "under the hood"

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: synchronized methods "under the hood"
Organization Canadian Mind Products
Message-ID <fpkcj8l7bqvg5qoki7m0b4dom3ha0qfp0f@4ax.com> (permalink)
References <7d23ce84-c209-43a2-bf88-2d112ce21a2e@googlegroups.com>
Date 2013-03-05 12:19 -0800

Show all headers | View raw


On Tue, 5 Mar 2013 09:02:25 -0800 (PST), bob smith
<bob@coolfone.comze.com> wrote, quoted or indirectly quoted someone
who said :

>How do synchronized methods work "under the hood"?
>
>Is there some kind of byte associated with each object that acts as a semaphore?

At the hardware level these are usually handled by some sort of test
and test instruction.  It tests if a byte is zero, and if it is, sets
it to 1.  It locks out any other CPU or thread from interfering
between the test and set.  If reports if the byte was zero to start
(in other words we successfully locked.) Test and Set is an "atomic"
operation.

The last time I peeked was in the hey days of Univac and CDC.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
One thing I love about having a website, is that when I complain about
something, I only have to do it once. It saves me endless hours of 
grumbling.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

synchronized methods "under the hood" bob smith <bob@coolfone.comze.com> - 2013-03-05 09:02 -0800
  Re: synchronized methods "under the hood" Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-03-05 09:15 -0800
  Re: synchronized methods "under the hood" Jan Burse <janburse@fastmail.fm> - 2013-03-05 18:59 +0100
    Re: synchronized methods "under the hood" Jan Burse <janburse@fastmail.fm> - 2013-03-05 19:16 +0100
    Re: synchronized methods "under the hood" Jan Burse <janburse@fastmail.fm> - 2013-03-06 15:24 +0100
  Re: synchronized methods "under the hood" Roedy Green <see_website@mindprod.com.invalid> - 2013-03-05 12:19 -0800
    Re: synchronized methods "under the hood" Sven Köhler <remove-sven.koehler@gmail.com> - 2013-03-05 23:44 +0100
      Re: synchronized methods "under the hood" Roedy Green <see_website@mindprod.com.invalid> - 2013-03-06 04:28 -0800
        Re: synchronized methods "under the hood" Jan Burse <janburse@fastmail.fm> - 2013-03-06 15:20 +0100

csiph-web