Just think, Just do it

COM组件中的线程模式
COM组件中的线程模式
2001-02-07· ·lostall··com集中营


  提及COM的线程模式,实际上指的是两个方面,一个是客户程序的线程模式,一个是组件所支持的线程模式。客户程序的线程模式只有两种,单线程公寓(STA)和多线程公寓(MTA)。组件所支持的线程模式有四种:Single(单线程)、Apartment(STA)、Free(MTA)、Both(STA+MTA)。

  1、公寓只是个逻辑上的概念。一个STA只能包含一个线程,一个MTA可以包含多个线程。一个进程可以包含多个STA,但只能有一个MTA。MTA中各线程可以并行的调用本公寓内实例化的组件,而不需要进行调度。跨公寓调用组件实例必须要进行调度。(除非使用了自由线程调度器)

  2、客户程序的线程是在调用CoInitializeEx()时决定客户线程的类型的。如果以参数COINIT_APARTMENTTHREADED调用,则会创建一个STA公寓,客户线程包含在这个公寓里。如果以参数COINIT_MULTITHREADED调用,则创建一个MTA公寓,把线程加入到这个MTA中;如果进程内已经有了一个MTA,则不创建新的MTA,只把线程加入到已有的MTA。注意每个线程都必须调用CoInitializeEx()才能使用COM组件。

  3、线程最重要的是同步问题。STA是通过窗口消息队列来解决这个问题的。当客户线程以COINIT_APARTMENTTHREADED调用CoInitializeEx()时,将为会该STA创建一个具有OleMainThreadWndClass窗口类的隐含窗口。所有对在这个公寓中建立的COM对象方法的调用都将都放到这个隐含窗口的消息队列中。所以每一个与STA相关联的线程必须用GetMessage、DispatchMessage或类似方法来分派窗口消息。MTA内各线程可并行调用同一个组件对象的实例,从而不保证安全性,所以实现同步访问的责任就落在了组件身上。注意,STA的同步是公寓级的,就是说对公寓内不同组件的访问都要放到同一个消息队列中,对一个实例的方法调用会影响对其他实例的调用,所以并发程度很低。

  4、在不同公寓间传递接口指针必须要经过调度。这主要还是为了同步对组件的调用。通过CoMarshalInterThreadInterfaceInStream和CoGetInterfaceAndReleaseStream实现。很简单。

  5、Single型组件很特殊,它只能在一个单一的线程中执行。首先要说明的是一个进程中第一个以COINIT_APARTMENTTHREADED调用CoInitializeEx()的线程被称作是主STA。每次用CoCreateInstance()创建的Single型组件实际上都是创建在了这个主STA中,而不管是谁调用了CoCreateInstance()这个函数。所有对这个Single组件方法的调用都必须要通过这个主STA。

  6、若STA创建STA型组件,是直接创建,直接调用。若STA创建MTA型组件,系统为组件创建一个MTA,STA通过代理访问组件。若STA创建Both型组件,是直接创建,直接调用。若MTA创建STA型组件,系统为组件创建一个STA,MTA通过代理访问组件。若MTA创建MTA型组件,是直接创建,直接调用。若MTA创建Both型组件,是直接创建,直接调用。可见如果客户程序和组件都支持同样的线程模式,那么COM就允许客户程序直接调用对象,这样将产生最佳性能。

  7、Both型组件已经很好了,无论是STA还是MTA都可以直接创建调用它。但跨公寓的调用仍然要经过代理。为了更进一步以获得最佳性能,可以使用自由线程调度器(FTM)。注意其它类型的组件也可以使用FTM,只是由Both使用FTM可获得是最佳效果。FTM实现了接口IMarshal,当调度那两个调度接口指针的函数时,这两个函数(见5)内部调用IMarshal内的相关函数,并判断如果调度发生在一个进程内的公寓之间则直接返回接口指针;如果调度发生在进程之间或者远程计算机间,则调用标准的调度器,并返回指向代理对象的指针。所以可见使用FTM,即使是公寓之间也不用调度接口指针了!!

  8、FTM虽然好,但使用FTM的组件必须遵守某些限制:使用FTM的对象不能直接拥有没有实现FTM的对象的接口指针;使用FTM的对象不能拥有其他公寓对象代理的引用。

  9、全局接口表(GIT)。作用范围是进程内。可以把接口指针存进表中,然后在别的公寓内把其取出,GIT自动执行公寓间的调度,所以很方便。GIT是通过IGlobalInterfaceTable访问的。通过创建CLSID为CLSID_StdGlobalInterfaceTable的对象可调用它。
