Bug 6509 - lock(object) does not work
Summary: lock(object) does not work
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-08-12 06:16 UTC by David N. Junod
Modified: 2013-12-05 18:34 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David N. Junod 2012-08-12 06:16:18 UTC
Dictionary <string,string> mDict = new Dictionary<string,string>();

public string MyMethod(string key) {
  lock(mDict) {

    string value;
    if (mDict.TryGetValue(key, out value)) {
      return value;

    // ... some lengthy calculation

    mDict.Add(key, value);
    return value;


multi-thread code calling into MyMethod will frequently throw an exception that the value is a duplicate at mDict.Add

pretty sure this is working fine on MonoTouch (don't use this particular method in MonoTouch).
Comment 1 David N. Junod 2012-08-12 06:46:45 UTC
btw---both the method and the mDict are static.
Comment 2 Zoltan Varga 2012-08-12 21:03:38 UTC
Can you attach a complete test case ? Also, does this happen on the device or in the simulator, or both ?
Comment 3 Jonathan Pryor 2012-08-31 11:14:14 UTC
What's your target device, specifically is it a multi-core device?

Release build or Debug build?

If a Release build, is this using the armeabi runtime or the armeabi-v7a runtime?
Comment 4 David N. Junod 2012-08-31 11:16:49 UTC
I only test on devices, i almost never test on the emulator.

It was a debug build.  I have many devices, this was a couple of weeks ago, was probably using a Samsung Nexus III
Comment 5 Atsushi Eno 2012-09-20 23:56:23 UTC
Could you provide a repro case as requested at comment #2?
Comment 6 PJ 2013-11-19 17:04:43 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 7 PJ 2013-12-05 18:34:53 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.