原文: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. sqlServer数据库常用连接字符串

    sqlServer   数据库常用连接字符串 用户名和密码验证的方式去连接到数据库服务器 <add name="conStr" connectionString=" ...

  2. AI贪吃蛇前瞻——基于Dijkstra算法的最短路径问题

    在贪吃蛇流程结构优化之后,我又不满足于亲自操刀控制这条蠢蠢的蛇,干脆就让它升级成AI,我来看程序自己玩,哈哈. 一.Dijkstra算法原理 作为一种广为人知的单源最短路径算法,Dijkstra用于求 ...

  3. ovs 下流表port 1进入,port 1出去

    问题:ovs流量从in_port=1进入,然后从output:1出去,就是说,流量从哪个端口进来,然后从哪个端口出去 流表: ovs-ofctl add-flow br-int in_port=10, ...

  4. (2019)OCP 12c 062考试题库出现大量新题-4

    4.Which four are true about creating and running a remote database scheduler jobs? A) A credential i ...

  5. Stack栈类与、Queue队列与线性表的区别和联系

    栈和队列都属于特殊的线性表   一.定义   1.线性表(linear list): 是数据结构的一种,一个线性表是n个具有相同特性的数据元素的有限序列.数据元素是一个抽象的符号,其具体含义在不同的情 ...

  6. Python面向对象(特殊成员)

    day25 __init__     类()自动执行     __del__     __call__     对象()  类()() 自动执行     __int__      int(对象)    ...

  7. 使用hex编码绕过主机卫士IIS版本继续注入

    本文作者:非主流 测试文件的源码如下: 我们先直接加上单引号试试: http://192.168.0.20/conn.asp?id=1%27 很好,没有报错.那我们继续,and 1=1 和and 1= ...

  8. SecurityManager入门

    java安全管理器SecurityManager入门 SecurityManager 每个Java应用都可以有自己的安全管理器,它是防范恶意攻击的主要安全卫士. 安全管理器通过执行运行阶段检查和访问授 ...

  9. (转)ldd 查看程序依赖库

    原文:https://blog.csdn.net/u010977122/article/details/52993560?spm=a2c4e.11153940.blogcont551034.8.4f7 ...

  10. 利用wget配合bash脚本同时下载多个文件

    先把需要下载的文件写入到一个文件中,命名为urls.txt,比如: http://blog.is36.com/a.jpg http://blog.is36.com/b.jpg http://blog. ...