posted @ 2006-03-29 10:18 zfly 阅读(395) | 评论 (0) | 编辑 收藏
 
memcpy(*)实现!

void * memcpy(void * to, const void * from, size_t n)
{
  const char *c_from = from;
  char *c_to = to;
  while (n-- > 0)
    *c_to++ = *c_from++;
  return((void *) to);
}

----------
char * strcat0 (char* s, const char * d )
{
 char * to_s = s;

// while( *s++ !='\0' ); //也可
// s--;

 while( *s !='\0' )
  s++;
 
 while ( (*s++ = *d++ ) !='\0');

 return ( to_s );
}

----------
char * strcpy0 (char* s, const char * d )
{
 char * to_s = s;
  
 while ( (*s++ = *d++ ) !='\0');

 return ( to_s );
}

posted @ 2006-03-27 12:39 zfly 阅读(1507) | 评论 (0) | 编辑 收藏
 
Waiting .... waiting .......

Relearning perl ,javascript!

OOP

Keep with studying!

小test routine:

------------------
#!/bin/perl -w
# Example of a daytime UDP server using perl functions
use Socket qw(INADDR_ANY AF_INET SOMAXCONN SOCK_DGRAM sockaddr_in inet_aton );
# Get protocol number
#my $proto = getprotobyname(’udp’);
# Create generic socket
socket(SOCK, AF_INET, SOCK_DGRAM, 17) or die "socket: $!";
# Bind to the daytime port on any interface
#my $port = getservbyname(’daytime’,’udp’);
my $port = 4000;
my $addr = inet_aton("192.1.1.201");
my $paddr = sockaddr_in($port, $addr);
#bind(SOCK, $paddr) or die "bind: $!";
# no listen() as that is a SOCK_STREAM call()
#$rin = "";
#vec($rin, fileno(SOCK), 1) = 1;

my $from = sockaddr_in(4001, $addr);
use strict;
    use CGI;
    my $q = new CGI;
   
 my $i = 0;
  print $q->header( "text/html" ),$q->start_html( "hello from perl cgi!" );
  #  print $q->h2("hello dave $i...");
   # print $q->end_html;
   
while ($i<60) {
#$from = recv(SOCK, $buffer, 1, 0) or next;
    send(SOCK, "AAAAAAAB\n", 0, $from) || die "send: $!";

    $i ++;
   
  #  print $q->h2("hello dave $i...");
}
 # print $q->end_html;

posted @ 2006-03-23 11:55 zfly 阅读(240) | 评论 (0) | 编辑 收藏
 
C++
"有一个","是一个" 和 "用...来实现"的区别?
posted @ 2006-03-21 14:56 zfly 阅读(188) | 评论 (0) | 编辑 收藏
 
今天收到外企2m了!!
我顶,顶!
一定抓住机会!!!!
posted @ 2006-03-17 09:09 zfly 阅读(198) | 评论 (0) | 编辑 收藏
 
无聊的笔试准备!!! (无聊透顶 ---------------------)

在开源如此盛行的年代,那种无聊的笔试,我真是痛恶之绝!!!
可我们得无奈的面对.........

以下为经典之作,那个考官能有如此慎密思路??不防一试!!!
-------------------------
1、自己写atoi
int atoi(number)
char  *number;
{
   int   n = 0, neg = 0;

   while (*number <= ' ' && *number > 0)
      ++number;
   if (*number == '-')
   {
      neg = 1;
      ++number;
   }
   else if (*number == '+')
      ++number;
   while (*number>='0' && *number<='9')
      n = (n * 10) + ((*number++) - '0');
   return (neg ? -n : n);
}
------------------------------------
2.
#if 1
char *
strstr(s1, s2)
const char *s1;
const char *s2;
{
   int l = strlen(s2);
   char * p = (char *) s1;

   if( l==0 ) return p;

   while (p = strchr(p, *s2))
   {
      if( memcmp(p, s2, l) == 0 )
         return p;
      p++;
   }
   return (char *) 0;
}

#else

char *strstr(str1, str2)
char *str1, *str2;
{
    char *Sptr, *Tptr;
    int len = strlen(str1) -strlen(str2) + 1;

    if (*str2)
 for (; len > 0; len--, str1++){
     if (*str1 != *str2)
  continue;

     for (Sptr = str1, Tptr = str2; *Tptr != '\0'; Sptr++, Tptr++)
  if (*Sptr != *Tptr)
      break;

     if (*Tptr == '\0')
  return (char*) str1;
 }

    return (char*)0;
}
#endif
-----------------------------
3.自己写fabs
/* Avoid using UNK if possible.  */
#ifdef UNK
#if BIGENDIAN
#define MIEEE 1
#else
#define IBMPC 1
#endif
#endif

