AOT-Compatlyzer icon indicating copy to clipboard operation
AOT-Compatlyzer copied to clipboard

Eliminate Interlocked CompareExchange

Open ncruces opened this issue 12 years ago • 4 comments

Hi,

I've found what I think is a "simpler" and more "general" solution for the ExecutionEngineException on events compiled with Visual Studio.

You can simply replace any call to the generic version of CompareExchange: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<T>(!!0&, !!0, !!0)

With a call to the non-generic version: call object [mscorlib]System.Threading.Interlocked::CompareExchange(object&, object, object)

You can safely do the same for calls to Interlocked::Exchange. You'll maintain thread-safety, and (surprisingly) it works on all platforms (at least for trusted code).

Greatings.

ncruces avatar Feb 05 '14 14:02 ncruces

Thanks for the tip! It looks like it is a better solution.

It may be months before I have time to implement this but I will make a note on the main page.

jaredthirsk avatar Feb 05 '14 15:02 jaredthirsk

I'm sorry I can't help you with code. I'm patching my assemblies using ildasm/ilasm and some regexs. If I ever get around using Mono.Cecil I'll share.

ncruces avatar Feb 09 '14 13:02 ncruces

Hey Jared!

We are just porting our Android/Windows Store project to iOS, so we need to compatlyze our framework again :)

Are there any plans to include this fix? With the current version we've got the problem that the call stacks don't match on exceptions, guess the pdb/mdb doesn't match the DLL anymore. With this fix it should be still compatible I guess.

I'm still wondering why there isn't any Unity way to do this, event handlers are quite common, aren't they?

Cheers Christian

coeing avatar Oct 15 '14 10:10 coeing

I don't have time right now. There's a chance I may want/need this fix myself in 1-5 months :-/

jaredthirsk avatar Mar 23 '15 22:03 jaredthirsk