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.

Multi-threaded COM object cannot be used with Progress ABL

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.


Jerry Faust
October 16, 2019, 8:36 PM

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.

Mathijs Dumon
October 16, 2019, 7:06 PM

Jerry - I recently added some locks in OgrLayer.cpp → could it be that this is actually not required? I’m really unschooled in ATL…

Jerry Faust
August 18, 2019, 8:01 PM

Additional NOTES:

  1. 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.

  2. 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.


Jerry Faust
August 18, 2019, 6:28 PM

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.



Jerry Faust


Jerry Faust



Epic Link


Affects versions


Fix versions