Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
repository with test case: https://bitbucket.org/tpurtell/contendedlockparallelforgcdeadlock
I started seeing deadlocks recently once we started doing multi-core optimizations for parts of our application. I was observing ANRs with the main thread stuck in unexpected places (e.g. mono android class registration, various n_OnXXX methods of my application).
Ultimately, I found a piece of code that we had just changed to use a Parallel.For operation and disabled that optimization. The end result was that the dead locks went away. I was able to put together a test case that demonstrates the hangs that occur.
I found bug #18363 which seems like it can cause iterations of the loop to be skipped or run multiple times... but I couldn't understand how it could cause a dead lock. My test case includes checks for #18363 and I do see that issue periodically (maybe 1/10000 iterations).
The test case runs a GC every 100ms. And at the same time, it keep launching a 20 iteration parallel for loop. I have two variants which both produce the deadlock (lock+collection like in my original app, and a lock free concurrent collection).
The deadlock occurs for both 4.12.2 stable and 4.12.3 alpha. They occur with both debug and release, though the time required varies. I never waited for the counter to go above 60000 to reproduce the hang. My device is an HTC One ATT - Android 4.3.
I also experimented with the test case using a plain old for loop (which is much faster) and appears not to show dead lock issues within a reasonable reproduction time limit. I suspect this is most likely a GC bug...
This issue no longer exists in Xamarin.Android/master and monodroid/master