Weird thread sync behavior (only every other notify works...)

So what's up with this? Why does only every other call to notify() within SyncThread work? I've tested this app in 1.4.2_03, 1.4.2_08 and 1.5.0_04 and they all report the following output:
Count is 2
Count is 4
Count is 6
Count is 8
Count is 10
Count is 12
Count is 14
Count is 15
:public class JavaThreadSyncBug {
:    public static void main(String args[]) {
:        try {
:            SyncThread s = new SyncThread();
:            CallerThread c = new CallerThread(s);
:            s.start();
:            c.start();
:            s.join();
:        catch(Exception e) {
:            System.out.println(e.getMessage());
:public class SyncThread extends Thread {
:    boolean terminated = false;
:    int count = 0;
:    public SyncThread() {
:        super("SyncThread");
:    synchronized public void run() {
:        while (!terminated) {
:            try {
:                wait();
:                System.out.println("Count is " + count);
:            catch(InterruptedException e) {
:                System.out.println(e.getMessage());
:    synchronized public void touch() {
:        ++count;
:        notify();
:    synchronized public void terminate() {
:        terminated = true;
:        if (isAlive()) {
:            notify();
:public class CallerThread extends Thread {
:    SyncThread s = null;
:    CallerThread(SyncThread _s) {
:        super("CallerThread");
:        s = _s;
:    public void run() {
:        try {
:            for (int i = 0; i < 15; ++i) {
:                sleep(1000);
:                s.touch();
:            s.terminate();
:        catch(InterruptedException e) {
:            System.out.println(e.getMessage());
:}I should point out that I can work around this by doing the following in SyncThread's touch function:
notify();
notify();
or by calling
notifyAll();
But I am really curious about what's going on here...
Thanks,
Ken

>
Rhetorical question:
Is there an underlying reason why a joining thread is
eligible to be scheduled via a call to notify()? It
seems to me that the joining thread (by definition)
wouldn't care about anything until the thread it's
joined to has terminated...Even 'Rhetoricallly' I don't know. I have just taken your example a bit further so that 2 threads are joined and then you only get every 3rd notify()! If I use notifyAll() I see everyone!
public class JavaThreadSyncBug
    public static void main(String args[])
        try
            final SyncThread s = new SyncThread();
            CallerThread c = new CallerThread(s);
            s.start();
            c.start();
            new Thread()
                public void run()
                    try
                        s.join();
                        System.out.println("XXXX");
                    catch(InterruptedException e)
                        System.out.println(e.getMessage());
            }.start();
            s.join();
        catch(Exception e)
            System.out.println(e.getMessage());
class SyncThread extends Thread
    boolean terminated = false;
    int count = 0;
    public SyncThread()
        super("SyncThread");
    public void run()
        while (!terminated)
            synchronized(this)
                try
                    wait();
                    System.out.println("Count is " + count);
                catch(InterruptedException e)
                    System.out.println(e.getMessage());
    synchronized public void touch()
        ++count;
        System.out.println(count);
        notify();
    synchronized public void terminate()
        terminated = true;
        if (isAlive())
            notify();
class CallerThread extends Thread
    SyncThread s = null;
    CallerThread(SyncThread _s)
        super("CallerThread");
        s = _s;
    public void run()
        try
            for (int i = 0; i < 15; ++i)
                sleep(1000);
                s.touch();
            s.terminate();
        catch(InterruptedException e)
            System.out.println(e.getMessage());
}

Similar Messages

  • Only every other keystroke registers in tty screen!

    Oh my! This problem is a huge pain in the butt!
    It seems that most of the time only every other keystroke registers on my HTPC running arch when I am in the tty screen.
    I know this isn't an issue with my input device as it happens with both my wired keyboard and my wireless mini remote keyboard. I have had a hard time finding anything on line about similar problems and was wondering if anyone might have a clue as to what might be behind this issue.
    Thanks in advance!

    Here's the fix:
    In "/etc/modprobe.d/modprobe.conf" add:
    # Fix key skip problem in tty
    options psmouse rate=40
    Does that fix it?
    I learned it somewhere on the Arch forums...
    Found it! https://bbs.archlinux.org/viewtopic.php … 79#p865979
    Last edited by drcouzelis (2011-12-23 02:29:02)

  • My AppleTV will not play anything over Air Play.  Every other function works perfectly, and my Internet/router are working at top speed.  I can watch HD Netflix and YouTube but nothing via my iTunes library on my MacBook or iPad.  All software is updated.

    Every other function works perfectly, and my Internet/router are working at top speed.  I can watch HD Netflix and YouTube but nothing via my iTunes library on my MacBook or iPad.  All software is updated.  The AppleTV will recognize that Air Play is trying to do it's thing, but with music files it sounds like they're skipping and video files just load endlessly. 

    I'm searching for an answer to almost the same exact problem, using almost the same exact hardware and software. Has an answer been found?
    The files that I'm trying to burn come from eMusic, and they are formatted mp3. Recently, (after the iTunes update to 9.2.3?,) they would not drag and drop from iTunes into Toast. From several different discussions I've tried working around this by dragging to the desktop first then dragging and dropping to Toast, going to Toast from a programmer's homemade help window, " iToons," and today, after talking with Apple support, going directly to Toast from my eMusic folder. Alas, all recordings do not perform like they use to. Sometimes they play and sometimes not. There is one I managed, that is listenable, but sometimes I have to put it in my car stereo over and over again as it gets ejected with an error code, sometimes, finally it takes it... Some of the recordings on other disks I've burned are not clean - they have white-noise sounds creeping in... I use to have none of these problems. One time as I was listening to a CD that managed to play, and it just stopped playing... Is there an answer out there to get back to how it use to be? Thanks for you help.

  • Firefox won't start up, when clicked, whereas every other browser works.

    Firefox won't start up, when clicked, whereas every other browser works.

    See:
    *http://kb.mozillazine.org/Browser_will_not_start_up
    Can you start Firefox in Safe mode?
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    You can use one of these to start Firefox in <u>Safe mode</u>:
    *On Windows, hold down the Shift key while starting Firefox with a double-click on the Firefox desktop shortcut
    *On Mac, hold down the Options key while starting Firefox
    *Help > Restart with Add-ons Disabled
    Another possible cause is security software (firewall,anti-virus) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox and the plugin-container from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.org/kb/Server+not+found
    *https://support.mozilla.org/kb/Firewalls

  • Firefox prints only every other page on a bulk print run, why?

    I use Firefox to bulk print Ebay invoices. It's been just fine for years. But 2 days ago it started printing just every other page in full. Intervening pages had only the top 20% printed (headers and footers are set to blank), and it prints one extra blank sheet at the end of the print run. 'Fit to page width' is enabled. I print at A5 size. When I check print preview it shows the problem exactly. The preview confirms 80% of every second page is missing, and there is an extra blank page at the end. Anyone else have this problem?

    Hi ashura,
    When you print, check to see which presets and defaults are selected. It could be a stored preference to only print every other.
    In order to reset these preferences in Firefox:
    *[[Fix printing problems in Firefox]]
    Did this help?

  • IE 9 - can't sign in to ebay (every other site works fine, as before)

    I can't sign in to ebay from my main computer; I can get to the main ebay website (www.ebay.com) and I can get to sign-in page, but when I enter my user ID and password, ebay displays an error page and returns immediately
    to the sign-in page. The error page flashes by so quickly I can't read it, although I have tried probably 30 times or so to catch enough of the words to determine at least the subject of the problem. I've cleaned out the cache, including all cookies; I've
    added several ebay pages to trusted sites, I've tried it with security levels set on lowest setting, and checked everything I know and still no results. I've also contacted ebay and done everything they suggested (which was actually very little), still with
    no success. Ebay is not listed as a blocked site.
    We have a laptop which accesses from our home WIFI network, and on it I am able to sign in just fine. Also, with Mozilla Firefox I am able to sign in just fine. So there is some small setting on my main computer that is preventing me from signing in. I've
    searched all of the Tools - Internet Options tabs and settings, and can't find out what may be preventing my access. Pop-up blockers are off, both in IE9, Google, etc.
    Every other website I've visited since this began happening works fine. The problem began when I downloaded the latest updates from Windows Update about 3 or 4 days ago. My IE9 is completely up to date, I use Windows 7 and ESET security software. Nothing
    has changed in my software or in how I access ebay except for the latest Windows updates. Please advise; thank you.

    Hi,
    Tools>Internet Options>Security tab, click "Reset all zones to default"
    Trusted Sites icon, 'Sites' button... remove Ebay from your Trusted Sites list..... websites work just as well in the (default) Internet Zone.
    Create separate windows accounts for each user that shares your computer, so that nothing is changed on your windows account without your knowledge.
    For the best security open Ebay with InPrivate browsing.
    Ebay won't login properly if you have their site in the Trusted Sites list in IE because there is a security setting to prevent navigation to zones of lower integrity.... Ebay use a sub-domain to validate your credentials and have a number of different global
    websites with different domains.
    For consumer help with IE select the Help>Online Support menu from IE and follow the links for your windows and IE versions.
    this forum is for Questions regarding Internet Explorer 8, 9 (and 10 Release Preview) for the IT Pro Audience. Topics covered are: Installation, Deployment, Configuration, Security, Group Policy, Management questions. If you are a consumer looking for answers
    or to raise a question, it's highly recommended you head on over to http://answers.microsoft.com/en-us
    Rob^_^

  • HP 48GX, weird on key behavior -- only works when simultaneously pressing a white key

    Hi all,
      I have an hp48gx calculator that I love, but, the "on" button no longer gets recognized as being pressed unless one of the top row buttons is pressed at the same time (e.g., the white "C").
    example:  to turn off, I need to do rshift, then hold on and press "C".  expected behavior: rshift, on should turn the calculator off.
    example: to turn up contrast, I have to hold C-On and press .  expected:  on and press plus
    Any thoughts?
    Thanks
     Jonathan

    Try a warmstart, that is hold down the ON key, press and release C, release ON.
    If that doesn't work, try doing a restart with a paper-clip reset. Remove the upper right (as viewed from the back) rubber foot. You'll see a small hole with the letter R next to it. Gently insert a straightened paper-clip (or something similar) straight in as far as it will go, and release it.
    If the above doesn't solve it, the problem may be more serious:
    Try pressing on the bezel, between the display and the soft keys, while you press a key.
    The problem then is that the rubber support inside tends to deteriorate.
    Here is a thread that discusses the problem:
    http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv019.cgi?read=151696
    If you have a wish to try to repair it:
    here is a guide to opening:
    http://users.ju.edu/hduong/open/
    and for repairing:
    http://users.ju.edu/hduong/repair/
    (about halfway down see "keyboard connector" and "Rubber Under Keyboard Contacts" which is the bit that has to be replaced).
    (Note: the SX shown in the links above is physically the same as the GX)
    Someone's temporary fix without opening the calculator:
    http://h30499.www3.hp.com/hpeb/attachments/hpeb/bsc-408/13673/1/HP42S.jpg
    Note: I do not work for HP, I just like playing with calculators :-)

  • Why can't people click on anything on my website when using firefox. Every other browser works

    hi guys,
    so i have a website but people using firefox cant click on anything but the navigation at the top.
    check the website out on IE or safari or chrome then compare it to firefox
    anybody know why this is happening?
    thanks!

    Ok so I looked at whe the main problems were and it seems as though they were in my Wordpress widgets. I disabled those and now everything is clickable.
    Only thing I'm not quite sure of is that the errors say that I have tags open or I missed closing them. But everything seems ok. I don't know the language that well (only very very basic stuff)
    I'll try and see if I can figure it out. I think I'm putting <p> and font tags where I am not suppose to

  • (Firefox is so extremely slow, it's unbelievable (google needs about 1 minute to load). Every other browser works perfectly fine. How is that possible

    I love Firefox and I still want to use it but my love doesn't go as far as waiting one minute for every page to load.
    I deactivated every Plug in. I tried with the other versions Firefox offers (moon something).
    I uninstalled several times and installed it again.
    Please Help Me!!!!!!

    uninstall the proxytube addon and set firefox to "use no proxy" under options > advanced > network > connection - settings... in order to get back to the normal browsing speed

  • Can no longer burn cd's using iTunes, every other application works - HELP

    I brought my iPOD mini to an apple store - can burn playlists on the mac's to a cd
    Can't do it at home anymore
    People at the Apple store had no ideas/clues/nothing
    I an use Windows media player and burn all other types of audio files
    I have a Samsung CDRW/DVD SM-308B
    Please help

    Microsoft Windows 2000 Professional Service Pack 4 (Build 2195)
    iTunes 7.0.2.16
    CD Driver 2.0.6.1
    CD Driver DLL 2.0.6.1
    LowerFilters: PxHelp20 (2.0.0.0), cdr4_2k (5.3.2.31),
    UpperFilters: GEARAspiWDM (2.0.6.1), pwd_2k (5.2.0.91), cdralw2k (5.3.2.31),
    Video Driver: NVIDIA RIVA TNT2 Pro\RIVA TNT2/TNT2 Pro
    Found aspi32 running.
    IDE\DiskWDCWD400BB-75CLB0_____________________05.04E05, Bus Type ATA, Bus Address [0,0]
    USBSTOR\DiskHP_____Officejet_7410_1.00, Bus Type USB
    USBSTOR\DiskHP_____Photosmart_81001.00, Bus Type USB
    IDE\CdRomSAMSUNGCDRW/DVD_SM-308B________________T100___, Bus Type ATA, Bus Address [0,0]
    If you have multiple drives on the same IDE or SCSI bus, these drives may interfere with each other.
    Some computers need an update to the ATA or IDE bus driver, or Intel chipset. If iTunes has problems recognizing CDs or hanging or crashing while importing or burning CDs, check the support site for the manufacturer of your computer or motherboard.
    Current user is an administrator.
    D: SAMSUNG CDRW/DVD SM-308B, Rev T100
    Audio CD in drive.
    Found 6 songs on CD, playing time 24:49 on Audio CD.
    Track 1, start time 00:02:00
    Track 2, start time 04:26:39
    Track 3, start time 09:26:63
    Track 4, start time 13:06:48
    Track 5, start time 17:20:64
    Track 6, start time 21:10:00
    Audio CD reading succeeded.
    Get drive speed succeeded.
    The drive CDR speeds are: 2 4 8.
    The drive CDRW speeds are: 2 4 8.
    The last failed audio CD burn had error code 4310(0x000010d6). It happened on drive D: SAMSUNG CDRW/DVD SM-308B on CDR media at speed 8X.

  • I have lost volume with YouTube on Firefox - only. Other browsers work fine with Youtube??

    F5 and other volume controls including the speakers cannot solve the issue. YouTube has been fine on Firefox forever, till last week. Now the volume is barely there at all. All ok with Chrome so its not the laptop?
    Thanks

    Did you check the volume setting for the plugin container process in the volume mixer while a video is playing?
    You can also try to clear the Flash local storage and settings for YouTube or all of them.
    *Windows Control Panel > Flash Player, click Delete All and Delete Data
    Flash Website Storage Settings panel:
    * http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager07.html
    Global Storage Settings Panel:
    * http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager03.html
    Flash Local storage settings Help:
    * http://www.macromedia.com/support/documentation/en/flashplayer/help/help02.html

  • Since yesterday morning Firefox can not load Facebook. Every other browser works fine. Tried many computers, both Windows and Macs, same issue. Help!

    Facebook loads fine on multiple PCs and Macs in any number of browsers but NOT with Firefox on any of them. Started Friday AM. It tries to load but takes FOREVER and never gets "up". Frustrating since FF is my browser of choice despite the fact it has recently become the slowest of all the browsers I've tried. Be nothing like THIS slow. Other sites seem to be unaffected, just Facebook.

    What you describe look like a problem of infection, for me.
    I have W7 and FF34 as you, and FF is faster than Chromium.
    So, except a problem of corruption of the code of your Firefox (and maybe problems generated by some addons or plugins), I' rather believe that there is malware(s) on your computer.
    For FB, it could be the adware pushow**.dll, like pushow35.dll, in c:\windows\system32
    What security programs do you use on your computer ?
    If you want, you could also try to start Firefox in "safe mode", to see if there is a difference of speed and on FB.

  • How to read a text file and only output every other line?

    I am just writing a program that reads a file but outputs only every other line. Any ideas...please? thanks

    I'd start with something like this and expand on it as you go:
    File file = <whatever>;
    BufferedReader in = null;
    try {
        in = new BufferedReader(new FileReader(file));
        int i = -1;
        for (String line = null; (line = in.readLine()) != null; ) {
            if ((++i % 2) == 0) {
                System.out.println(line);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
    }Shaun

  • KDE: Laptop only sleeps when closing lid every other time

    Hello all,
    I'm running KDE 4.14.1 on an older Toshiba Satellite laptop. In the KDE System Settings, I've told it to sleep when closing the lid and this works - but strangely only every other time I close the lid. It will work once, then I open the lid and it powers up just fine. Then I close it again and the screen just turns off but the laptop stays fully powered.
    Any ideas what might be going on? It consistently only sleeps every other time when I close the lid (the other times it just turns the screen off).

    Take a look at /etc/systemd/logind.conf
    Is systemd also trying to manage this?

  • I CAN ONLY PRINTS EVERY OTHER PAGE - PLEASE HELP ME!

    Please can anyone help me?  I am trying to print from my iMac (running Lion) to my HP1022nw laser printer.  In every application, only every other page prints out.  Within Paper Handling on the print window, I have correctly selected print every page.
    Can anyone help me? PLEASE!
    Many thanks and kind regards

    I am surprised you can send mail, but not receive.
    If you want ot send mail, you will have to configure the MTA to allow relaying for your internal IP address range. Edit the INTERNAL_IP section of the mappings file, change the 32 after the ipaddrees of your system to somthing like 24 or 16 (depending on your network!)
    If you can send & receive messages in webmail, then there must be something wrong with your outlook settings for reading. Are you trying to read mail using POP or IMAP? What are your settings for POP system, user & password, etc?
    Also, creating a user in the console is fully supported. No problem, just don't forget to tick the "mail" service and do the mail settings for the account.
    Hope this helps you further.
    Regards,
    Niels

Maybe you are looking for