Threading model not properly defined; hard-coded to multi-threaded
This issue arose due to a concern raised by a Progress user, based on the following Knowledge Base article. And while looking into it, I discovered that we were not following the standard ATL protocol for the changing of the threading model.
Although I don't know the full history, it appears that the majority of the classes were changed in 2015 from single-threaded to multi-threaded model. However, this was done inside each class rather than in stdafx.h.
ATL allows for every class to be defined with a more generic model, called CComObjectThreadModel.
This definition is intended to follow a #define that is placed in stdafx.h so that you can change the entire threading model with one definition rather than having to change the definition within every class.
Locks are appropriate to protect a shared resource in case the OCX is built free-threaded, which is the default; and should be harmless in an apartment-threaded build.
Jerry - I recently added some locks in OgrLayer.cpp → could it be that this is actually not required? I’m really unschooled in ATL…
Prior to this change, the Point class was specifically overridden, being hard-coded to the single-threaded apartment model, apparently for memory usage concerns. I did not change that.
In general, there should not be a need to change the threading model. However, in such a case as someone wanting to explore the behavioral differences, we now support the standard ATL protocol for doing such.
This change affects 53 .h files and stdafx.h.
CComMultiThreadModel has been...changed to CComObjectThreadModel, as seen here…
stdafx.h has been changed as follows, changing from _ATL_APARTMENT_THREADED to _ATL_FREE_THREADED.
The previous definition, _ATL_APARTMENT_THREADED had no effect since the threading model was hard coded within each class. Now, when the compiler sees CComObjectThreadModel, it will defer to the _ATL_FREE_THREADEDdefinition in stdafx.h, resulting in CComMultiThreadModel, just as it was originally.
So, as it stands, the resulting compilation is no different than it was before, except that now, if someone has reason to change the OCX to the single-threaded model, it can be done by simply changing stdafx.h.