double fabs(x)
double x;
{
union
  {
    double d;
    short i[4];
  } u;

u.d = x;
#ifdef IBMPC
    u.i[3] &= 0x7fff;
#endif
#ifdef MIEEE
    u.i[0] &= 0x7fff;
#endif
#ifdef DEC
    u.i[3] &= 0x7fff;
#endif
#ifdef UNK
if( u.d < 0 )
   u.d = -u.d;
#endif
return( u.d );
}
------------------------
4.
static char buf[12];

extern char * ultoa();

char * ltoa(val)
long val;
{
   char *p;
   int flg = 0;
   if( val < 0 ) { flg++; val= -val; }
   p = ultoa(val);
   if(flg) *--p = '-';
   return p;
}

char * ultoa(val)
unsigned long val;
{
   char *p;

   p = buf+sizeof(buf);
   *--p = '\0';

   do
   {
      *--p = '0' + val%10;
      val/=10;
   }
   while(val);
   return p;
}

--------------------
5.
#define __MAX_INT_CHARS 7

char *
itoa(i)
int   i;
{
   static char a[__MAX_INT_CHARS];
   char *b = a + sizeof(a) - 1;
   int   sign = (i < 0);

   if (sign)
      i = -i;
   *b = 0;
   do
   {
      *--b = '0' + (i % 10);
      i /= 10;
   }
   while (i);
   if (sign)
      *--b = '-';
   return b;
}

---------------------------
6:折半查
#include <stdio.h>

static int _bsearch;   /* index of element found, or where to

           * insert */

char *bsearch(key, base, num, size, cmp)
char *key;    /* item to search for */
char *base;   /* base address */
int num;      /* number of elements */
int size;    /* element size in bytes */
int (*cmp) ();   /* comparison function */
{
 int a, b, c, dir;

 a = 0;
 b = num - 1;
 while (a <= b) {
  c = (a + b) >> 1;  /* == ((a + b) / 2) */
  if ((dir = (*cmp) (key, (base + (c * size))))) {
   if (dir < 0)
    b = c - 1;
   else    /* (dir > 0) */
    a = c + 1;
  } else {
   _bsearch = c;
   return (base + (c * size));
  }
 }
 _bsearch = b;
 return (NULL);
}

太多了,一大把,哎........................

posted @ 2006-03-10 10:44 zfly 阅读(479) | 评论 (0) | 编辑 收藏
 
looking for job .............
looking for  job.............

........................................
........................................

What is bottom up Parsing ?
The Parsing method in which the Parse tree is constructed from the input language string begining from the leaves and going up to the root node.
Bottom-Up parsing is also called shift-reduce parsing due to it's implementation.
The YACC supports shift-reduce pasing.
e.g  Suppose there is a grammar G having a production E
               E->E*E
and an input string   x*y.
The left hand side of any production are called Handles. thus the handle for this example is E.
The shift action is simply pushing an input symbol on a stack. When the R.H.S of a production is matched the stack elements are popped and replaced by the corresponding Handle. This is the reduce action.

Thus in the above example , The parser shifts the input token 'x' onto the stack. Then again it shifts the token '*' on the top of the stack. Still the production is not satisfied so it shifts the next token 'y' too. Now the production E is matched so it pops all the three tokens from the stack and replaces it with the handle 'E'. Any action that is specified with the rule is carried out.
                                  If the input string reaches the end of file /line and no error has occurred then the parser executes the 'Accept' action signifing successfull completion of parsing. Otherwise it executes an 'Error' action.

What is a LR Parser ?
The LR means Left-to- Right signifying the parser which reads the input  string from left to right. An LR parser can be written for almost all Programming  constructs.
                      An LR parser consists of two parts:- Driver Routine & Parsing  Table. The Driver routine is same for all the Parsers ,only  the Parsing Table  changes. The Parsing Table is essentially a form of representing the State-  Transition Diagram for the language. It consists the entries for all possible  States  and the input symbols. In each state there in a predetermined next state  depending upon the input symbol. If there is any duplicate entry or two next  states for the same symbol, then there is an ambiguity in the grammar.

What is LALR Parser ?
LALR is Look-ahead LR parser. It differs from LR in the fact that it will look ahead one symbol in the input string before going for a reduce action. Look- ahead helps in knowing if the complete rule has been matched or not.

e.g Consider a grammar G with production
         P->AB|ABC
