原文:https://msdn.microsoft.com/library/ms809971.aspx

Behavior of the COM Threading Models

COM线程模型的行为

Before any thread can create or manipulate COM objects, it must perform some preliminary initialization to establish its relationship with the COM library. As a result of this process, COM creates an apartment appropriate for the initialization routine: CoInitialize creates a single-threaded apartment (STA), whereas CoInitializeEx with the COINIT_MULTITHREADED flag produces a multi-threaded apartment. The CoInitialize/CoInitializeEx call does not initialize the COM library globally, only the calling thread's use of it, so it's important to remember that this initialization should be done on a per-thread basis. This is typically done early in a thread's work function (ThreadProc).

在任何线程能创建或操作COM对象前,必须执行一些预初始化来创建进程与COM库之间的连接。该操作的结果:COM创建了一个“公寓”适用于初始化例程;CoInitialize用于创建STA,用COINIT_MULTITHREADED标记的CoInitializeEx用于创建MTA。CoInitializeCoInitializeEx调用不能在全局初始化COM库,只有调用的线程能初始化COM对象。因此,应该牢记初始化必须在线程的创建阶段发生。通常应当早于ThreadProc方法。

A single-threaded apartment is associated with the thread that created it, and only that specific thread may execute calls on objects within the apartment. By contrast, a multi-threaded apartment is not associated with any particular thread. It may be called concurrently by any number of threads and objects within it and should subsequently protect their member data.

一个STA与创建该公寓的线程关联,只有特定的线程有可能执行STA创建的COM对象的调用。与此不同,MTA不与任何特定的线程关联。MTA的COM对象的调用可以被多线程并发的处理,并且由线程自己保证数据的安全。

Communication between apartments is done via marshaling, a generic abstraction for passing data across thread or process boundaries. Because calls to single-threaded apartments can only be executed on the thread that created them, other threads that wish to use an object within this apartment marshal the call to the apartment's thread and let the apartment thread execute the call. The apartment thread then marshals the return value back to the calling thread.

公寓见的通信通过封送形式,封送是一个通用的抽象用于传递数据穿过线程或进程的边界,由于调用STA创建的COM对象只能被创建该公寓的线程执行,其他线程想要使用在STA创建的(COM)对象可以封送这个调用到创建STA的线程,然后让该线程执行这个调用。STA线程然后封送这个调用返回调用线程。

COM线程模型的行为的更多相关文章

  1. 看我是如何处理自定义线程模型---java

    看过我之前文章的园友可能知道我是做游戏开发,我的很多思路和出发点是按照游戏思路来处理的,所以和web的话可能会有冲突,不相符合. 来说说为啥我要自定义线程模型呢? 按照我做的mmorpg或者mmoar ...

  2. HBase的Write Ahead Log (WAL) —— 整体架构、线程模型

    解决的问题 HBase的Write Ahead Log (WAL)提供了一种高并发.持久化的日志保存与回放机制.每一个业务数据的写入操作(PUT / DELETE)执行前,都会记账在WAL中. 如果出 ...

  3. Netty学习三:线程模型

    1 Proactor和Reactor Proactor和Reactor是两种经典的多路复用I/O模型,主要用于在高并发.高吞吐量的环境中进行I/O处理. I/O多路复用机制都依赖于一个事件分发器,事件 ...

  4. Mina、Netty、Twisted一起学(十):线程模型

    要想开发一个高性能的TCP服务器,熟悉所使用框架的线程模型非常重要.MINA.Netty.Twisted本身都是高性能的网络框架,如果再搭配上高效率的代码,才能实现一个高大上的服务器.但是如果不了解它 ...

  5. WPF QuickStart系列之线程模型(Thread Model)

    这篇博客将介绍WPF中的线程模型. 首先我们先来看一个例子,用来计算一定范围内的素数个数. XAML: <Grid> <Grid.RowDefinitions> <Row ...

  6. servlet的生命周期与运行时的线程模型

    第 14 章 生命周期 注意 讲一下servlet的生命周期与运行时的线程模型,对了解servlet的运行原理有所帮助,这样才能避免一些有冲突的设计. 如果你不满足以下任一条件,请继续阅读,否则请跳过 ...

  7. eventloop & actor模式 & Java线程模型演进 & Netty线程模型 总结

    eventloop的基本概念可以参考:http://www.ruanyifeng.com/blog/2013/10/event_loop.html Eventloop指的是独立于主线程的一条线程,专门 ...

  8. 理解RxJava线程模型

    RxJava作为目前一款超火的框架,它便捷的线程切换一直被人们津津乐道,本文从源码的角度,来对RxJava的线程模型做一次深入理解.(注:本文的多处代码都并非原本的RxJava的源码,而是用来说明逻辑 ...

  9. Hbase WAL线程模型源码分析

    版权声明:本文由熊训德原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/257 来源:腾云阁 https://www.qclo ...

  10. Hadoop的Server及其线程模型分析

    早期的一篇文章,针对Hadoop 2.6.0. 一.Listener Listener线程,当Server处于运行状态时,其负责监听来自客户端的连接,并使用Select模式处理Accept事件. 同时 ...

随机推荐

  1. Algorithm 用各种语言写出n!的算法

    写出n!的算法 C# 递归方式: class Program { static void Main(string[] args) { Console.WriteLine("请输入一个数!&q ...

  2. foreach写失效的问题

    本文由作者张远道授权网易云社区发布. 坦白讲身为程序员,bug在所难免.有人讲,bug越多,说明程序员越伟大.这句话有它一定的道理. 因为从某方面讲,bug多了说明他的代码量也多. 言归正传,这里我记 ...

  3. Mitsubishi Lancer JDM

  4. [JavaScript] 根据字符串宽度截取字符串

    /** * 根据字符串宽度截取字符串 * @param desc 原始字符串 * @param width 该显示的宽度 * @param fontsize 字体大小 12px * @returns ...

  5. JavaWeb之Servlet中ServletConfig和ServletContext

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140877.html [正文] 一.ServletConfig:代表当前 ...

  6. OO第一单元作业

    第一次作业 类图:   复杂度: 圈复杂度的问题一直困扰着这三次作业,主要体现在求导方法中先判断符号导致出现过多判断语句,应该将整理符号放在一个新的类中处理. 第一次作业由于对面向对象的思维有些不理解 ...

  7. JS: 防抖节流

    防抖节流 防抖(debounce) 先来看看下面的代码: //触发滚动事件,num 就加1 let num = 0; function incNum() { console.log('鼠标滚动中'); ...

  8. 【BZOJ1502】【NOI2005】月下柠檬树 simpson 积分

    特别提醒:eps至少要5e-6 首先我们来研究下平行光对投影的影响. 一个二维的图形,若它与光屏平行,那么不论平行光与光屏的夹角为多少,所得图形与原图形全等的(只是位置会有影响) 通过这么一分析,我们 ...

  9. Install MySql on CentOS

    Installing & Configuring MySQL Server This Howto will show you how to install MySQL 5.x, start t ...

  10. [转]RESTful API 设计指南

    转自:http://www.ruanyifeng.com/blog/2014/05/restful_api.html 网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机. ...