Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.SyntaxDWORD WINAPI WaitForMultipleObjectsEx( __in DWORD nCount, __in const HANDLE *lpHandles, __in BO... Read More
posted @ 2012-03-24 23:00 Dance With Automation Views(492) Comments(0) Diggs(0) Edit
调试之前首先将代码编译成可执行文件,并打开运行程序,效果如下,我们看到程序在打印出2之后就Hung住了,而原因我们也很明确,就是Wait惹得。现在通过Windbg attach 这个进程,加载SOS, .load C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\sos.dll使用!threads命令打印出当前托管程序所有的线程,如下:ThreadCount: 4 UnstartedThread: 0 BackgroundThread: 1 PendingThread: 0 DeadThread: 1 Hosted Runtime: no PreEm. Read More
posted @ 2012-03-24 15:10 Dance With Automation Views(866) Comments(0) Diggs(0) Edit
线程是一个操作系统的概念,线程的同步也涉及到操作系统的知识。但是具体到不同的开发环境和开发语言中,线程的同步各有各的特点。所以我们可能会感兴趣,这些各具特色的线程同步技术是否一定离不开操作系统底层提供的同步技术呢,还是会在实现的过程中加入一些自己的偏方和窍门。O,这个问题太大了,需要慢慢来讨论。先解剖解剖一只小麻雀吧,这里我只对.Net 提供的Monitor类感兴趣,如有分析错误或不到位之处,还希望同学们积极交流反馈。我们知道Managed Code C#中用来线程同步的技术有好几种,而最常用的可能就是加锁了,也即是使用关键词lock。lock的语法如下:lock (_lockObject) Read More
posted @ 2012-03-24 14:41 Dance With Automation Views(518) Comments(0) Diggs(0) Edit