Bug 234 - Interlocked.Exchange<T>(...) crashes the App and throws System.ExecutionEngineException in debug
Summary: Interlocked.Exchange<T>(...) crashes the App and throws System.ExecutionEngin...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime (show other bugs)
Version: 4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-08-08 17:40 UTC by zelyony
Modified: 2011-08-09 13:54 UTC (History)
6 users (show)

Tags: Interlocked.Exchange
Is this bug a regression?: ---
Last known good build:


Attachments
log (32.91 KB, text/plain)
2011-08-08 17:40 UTC, zelyony
Details


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:
Status:
RESOLVED FIXED

Description zelyony 2011-08-08 17:40:03 UTC
Created attachment 91 [details]
log

Interlocked.Exchange<T> crashes app on device (I have iPod4)
others Interlocked.XXX worked

- create windows-based app for iPhone
- add variables to AppDelegate 
    string str = null;
- insert first line of code in AppDelegate.FinishedLaunching
    Interlocked.Exchange( ref str, "one" );
vuala
Comment 1 Sebastien Pouliot 2011-08-08 20:13:09 UTC
Confirmed. It happens with, or without, the linker being enabled.

Not sure why the AOT compiler is not able to detect and compile a string version of this call.

Reducing the severity to Normal since you can use the non-generic overload that accept System.Object to pass string instances as a workaround.
Comment 2 Sebastien Pouliot 2011-08-08 20:20:49 UTC
That same issue has hit other people (before 4.0.4.1)
http://trentacular.com/2011/05/consuming-an-odata-feed-using-monotouch/
Comment 3 Sebastien Pouliot 2011-08-09 08:33:16 UTC
It looks like AOT is well aware of the generic type to use:

imac:Keychain sebastienpouliot$ MONO_PATH=/Users/sebastienpouliot/git/monotouch-samples/Keychain/Keychain/bin/iPhone/Debug/Keychain.app /Developer/MonoTouch/usr/bin/arm-darwin-mono --debug --aot=full,static,asmonly,soft-debug,iphone-abi,outfile=Keychain.exe.6.s -v -v "/Users/sebastienpouliot/git/monotouch-samples/Keychain/Keychain/bin/iPhone/Debug/Keychain.app/Keychain.exe" | grep Interlock
	 call R202 <- [System.Threading.Interlocked:Exchange<string> (string&,string)] [arm_r0 <- R203] [arm_r1 <- R204] [arm_v5 <- R201] clobbers: c

So I wonder if this could be a (undocumented) AOT (or full-AOT) restriction wrt internal calls:

		[ComVisible (false)]
		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
		public extern static T Exchange<T> (ref T location1, T value) where T:class;

c.c. Rodrigo
Comment 4 Zoltan Varga 2011-08-09 13:16:43 UTC
Fixed by 79b99d358b1321759ea3a42f22eaf141aecf0e79 on the mono 2.10 branch.
Comment 5 Sebastien Pouliot 2011-08-09 13:29:24 UTC
Thanks Zoltan! I'll test the fix and include it into monotouch.
Comment 6 Sebastien Pouliot 2011-08-09 13:54:43 UTC
Fixed. 
Thanks for the test case!