Question

If I write a DynamicMethod with an ILGenerator and the code that I output is thread safe would the resulting delegate be threadsafe?

My concern is that the IL gets compiled the first time the method runs. If that is true what happens if some other thread tries to run the delegate while it is compiling?

Was it helpful?

Solution

It doesn't do any difference with a standard delegate. They are both present as MSIL somewhere and the JIT compile them when it wants.

Once you have it in delegate form it is a body of code you could call. That's all you really need to know. The implementation of .NET you are running in (Rotor, Mono, Microsoft one) should shield you from any consideration about this, otherwise it's a bug in the implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top