Introduction
Let's ensure we understand the foundational concepts before delving further into the subjects. Here is a brief introduction if you are unfamiliar with Thread pooling in ATL.
The Active Template Library (ATL) is a Microsoft library that provides a set of C++ templates to simplify the development of COM objects and other Windows-based applications.

In the Active Template Library (ATL), a thread pool is a group of worker threads used to perform tasks in parallel. The ATL manages the thread pool, which creates and manages the threads and provides an interface for scheduling tasks to be executed on the threads. Using a thread pool can help improve an application's performance and responsiveness by allowing multiple tasks to be executed in parallel rather than sequentially.
The article explains the details of Thread pooling class-CComApartment in ATL. Let's get started.
CComApartment Class
The CComApartment class is a part of the ATL thread pooling implementation. It manages a single thread of execution and its associated message queue.
Note: It is impossible to use this class or any of its members in Windows Runtime-based applications.
Syntax
class CComApartment
Members

Public Constructors
Name |
Description |
CComApartment::CComApartment |
The constructor. |
Public Methods
Name | Description |
CComApartment::Apartment | Defines the thread's beginning address. |
CComApartment::Lock | The thread's lock count is increased. |
CComApartment::Unlock | Reduces the number of locks on the thread. |
CComApartment::GetLockCount | The thread's current lock count is returned. |
Public Data Members
Name | Description |
CComApartment::m_dwThreadID | Contains the thread's identifier. |
CComApartment::m_hThread | Contains the thread's handle. |
CComApartment::m_nLockCnt | Contains the thread's current lock count. |
Remarks
To manage an apartment in a thread-pooled EXE module, CComAutoThreadModule uses CComApartment. The lock count on a thread can be increased and decreased using the methods provided by CComApartment.
Requirements
Header: atlbase.h