简体   繁体   中英

.NET DynamicMethod Thread Safe?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM