none
ThreadSynchronizationException RRS feed

  • Question

  • Hi,

    When I profile my multithreaded c# Windows service, I find hundreds of instances of ThreadSynchronisationExceptions. (rate of 22 to 25 exceptions per sec, and the number is always little less than or equal to the number of thread as shown by the profiler). I have not used any Monitor class method calls or lock statements or synchronisation. But these exceptions seem to be getting thrown from everywhere. Why is it that I am geting these exceptions? And where do I need to start looking for to troubleshoot? Any pointers would be appreciated.

     

    Thanks,

    Sanjukta


    Sanjukta
    Monday, May 9, 2011 3:43 AM

Answers

  • That exception has a pretty simple meaning: A thread is trying to release or signal using a lock that it does not own. Are you by any chance using the Monitor or ReaderWriterSlim classes? If so, make sure that you're acquiring and releasing all locks properly.

    /Calle


    - Still confused, but on a higher level -
    • Proposed as answer by eryang Tuesday, May 17, 2011 9:33 AM
    • Marked as answer by Paul Zhou Tuesday, May 24, 2011 6:07 AM
    Tuesday, May 10, 2011 8:14 AM

All replies

  • ThreadSynchronizationException, is that a managed exception? I can't seem to find it. Is it possible to provide a stack trace of one such exception? What tool do you use to profile the service?

    Lots of questions, sorry :)

    /Calle


    - Still confused, but on a higher level -
    Monday, May 9, 2011 11:44 AM
  • Sorry, it is System.Threading.SynchronizationLockException. I am using Red Ant for profling and it does not provide any stack trace.

    I have a static class in which I have a staic method and static property (see code below). This method gets called by multiple threads. The exceptions seems to be pointing to this method.

    [ThreadStatic]

     

    private static string

    configurationSource;

     

    public static string

    ConfigurationSource

    {

     

    get { return

    configurationSource; }

     

    set

    { configurationSource = value; }

    }

     

    public static Database CreateDatabase(string

    databaseKey)

    {

    DatabaseProviderFactory dbFactory =

    null

    ;

     

    using (FileConfigurationSource dataSource = new

    FileConfigurationSource(configurationSource))

    {

    dbFactory =

    new

    DatabaseProviderFactory(dataSource);

    }

     

     

    return

    dbFactory.Create(databaseKey);

     

    }

    

    What am I doing wrong here?

    

    Regards,

    Sanjukta


    Sanjukta
    Monday, May 9, 2011 11:06 PM
  • That exception has a pretty simple meaning: A thread is trying to release or signal using a lock that it does not own. Are you by any chance using the Monitor or ReaderWriterSlim classes? If so, make sure that you're acquiring and releasing all locks properly.

    /Calle


    - Still confused, but on a higher level -
    • Proposed as answer by eryang Tuesday, May 17, 2011 9:33 AM
    • Marked as answer by Paul Zhou Tuesday, May 24, 2011 6:07 AM
    Tuesday, May 10, 2011 8:14 AM