Strictly speaking, what can you do with a delegate on multiple threads?

According to the documentation of System.MulticastDelegate :

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members do not guarantee thread safety.

The same statement exists in the documentation for System.Delegate.

Delegates now have an immutable API, but, as Eric Lippert explains, "it is a mistake to assume that just because the data structure does not allow any way for you to change its contents, its implementation must be thread safe!"

Some mechanisms for creating new delegates from existing delegates are static methods: Delegate.Combineand Delegate.Remove. They appear to be thread safe. Given the multi-sheeted delegates A, B and C, I can safely combine A and B to make D in one thread, combining B and C to make E on another.

But calling a delegate is not a static method. Does this mean that technically my code might break if I split the delegate between threads and call it on both, or if I call the delegate in one thread, combining it with another in another thread? Can a standard implementation MulticastDelegatelead to undefined behavior in such a scenario? Is the delegated delegate returned Combineor Removenot using any hidden mutable state with any other delegate?

, , , # CIL JIT. , , .NET Mono , , .

+5
2

, . . , , ( - ).

, . , BCL, , .

. . . , , . . , :

+1

- , , .

. 14.5.10.3 http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf

" , , , . , , . [: , , , . end note]"

, , .

0

All Articles