COM Suvel (Apartment)

zhaozj2021-02-16  43

COM Suite

Reference: "Essential COM", "MSDN"

What is a suit

Suitment, image point, he is a container for installing COM objects, and there can be multiple COM objects in a suite, but for each COM object, only a certain set.

Space use and existence

Suppose you have used COM. We created a COM object in a thread A, then we can access the method, attribute of the COM object in thread A. If we have another thread b he wants to access the methods and properties of the COM object created in thread a, what should I do? As usual, we have to re-change our thread strategy, such as a global pointer to a COM object; or to define a global pointer to a COM object, give her a value after the thread A is created, and then this pointer when creating thread b Pass, and you have to make some synchronous operations to ensure that the object is valid (not deleted) during the COM object call created by thread b. Seeing it, we just want B to access A COM object, but the work to do is so irritated. In order to make us very convenient to use the objects provided by others without re-change our thread strategy. COM provides this concept of apartment, which puts the object's and release restrictions as another implementation, unlock the association between the customer and the COM object, and the association between the re-entry restriction, established a COM object and process and thread The model of interrelationships, so that we can use an object to be transparent without care that she is sensible.

The socket is neither a process, nor thread. The relationship between her and the process and threads is respectful to the following principles:

1. Each process using COM has one or more suites;

2. A suit can only be included in a certain process;

3. Each suite can have a (STA) or multiple (MTA) threads;

4. A thread is only implemented in a certain set;

5. Each suite can contain multiple objects.

COM stipulates that only threads running in the socket of the object can access the object.

Set of detailed

Two types of suite: multi-threaded suites (MTA, Multithreaded Apartment) and single-threaded suites (SINGLETHREADED APARTMENT) are currently defined in the COM specification.

From the classification of the suite, there are several possible types of possibilities:

a. Just contain a STA (a Single-Threaded Process);

b. Contains two or more STA (An Apartment Model Process);

c. contains a MTA (a free-threaded process);

d. Contains a MTA, an unstable number of STA (Mixed Model Process);

STA

in principle:

a. A process can contain multiple STAs;

b. There is only one thread per STA;

The above principles determine that the objects residing in STA will never be connected concurrently by multiple threads, and there is only one way to perform objects.

MTA room

in principle:

a. A process can only contain an MTA;

b. There can be multiple thread execution in each MTA;

The above principles determine that the object resides in the MTA can be accessed by multiple threads, which can provide programs in some cases (such as the beginning of the article), but as an implementation, you must handle threads Synchronization.

转载请注明原文地址:https://www.9cbs.com/read-26955.html

New Post(0)