收录查询

CP站的thread主题

0. 维基百科
http://en.wikipedia.org/wiki/Thread_(computing)
Models
1:1 (Kernel-level threading)Threads
    ~ created by the user are in 1-1 correspondence with schedulable entities in the kernel. This is the simplest possible threading implementation. Win32 used this approach from the start. On Linux, the usual C library implements this approach (via the NPTL or older LinuxThreads). The same approach is used by Solaris, NetBSD and FreeBSD.

1.首先当然是KB了:关于thread的
http://www.codeproject.com/KB/threads/

2. 然后当然是C的主题了
http://www.codeproject.com/Articles/11132/Walking-the-callstack

2.然后就是系列文章了
(1)http://www.codeproject.com/Articles/26148/Beginners-Guide-to-Threading-in-NET-Part-1-of-n

(2)http://www.codeproject.com/Articles/26675/Beginner-s-Guide-to-Threading-in-NET-Part-2-of-n

(3)http://www.codeproject.com/Articles/27366/Beginner-s-Guide-to-Threading-in-NET-Part-3-of-n

(4)http://www.codeproject.com/Articles/27923/Beginners-Guide-to-Threading-in-NET-Part-4-of-n

(5)http://www.codeproject.com/Articles/28485/Beginners-Guide-to-Threading-in-NET-Part-5-of-n

园子里的文章:
COM thread model
http://www.cnblogs.com/whyandinside/archive/2009/08/30/1556938.html

微软的大胡子:Thread model in Windows
http://blogs.msdn.com/b/larryosterman/archive/2004/04/28/122240.aspx

下面是一篇关于COM的线程模型的网文
The COM Threading Models

COM uses the same threading mechanism that Win32 uses. It uses the Win32 API for creating and synchronizing threads. However, threading models are referred to differently in Win32 and COM.

The Win32 Threading Model

Win32 defines two types of threads. User-Interface threads and Worker threads. Each process in Win32 can have one or more User Interface and/or multiple Worker threads. User Interface threads have message-loops that receive events targetted to that window and are hence associated with one or more windows. Worker threads are used for background processing and are not associated with any window.

As a developer, there is one other major difference that you have to be aware of when developing Win32 threads. User Interface threads always own one or more windows. Whenever there is an event for a particular window, the UI thread takes care of calling the appropriate method. Since the message loop is executed on the same UI thread regardless of the thread that sent the message, synchronization is guaranteed by Windows. You as the programmer need not write any special code for thread synchronization. However, if you are developing worker threads, it is your responsibility to handle thread synchronization and prevent deadlocks or racing conditions.

The COM Threading Model

COM terminology to threads is slightly different. There are three types of threading models in COM. They are apartment threading, free threading and rental threading ( introduced for MTS ) The closest analogy to Win32 is that UI threads are analogically similar to the Apartment threading model and worker threads are analogically similar to the Free threading model.

Apartment Threading Model (single threaded apartments)

This model was introduced in the first version of COM with Windows NT3.51 and later Windows 95. The apartment model consists of a multithreaded process that contains only one COM object per thread. Single Threaded Apartments (STA)- This also means that each thread can be called an apartment and each apartment is single threaded. All calls are passed through the Win32 message processing system. COM ensures that these calls are synchronized. Each thread has its own apartment or execution context and at any point in time, only one thread can access this apartment. Each thread in an apartment can receive direct calls only from a thread that belongs to that apartment. The call parametes have to be marshalled between apartments. COM handles marshalling between apartments through the Windows messaging system.

Free Threading Model (multi threaded apartments)

This model was introduced with Windows NT 4.0 and Windows95 with DCOM. The free threaded model allows multiple threads to access a single COM object. Free threaded COM objects have to ensure thread synchronization and they must implement message handlers which are thread aware and thread safe. Calls may not be passed through the Win32 messaging system nor does COM synchronize the calls, since the same method may be called from different processes simultaneously. Free threaded objects should be able to handle calls to their methods from other threads at any time and to handle calls from multiple threads simultaneously. Parameters are passed directly to any thread since all free threads reside in the same apartment. These are also called Multi-Threaded Apartments ( MTA )

Both Apartment and Free Threaded Model

It is possible for a process to have both the apartment and free threaded model. The only restriction is that you can have only one free threaded apartment but you can have multiple single threaded apartments. Interface pointers and data have to be marshalled between apartments. Calls to objects within the STAs will be synchronized by Win32 whereas calls to the MTAs will not be synchronized at all.

Thread Neutral Apartment Model

Components that use the Thread Neutral Apartment model (TNA), mark themselves as Free Threaded or Both. Here the component instances run on the same thread type as the caller's thread. Each instance of a COM class can run on a different thread each time a method is called. When a thread is executing a method in a COM object, and that method creates a new object, MTS will suspend the current thread and create a new thread to handle the new object. Like the MTA, TNAs allow more than one thread to enter an apartment. However, once a thread has entered an apartment, it obtains an apartment-wide lock and no other thread can enter that apartment until it exits. This model was introduced into MTS and COM+ to ensure that context switches are faster.

//end


另1篇鬼佬的网文:
COM Threading Model vs Win32/MFC Threads

1   Win32/MFC Threads
There are two types of win32/MFC threads.

1.User-interface thread: these types of threads are associated with one or more windows. These threads have message loops that keep the window alive and responsive to the users input.
2.Worker thread: these threads are associated with background processing and are not associated with a window. These types oh threads does not use message loops.
NOTE: A single process can have multiple user interface threads, multiple worker threads.

 

2   COM Threads
COM uses same type of threads with different names.

1.Apartment threads (User Interface Thread): This thread owns the component it creates. COM synchronizes, all calls to the component. The component does not need to be threading safe. COM does all of the marshaling and synchronization.
2.Free threads (Worker Thread): COM does not synchronize the calls. Ant thread can access the component. These are free to use. The component must be threading safe. Marshalling is not necessary and component’s job to synchronize.
NOTE: One process can have single apartment or multiple apartments. In-proc server is example for single process with different apartments (server apartment, client apartment both are in same exe).

Out of-proc server is example for single process with single thread.

//end

Win32 Thread Object Model 的2篇文章:
文章1:Simple thread object model
http://cboard.cprogramming.com/windows-programming/46958-simple-thread-object-model-my-first-post.html

文章2:Win32 Thread Object Model Revisted
http://cboard.cprogramming.com/windows-programming/59695-win32-thread-object-model-revisted.html

posted @ 2012-08-01 21:59  ->  阅读(308)  评论(0)    收藏  举报