When the Parser shifts the Symbol B it can reduce to P . But if the next Symbol was C then it has not matched the complete rule. A LALR parser will shift one extra token and then take a decision to reduce or shift

posted @ 2006-03-08 13:37 zfly 阅读(334) | 评论 (0) | 编辑 收藏
 
工作,工作!!!
工作,工作!!!
真是不好找!!!
好工作,更难找!!!!!
posted @ 2006-03-03 10:06 zfly 阅读(235) | 评论 (2) | 编辑 收藏
 
开心不起来,练练字吧!
哎,开心不起来啊!发现写程序、代码,越来越没前途,更没钱途啊,
独有辛苦。百无聊耐,写了几个字练练,疏散疏散心中的郁气!

SV401529.JPG
posted @ 2006-02-25 20:54 zfly 阅读(228) | 评论 (0) | 编辑 收藏
 
中国金融认证中心技术标准--转


在CFCA的系统中,各种密码算法、密钥格式、加解密方式、消息传输方式和证书格式等都应符合国内或国际标准。若没有标准的,采用国际上通用的企业标准或公认的事实标准。

现将CFCA系统所遵循的有关标准公布如下:

·SET 1.0(Secure Electronic Transaction):定义SET系统内部各项支付数据、格式和流程标准,由SETCc负责修订。

·ASN.1(Abstract Syntax Notation):抽象句法符号标准,用来表示各种消息,符合ITU-T X.208标准。

·DER(Distinguished Encoding Rules):唯一编码规则,用来以明确的格式对支付消息和整数中的协议数据进行编码,符合ITU-T X.680标准。

·DES(Data Encryption Standard):数据加密标准。

·RSA:非对称加密方式,主要用于数字签名。

·CAST:分组密码,符合Internet RFC 2144。

·PKCS(Public-Key Cryptography Standards):由RSA公司制定的公开密钥标准。

·PKCS#1(RSA Encryption Standard):RSA加密标准格式。

·PKCS#3:(Diffie-Hellman Key Agreement Standard):描述在原来没有协议的双方应用Diffie-Hellman 密钥协议的方法。

·PKCS#5(Password-Based Encryption Standard):从口令推导出密钥和算法的参数。

·PKCS#6:(Extended-Certificate Syntax Standard):扩展证书的语法定义。

·PKCS#7(Cryptographic Message Syntax Standard):定义加密消息句法。

·PKCS#8(Private-Key Information Syntax Standard):定义私钥信息语法。

·PKCS #9: (Selected Attribute Types):定义使用在扩展证书、数字签名信息和私钥信息中可选的属性类型。

·PKCS#10(Certification Request Syntax Standard):证书申请语法格式。

·X.509:ITU-T X.509建议(1997)公开密钥证书的格式和身份鉴别过程。CFCA系统中支持的证书格式均在X.509版本3中定义,CRL格式符合X.509 V2标准。

·SHS(Secure Hash Standard):安全哈希算法标准,符合FIPS PUB 180标准。

·TCP/IP:一系列用于支持因特网通讯的协议。

·HTTP:超文本传输协议。支持WWW浏览器和服务器的万维网传输协议。

·S/MIME:多用途因特网消息扩展。用来对支付消息的信封进行编码,使浏览器可以辨别支付消息,支持以电子邮件为基础的商务交易。

·PEM(Privacy-Enhance Mail): 保密性提高的邮件格式,定义在RFC 1421-1424中。

·RFC 1766:语言标记标准。

·HMAC:密钥的哈希机制,用于信息完整性检查,符合RFC 2104标准。

·Triple-DES:三重数字加密标准。执行三次常规的DES加密步骤,用于对数据进行加密。

·MD5:报文摘要算法,符合因特网RFC 1321。

·SPKM:适用于GSS-API的简单公钥机制,用于Non-SET体系中公钥的传输,符合RFC 2025标准。

·LDAP:轻型目录存取协议,符合RFC 1777。只用在Non-SET体系中。

·SEP(Secure Exchange Protocol):安全交换协议,符合ITU-T X.830,X.831,X.832和ISO/IEC 11856-1,11856-2,11856-3。该协议只用于Non-SET体系。

·ISO 3166:用于表示国家名字的代码。

·ISO 4217:用于表示货币的代码。

·ISO 7812:身份卡编号系统和注册规程。

·ISO 8583:金融交易卡消息、互换消息规范。

·ISO 9594-8:ITU-T X.509建议,信息技术-开发系统互连。SET协议支持该证书格式。

·ISO 9834-7:提供了一个国际注册机关。

posted @ 2006-02-22 10:43 zfly 阅读(281) | 评论 (0) | 编辑 收藏
 
