Multi-thread test of COM components - Single Model

zhaozj2021-02-16  54

Multi-thread test of COM components - Single Model

Version Information:

version

Author

Fixed / record

Ver 1.0 zzyx 2003-5-16. create

Keywords:

COM multi-threaded thread model Single Apartment Coinitialize CoinitializeEx

Coinit_ApartmentthReaded Coinit_ApartmentthReadeded COINIT_APARTMENTTHREADED

Test object

The component object thread model is Single.

Component code:

STDMETHODIMP CTEST1 :: Test (long NCNT)

{

Printf ("/ N object test1. The thread id:% D", getCurrentThreadId ());

_tzset ();

Char tmpbuf [128];

_STRTIME (TMPBUF);

Printf ("/ N / T Thread ID:% D, Begin Time: / T% S / N", getCurrentThreadId (), TMPBUF);

SLEEP (1000 * NCNT);

_STRTIME (TMPBUF);

Printf ("/ N / T Thread ID:% D, End Time: / T% S / N", getCurrentThreadID (), TMPBUF);

Return S_OK;

}

Object cross-thread call

testing method:

The client creates an object instance and passes the pointer of the object to multiple threads.

Method for calling this instance in each thread

Observe the output

serial number

Client COM environment

result

Experience

S1 NO cannot create an object

S2 Coinitialize Synchronous Execute and Method Create Multiple Thread Synchronization Call From the perspective of the component, you need to manage thread synchronization. Although the components' thread model is Single

S3 CoinitializeEx Coinit_ApartmentthReaded The method of executing the object in the same threaded S4 CoinitializeEx Coinit_MultithReaded is called the thread to create a thread synchronization for COM. But if it is a different method? Logically should be synchronized, not tested

Multi-threaded object instance call

testing method:

Client launch multiple threads

Each thread creates an object instance and calls the object.

Observe the output result.

The test results are as follows:

Main thread

COM environment

serial number

Thread com

surroundings

operation result

NO T1 NO Unable to create objects T2 Coinitialize must call each thread to start the first thread Object Run in the corresponding thread, the second thread creates a COM object failed: CreateInstance Failed, -2147221164 (No registration class) third And the objects of the rear threads are running in additional same threads. It seems that the system is created. T3 CointializeEx Coinit_apartmentthReaded Sequence Call Each thread starts the object of the first thread runs in the corresponding thread in the corresponding thread runs in another same thread. It seems that the system is created. No exception T4 CointializeEx Coinit_MultithReaded order Call each thread is started, but the object is running in another thread, which seems to be an abnormality created by the system.

Coinitialize T5 No Could Create Object T6 Coinitialize? ? ? Phenomenon with T2 Is there an abnormality T7 COINTIAALIZEEX COINIT_APARTMENTTHREADED? ? ? The phenomenon of T2 has an abnormal T8 CointializeEx Coinit_Multithreaded with T4

CoInitializeEx COINIT_APARTMENTTHREADED T9 NO can not create object T10 CoInitialize with abnormal T2 T2 T11 CoIntializeEx COINIT_APARTMENTTHREADED with abnormal T12 CoIntializeEx COINIT_MULTITHREADED can not be created with T4 Yes CoInitializeEx COINIT_MULTITHREADED T13 NO T14 CoInitialize objects called in order to create the first thread of COM objects from running in this thread The COM object created by other threads runs in one of the same threads. It seems that the system created with no exception T15 COINTIALIZEEX COINIT_APARTMENTTHREADEDED T14 T16 COINTIAALIX COINIT_MULTITHREADED The object created in the T4 call all threads is in the same additional thread, the thread seems to Whether there is no abnormality created by the system reference Appendix

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

New Post(0)