Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7023793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:45:22+00:00 2026-05-27T23:45:22+00:00

I am using the CMU Sphinx Speech Recognizer library ( Link to source )

  • 0

I am using the CMU Sphinx Speech Recognizer library (Link to source) that makes some use of synchronized blocks.

One example block from the RecognizerTask:

Event mailbox;

[...]

public void start() {
    synchronized (this.mailbox) {
        this.mailbox.notifyAll();
        this.mailbox = Event.START;
    }
}

The code works without any problems, however BugFinder gives this warning:

Bug: Synchronization on RecognizerTask.mailbox in futile attempt to
guard it

This method synchronizes on a field in what appears to be an
attempt to guard against simultaneous updates to that field. But
guarding a field gets a lock on the referenced object, not on the
field. This may not provide the mutual exclusion you need, and other
threads might be obtaining locks on the referenced objects (for other
purposes). An example of this pattern would be:

private Long myNtfSeqNbrCounter = new Long(0);
private Long getNotificationSequenceNumber() {
     Long result = null;
     synchronized(myNtfSeqNbrCounter) {
         result = new Long(myNtfSeqNbrCounter.longValue() + 1);
         myNtfSeqNbrCounter = new Long(result.longValue());
     }
     return result;
 }

To be honest, I don’t quite understand the bug description and what is supposed to be wrong in this case.
Is a global variable not a field? And if not, how can I improve the code?

/edit: This is the only part where Event.wait() is called:

Event todo = Event.NONE;
        synchronized (this.mailbox) {
            todo = this.mailbox;
            /* If we're idle then wait for something to happen. */
            if (state == State.IDLE && todo == Event.NONE) {
                try {
                    //Log.d(getClass().getName(), "waiting");
                    this.mailbox.wait();
                    todo = this.mailbox;
                    //Log.d(getClass().getName(), "got" + todo);
                } catch (InterruptedException e) {
                    /* Quit main loop. */
                    //Log.e(getClass().getName(), "Interrupted waiting for mailbox, shutting down");
                    todo = Event.SHUTDOWN;
                }
            }
            /* Reset the mailbox before releasing, to avoid race condition. */
            this.mailbox = Event.NONE;
        }

This code is actually using a synchronized statement as well. Does it make sense at all to use it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:45:22+00:00Added an answer on May 27, 2026 at 11:45 pm

    I don’t think it applies in your case. You have a call to notifyAll() which means that somewhere in the code of the other threads there is a matching wait() call:

    synchronized (this.mailbox) {
        this.mailbox.wait();        
    }
    

    meaning that the other thread will relinquish the lock while waiting to be notified.

    Your code inspector is probably confused by the line:

    this.mailbox = Event.START;
    

    meaning that you might be concurrently modifying this object, such that if another thread attempts to get the lock on this.mailbox, it will see a different object. However, I do think that since:

    1. this.mailbox is globally visible
    2. assigns of references are atomic
    3. the lock generates a fence

    all threads should have an updated view of the synchronization object at all times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello any one who have used this OpenEars, speech library for IPhone using CMUSphinx
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am designing an app that needs text to speech. I am using the
I am very new to generating an speech using some input text. I tried
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C#, I need a class called User that has a username, password, active
im using Sphinx and i have configured my gammar model path which is build\class\FYP
Using Rails 3.2.0 with haml and sass: I Would like to link an external

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.