仅列出标题
共14页: First 5 6 7 8 9 10 11 12 13 Last 
 
<2008年6月>
日一二三四五六
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

 公告


我创建的群:21159852,欢迎大家加入! ( Scada,DCS,PLC, RTU,VxWorks, Linux,104,101, DNP,MODBUS ...... )

 导航

  • IT博客
  • 首页
  • 发新随笔
  • 发新文章
  • 联系
  • 管理

 统计

  • 随笔: 137
  • 文章: 3
  • 评论: 97
  • 引用: 0

常用链接

  • 我的随笔
  • 我的评论
  • 我参与的随笔

留言簿(9)

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类(141)

  • 学习C C++(28) (rss)
  • 本人作品 ---下载(3) (rss)
  • 生活(47) (rss)
  • 知识(47) (rss)
  • 通讯规约(16) (rss)

随笔档案(137)

  • 2009年2月 (1)
  • 2008年6月 (3)
  • 2008年4月 (1)
  • 2008年2月 (2)
  • 2007年12月 (1)
  • 2007年11月 (1)
  • 2007年10月 (2)
  • 2007年9月 (1)
  • 2007年8月 (2)
  • 2007年7月 (4)
  • 2007年6月 (4)
  • 2007年5月 (4)
  • 2007年4月 (6)
  • 2007年3月 (4)
  • 2007年2月 (2)
  • 2007年1月 (1)
  • 2006年12月 (1)
  • 2006年11月 (1)
  • 2006年9月 (6)
  • 2006年8月 (12)
  • 2006年7月 (1)
  • 2006年6月 (6)
  • 2006年5月 (9)
  • 2006年4月 (3)
  • 2006年3月 (10)
  • 2006年2月 (10)
  • 2006年1月 (11)
  • 2005年12月 (12)
  • 2005年11月 (2)
  • 2005年10月 (6)
  • 2005年9月 (8)

文章分类(2)

  • 技术类(2) (rss)

文章档案(3)

  • 2013年1月 (1)
  • 2008年4月 (1)
  • 2005年8月 (1)

相册

  • SCADA

上传

  • about apache
  • 学习工业控制方面 -知识的好网站
  • 学学老外的思想!

最新随笔

  • 1. 好久没上来了哦
  • 2. 看看未来的节能车,61850竟然也包括其通讯
  • 3. News on IEC 61850
  • 4. 口乃心户之门!
  • 5. 活着!
  • 6. 在HK
  • 7. On-business
  • 8. life..
  • 9. AB PLC
  • 10. AN OVERVIEW OF REAL-TIME DATABASE SYSTEMS

搜索

  •  

积分与排名

  • 积分 - 112236
  • 排名 - 67

最新评论

  • 1. re: IEC104
  • 能否给我一份代码呢。最近刚开始学习104规约,邮箱是270797194@qq.com。不胜感激啊
  • --兵兵
  • 2. re: IEC104
  • 请将源码发给我学习学习啊,lucas_woo@gmail.com。谢谢!!!
  • --ww
  • 3. re: 哎,老有人问我Modbus CRC 算法!! 今天贴出代码!!(超值)以后不再回答
  • 嗯,楼主,谢谢了
  • --sanwen
  • 4. re: 下步学习内容!(下一代规约... ... ASN.1不学不行啊!!)
  • 貌似asnlab 的 ADT软件确实不错,编解码速度快,
  • --迷你猫
  • 5. re: 下步学习内容!(下一代规约... ... ASN.1不学不行啊!!)
  • 从来没接触过asn。1,如何可以最快上手?期待,lengshu66@163.com
  • --me

阅读排行榜

  • 1. Cygwin(或linux) 中环境变量的配置(要区分BASH 和TCSH)(5017)
  • 2. 下步学习内容!(下一代规约... ... ASN.1不学不行啊!!)(4992)
  • 3. 哎,老有人问我Modbus CRC 算法!! 今天贴出代码!!(超值)以后不再回答(4843)
  • 4.  1M带宽到底是多少?和磁盘的1M有什么区别?(4618)
  • 5. 查看. ODT文件! 同时支持windows 和linux(3454)

评论排行榜

  • 1. IEC104(27)
  • 2. 下步学习内容!(下一代规约... ... ASN.1不学不行啊!!)(11)
  • 3. http://www.xialala.com/(11)
  • 4.  1M带宽到底是多少?和磁盘的1M有什么区别?(10)
  • 5. 查看. ODT文件! 同时支持windows 和linux(6)

Powered by: 博客园
模板提供:沪江博客
Copyright ©2025 zfly