views:

42

answers:

1

Consider a situation. I have an in-proc COM server that contains two COM classes. Both classes are marked as "no threading model" in the registry - the "ThreadingModel" value is just absent. Both classes read/write the same set of global variable without any synchronization.

As far as I know "no threading model" will enforce COM to disallow concurrent access to the same or different instances of the same class by different threads.

Will COM prevent concurrent access to instances of the two abovementioned different classes? Do I need synchronization when accessing the global variables from two different COM classes in this situation?

+1  A: 

When there ThreadingModel is absent then the it defaults of Main STA or Legacy STA. All the legacy components are always created in this Legacy STA. For more details, I would recommend reading http://www.codeproject.com/kb/com/CCOMThread.aspx

byte
I've read that. It's still unclear whether putting two different classes to a legacy STA will protect data shared between them against concurrent access.
sharptooth
The article I mentioned, describes scenario as "The advantage of developing a legacy STA object is that all access to all instances of such objects are serialized. You do not need any inter-apartment marshalling between any two legacy STA objects. However, non-legacy STA objects living in non-legacy STAs that want to make calls to legacy-STA objects must, nevertheless, arrange for inter-apartment marshalling. The converse (legacy-STA objects making calls to non-legacy STA objects living in non-legacy STAs) also requires inter-apartment marshalling. Not a very attractive advantage, I think."
byte