我看见过一些介绍,记不清了,
线程模型有多种:Single Threaded,Apartment Threaded,
Thread per Object,Thread Pool,Free Thread,...(还有记不清了)
不同的应用可以选择合适的线程模型,不好的选择会影响性能。
多用户下,最好不要用Single Threaded。
线程模型有多种:Single Threaded,Apartment Threaded,
Thread per Object,Thread Pool,Free Thread,...(还有记不清了)
不同的应用可以选择合适的线程模型,不好的选择会影响性能。
多用户下,最好不要用Single Threaded。
解决方案 »
- 去掉了view,doc等类,在cMainFrame上放了一个listCtrl
- 读取文件
- 求救,为什么会提示"无效的字符值或规格"这个错误
- ADO打开不同的ACCESS表?
- 我是计算机系的啊,曾经很傻的想过,要是有女生能做知心朋友,而且长相还不错,那有多好啊~~呵呵
- 如何用socket来传送一个mp3文件(用API)?
- 关于keybd_event用法的问题
- 运行MFC时afxcoll.inl中ASSERT(AfxIsValidAddress(pNode, sizeof(CNode)));出错?
- VS2008中怎么使用updatable()函数?
- 如何向打印机发送指令实现打印机的高速打印和双向打印
- *****问几个C\C++的基础问题,参加者一天后得分,分数为我的总分平均分配给参与人数*****
- 关于打印问题的具体问题(100分)?????????????
多看看COM+中新提出的中性(线程无关)单元的信息,或许那才是COM上将来解决并发问题之道。
Win32 programming involves understanding processes and threads. A process is an instance of an application that has an address space with four gigabytes of virtual memory and other resources. Threads are objects that live in a process, and are the actual pieces of code that are executed on the processor. Each process starts with one thread, called the primary thread. A process always has one or more threads executing; the process ends when there are no more threads executing. The term multithreading comes from the fact that a process can execute more than one thread.Apartment ThreadedIn an ActiveX DLL project, the Threading Model list box allows you to choose whether your component is single-threaded or apartment-threaded. The default threading model is set to Apartment Threaded.The apartment model is a COM-specific form of multithreading in Windows 95, Windows 98, and Windows NT. An apartment is essentially a way of describing a thread with a message queue that supports COM objects. Visual Basic greatly simplifies the job of authoring in-process components that multithreaded clients can use safely and efficiently. All COM components created with Visual Basic use apartment model threading, whether they're single-threaded or multithreaded.Single ThreadedA single-threaded component has only one apartment, which contains all the objects the component provides. This means that a single-threaded DLL that you create with Visual Basic is safe to use with a multithreaded client. However, there is a performance trade-off for this safety: Visual Basic marshals calls from all client threads except one, just as if they were out-of-process calls.Advantages of Apartment-Model ThreadingMarking an ActiveX DLL project for apartment-model threading provides the following benefits:
All of the objects a client creates on a given thread are created in the same apartment (thread) in the DLL. Calls to these objects do not require cross-thread marshaling, making them more efficient.
When a component has one thread of execution, code for only one object can execute at any given time. COM deals with this situation by serializing requests; the requests are queued and processed one at a time until they are all completed. Because an object is accessed only on the thread where it was created in apartment-model threading, calls are synchronized (serialized) so that a call is never interrupted by a call from another thread.
Arguments for cross-thread calls are marshaled, and the calling thread is blocked. This synchronization of data protects the calling thread's state.ActiveX EXE ThreadingFor ActiveX Exe projects, you can either specify that each new object be created on a new thread (Thread Per Object), or limit your component to a fixed pool of threads. A thread pool size of one makes the project single-threaded; a larger thread pool makes the project apartment-threaded. Visual Basic provides the following three models for assigning objects to threads in out-of-process components:
One thread of executionTo use this option, select the Thread Pool option with one thread.
Thread pool with round-robin thread assignmentTo use this option, select the Thread Pool option and specify the number of threads to allow.
Every externally created object on its own threadTo use this option, select the Thread Per Object option.A new ActiveX EXE project is single-threaded by default, which means that it can run only one method call at a time. When multiple clients are connected to the server component, this can cause one client's call to a method to block calls from all other clients. To increase the responsiveness of the server component, you can change the threading model. If you choose the Thread Pool option (round-robin thread assignment), you cannot predict when objects will share global data, or when they will block each other from executing. The behavior of the round-robin thread pool algorithm is therefore referred to as nondeterministic. However, the advantage of this threading model is that it puts a limit on the total number of threads.In the Thread Per Object model, as clients request objects, Visual Basic creates each object on a new thread. When the last client releases its last reference to objects on that thread, Visual Basic terminates the thread. The big drawback to the Thread Per Object model is that you have no control over the number of objects (and hence threads) that clients create. Too many active threads-threads that are actively executing code-will bog down the operating system. As a general rule, you want about the same number of active threads as you have processors.