Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-07.dc1.easynews.com.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: synchronized methods "under the hood" Organization: Canadian Mind Products Reply-To: Roedy Green Message-ID: References: <7d23ce84-c209-43a2-bf88-2d112ce21a2e@googlegroups.com> User-Agent: ForteAgent/7.00.32.1200 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Lines: 23 X-Complaints-To: abuse@easynews.com X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Wed, 06 Mar 2013 04:28:58 -0800 X-Received-Bytes: 2080 Xref: csiph.com comp.lang.java.programmer:22735 On Tue, 05 Mar 2013 23:44:34 +0100, Sven Köhler wrote, quoted or indirectly quoted someone who said : >Such test and set methods are implemented in Java's Atomic* classes >(e.g. AtomicInteger). However, you need more than that to implement a >proper mutex. What I would call a proper mutex puts a thread to sleep, >if it cannot lock the mutex. To do that, you need to tell the kernel >that the thread is suspended I thought he was asking about what happens at the hardware level. Thread context switching I think is still done with software. Back in the 1990s I wrote a package in C to allow threads that ran on a single CPU. Threads had to be well behaved and call "have a conscience" periodically. It was remarkably simple, just save and restore contexts. It is quite bit more complicated when you can interrupt threads in mid instruction or when you have multiple CPUs. -- 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.