- 浏览: 488950 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (185)
- job (15)
- linux/windows/unix/bash/shell (31)
- JAVA/J2EE/spring/hibernate/struts (30)
- VC/C++ (48)
- mysql/postgresql (6)
- php/jsp/asp/pear (1)
- FMS/flex/openlaszlo/red5/openmeetings (34)
- apache/tomcat/ftp/svn (6)
- xen/vm/Hadoop/cloudcompute (6)
- visual studio/eclipse/zendstudi/ant (8)
- others (1)
- windows异常处理 __try __except (1)
- (1)
- matlab (4)
- android (0)
最新评论
-
hongzhounlfd:
很透彻,很详细
依赖注入和控制反转 -
jefferyqjy:
谢谢~言简意赅~很明了!
依赖注入和控制反转 -
elderbrother:
太好了,谢谢
依赖注入和控制反转 -
east_zyd_zhao:
终于搞明白了
依赖注入和控制反转 -
Dremeng:
完美,一看就懂理解透彻
依赖注入和控制反转
Synchronizing Execution of Multiple Threads
To avoid race conditions and deadlocks, it is necessary to synchronize access by multiple threads to shared resources. Synchronization is also necessary to ensure that interdependent code is executed in the proper sequence.
避免死锁,多线程同步机制很主重要。有助于解决资源共享和协助工作的问题。
There are a number of objects whose handles can be used to synchronize multiple threads. These objects include:
有很东西的句柄可以同步多线程
Console input buffers
输入buf的控制台
Events
事件
Mutexes
互斥
Processes
进程
Semaphores
信号
Threads
线程
Timers
定时器
The state of each of these objects is either signaled or not signaled. When you specify a handle to any of these objects in a call to one of the wait functions, the execution of the calling thread is blocked until the state of the specified object becomes signaled.
这些东西的状态是有信号或者无信号的。当你调用等待函数的时候给这些东西一个句柄。线程的回调函数被阻止知道信号的状态改变(即用信号状态来控制进程函数的执行与否)
Some of these objects are useful in blocking a thread until some event occurs. For example, a console input buffer handle is signaled when there is unread input, such as a keystroke or mouse button click. Process and thread handles are signaled when the process or thread terminates. This allows a process, for example, to create a child process and then block its own execution until the new process has terminated.
这些东西很有用在阻止一个线程的执行直到某些事件发生。比如,控制台输入buf句柄被标记当还有待读取的输入,比如按键或者鼠标点击。(保证用户的输入被执行)。进程和线程的句柄被标记当进程或线程终止(terminates)。允许进程,比如创建子进程的时候阻止它自己执行,直到新的进程被创建。
Other objects are useful in protecting shared resources from simultaneous access. For example, multiple threads can each have a handle to a mutex object. Before accessing a shared resource, the threads must call one of the wait functions to wait for the state of the mutex to be signaled. When the mutex becomes signaled, only one waiting thread is released to access the resource. The state of the mutex is immediately reset to not signaled so any other waiting threads remain blocked. When the thread is finished with the resource, it must set the state of the mutex to signaled to allow other threads to access the resource.
在同时访问的时候保护资源共享,其他的东西也是很有用的。比如,多线程的每一个线程可以有一个互斥锁的句柄。在访问共享资源之前,线程必须等待线程锁的状态被标记。当线程锁的被标记,只有一个等待线程被释放去访问这些资源。这个互斥锁的状态立即去掉标记,其他等待的线程被阻止。当这个线程完成了,它必须改变互斥锁为标记状态,以便其他的进程可以访问这些资源。
For the threads of a single process, critical-section objects provide a more efficient means of synchronization than mutexes. A critical section is used like a mutex to enable one thread at a time to use the protected resource. A thread can use the EnterCriticalSection function to request ownership of a critical section. If it is already owned by another thread, the requesting thread is blocked. A thread can use the TryEnterCriticalSection function to request ownership of a critical section, without blocking upon failure to obtain the critical section. After it receives ownership, the thread is free to use the protected resource. The execution of the other threads of the process is not affected unless they attempt to enter the same critical section.
单进程的线程,(临界区)critical-section 对象提供比互斥锁更有效的同步机制。临界区对象提供类似互斥锁来协调某一个时刻只有一个线程去访问共享资源。线程可以用函数EnterCriticalSection 来请求获取临界区的所有权。如果临界区被其他进程所占有,则请求进程被阻止。
The WaitForInputIdle function makes a thread wait until a specified process is initialized and waiting for user input with no input pending. Calling WaitForInputIdle can be useful for synchronizing parent and child processes, because CreateProcess returns without waiting for the child process to complete its initialization.
For more information, see Synchronization.
To avoid race conditions and deadlocks, it is necessary to synchronize access by multiple threads to shared resources. Synchronization is also necessary to ensure that interdependent code is executed in the proper sequence.
避免死锁,多线程同步机制很主重要。有助于解决资源共享和协助工作的问题。
There are a number of objects whose handles can be used to synchronize multiple threads. These objects include:
有很东西的句柄可以同步多线程
Console input buffers
输入buf的控制台
Events
事件
Mutexes
互斥
Processes
进程
Semaphores
信号
Threads
线程
Timers
定时器
The state of each of these objects is either signaled or not signaled. When you specify a handle to any of these objects in a call to one of the wait functions, the execution of the calling thread is blocked until the state of the specified object becomes signaled.
这些东西的状态是有信号或者无信号的。当你调用等待函数的时候给这些东西一个句柄。线程的回调函数被阻止知道信号的状态改变(即用信号状态来控制进程函数的执行与否)
Some of these objects are useful in blocking a thread until some event occurs. For example, a console input buffer handle is signaled when there is unread input, such as a keystroke or mouse button click. Process and thread handles are signaled when the process or thread terminates. This allows a process, for example, to create a child process and then block its own execution until the new process has terminated.
这些东西很有用在阻止一个线程的执行直到某些事件发生。比如,控制台输入buf句柄被标记当还有待读取的输入,比如按键或者鼠标点击。(保证用户的输入被执行)。进程和线程的句柄被标记当进程或线程终止(terminates)。允许进程,比如创建子进程的时候阻止它自己执行,直到新的进程被创建。
Other objects are useful in protecting shared resources from simultaneous access. For example, multiple threads can each have a handle to a mutex object. Before accessing a shared resource, the threads must call one of the wait functions to wait for the state of the mutex to be signaled. When the mutex becomes signaled, only one waiting thread is released to access the resource. The state of the mutex is immediately reset to not signaled so any other waiting threads remain blocked. When the thread is finished with the resource, it must set the state of the mutex to signaled to allow other threads to access the resource.
在同时访问的时候保护资源共享,其他的东西也是很有用的。比如,多线程的每一个线程可以有一个互斥锁的句柄。在访问共享资源之前,线程必须等待线程锁的状态被标记。当线程锁的被标记,只有一个等待线程被释放去访问这些资源。这个互斥锁的状态立即去掉标记,其他等待的线程被阻止。当这个线程完成了,它必须改变互斥锁为标记状态,以便其他的进程可以访问这些资源。
For the threads of a single process, critical-section objects provide a more efficient means of synchronization than mutexes. A critical section is used like a mutex to enable one thread at a time to use the protected resource. A thread can use the EnterCriticalSection function to request ownership of a critical section. If it is already owned by another thread, the requesting thread is blocked. A thread can use the TryEnterCriticalSection function to request ownership of a critical section, without blocking upon failure to obtain the critical section. After it receives ownership, the thread is free to use the protected resource. The execution of the other threads of the process is not affected unless they attempt to enter the same critical section.
单进程的线程,(临界区)critical-section 对象提供比互斥锁更有效的同步机制。临界区对象提供类似互斥锁来协调某一个时刻只有一个线程去访问共享资源。线程可以用函数EnterCriticalSection 来请求获取临界区的所有权。如果临界区被其他进程所占有,则请求进程被阻止。
The WaitForInputIdle function makes a thread wait until a specified process is initialized and waiting for user input with no input pending. Calling WaitForInputIdle can be useful for synchronizing parent and child processes, because CreateProcess returns without waiting for the child process to complete its initialization.
For more information, see Synchronization.
发表评论
-
C++STL轻松导学(2)
2011-09-27 17:02 12732.2.2 第二版:工业时代- ... -
C++ STL轻松导学
2011-09-27 16:59 1130作为C++标准不可缺少的 ... -
Chapter 6 Exceptions(JAVA EXCEPTION IN NATIVE CODE)
2011-09-26 09:53 1456Contents | Prev | Next | Index ... -
JNI编程中如何传递参数和返回值。
2011-09-14 17:51 1754首先要强调的是,native方法不但可以传递Java的基本类型 ... -
Windows Mobile与Android应用开发对比
2011-09-06 11:44 1235Windows Mobile在经历过最初的Wince系列,po ... -
android和JNI经典blog.doc
2011-09-01 15:29 1703Android JNI调用 2011-02-24 1 ... -
定义VC 消息映射函数小结
2011-08-21 22:15 1281定义VC 消息映射函数小 ... -
多线程中的事件对象
2011-08-21 14:23 1401Using Event Objects 使用事件对象 Appl ... -
VC++多线程调用webservice实例
2011-08-21 12:04 1543一、开始多线程 1.开始 ... -
如何结束线程VC++
2011-08-21 09:20 2749Terminating a Thread Terminati ... -
VS2005使用多字节字符集问题
2011-08-03 13:27 20381>------ 已启动生成: 项目: psgdatat ... -
matlab的作图函数(二维) 星号,点号 颜色
2011-07-27 14:57 9918zz matlab的作图函数(二维 ... -
android 调用C++的so
2011-07-08 18:36 4328第一步:开发环境的安 ... -
windows异常处理__try__except
2011-07-07 14:24 1940try-except用法 try except是win ... -
Java中的一个byte
2011-06-30 14:34 976Java中的一个byte,其范围是-128~127的,而Int ... -
NDK中char*如何转换成jstring
2011-06-30 13:05 1836JNIEXPORT jstring JNICALLJava_T ... -
CFileDialog多选文件时的最大数量
2011-06-25 20:29 2217system("explorer d:\我的 ... -
C++信号处理编程风格规范
2011-06-24 10:07 21241.背景: C++做数字信号处理很普遍,如何 ... -
C++如何获取系统时间
2011-06-22 11:31 623//方案— 优点:仅使用C标准库;缺点:只能精确到秒级 #in ... -
C++编码中减少内存缺陷的方法和工具
2011-06-14 10:22 1157C++编码中减少内存缺陷的方法和工具 编程技术 ...
相关推荐
多线程的同步机制 多线程的同步机制 多线程的同步机制
讲述windows多线程编程的机制,包括线程同步、线程通讯等,每一个讲解附带源码
vc++ 线程同步与异步套接字编程实例,Windows套接字在两种模式下执行I/O操作,阻塞和非阻塞。在阻塞模式下,在I/O操作完成前,执行操作的Winsock函数会一直等待下去,不会立即返回程序(将控制权交还给程序)。而在非...
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
第十五课:多线程与聊天室程序的创建 第十六课:线程同步与异步套接字编程 第十七课:进程间通信 第十八课:ActiveX控件 第十九课:动态链接库 第二十课:HOOK和数据库访问 希望对大家的学习有帮助,如果不错,请帮点个赞...
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
VC++编程指南(中文版),不错的一本电子书。啥也不说了,直接看内容预览...第十二章 多线程与串行通信 12.1 多任务、进程和线程 12.2 线程的同步 12.3 串行通信与重叠I/O 12.4 一个通信演示程序 12.5 小结
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
在PB中利用Delphi的多线程机制实现对串口的实时监听;ActiveMovie控件在VC++多媒体程序开发中的应用;VC++环境下多虚拟桌面程序的实现;VC中动态打开显示数据库实现;利用Delphi编写远程控制程序;利用VC++6.0对...
第一课 Windows编程和面向对象技术 1.1 Windows发展历史 ...第十二章 多线程与串行通信 12.1 多任务、进程和线程 12.2 线程的同步 12.3 串行通信与重叠I/O 12.4 一个通信演示程序 12.5 小结
58·多线程方式同时进行多项任务 59·线程优先级示例==赛马 60·利用剪贴板实现exe程序间的数据交换 61·通过内存映射实现exe程序间的数据交换 62·通过消息机制实现exe程序间的数据交换 第七章 63·获取驱动器...
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
多线程; 使用DIBs和DrawDIB API (基于WFW)用于动画处理; 同步机制; 消息打包和解包; 定时机制; 自动和随机地传输地形; 图像管理器; 线程内消息快速排队支持; 键盘管理器:将虚拟键映射为本地坦克的随机移动...
用同步对象、自定义计数信号量等四种方法实现生产者消费者共享有限缓冲区问题Vc++源代码。问题描述:一些生产者线程各自找出自己要搜索的范围内的素数,并放到一个有限缓冲区——数组中,另一些消费者线程线程将数组...
第一课 Windows编程和面向对象技术 1.1 Windows发展历史 ...第十二章 多线程与串行通信 12.1 多任务、进程和线程 12.2 线程的同步 12.3 串行通信与重叠I/O 12.4 一个通信演示程序 12.5 小结
结合串口通信的机理和多线程同步方式,分析了Win32系统下多线程异步串口通信程序的开发方法. 1 引 言 串行通讯是计算机与其他设备进行数据交换时经常使用的方法之一,他具有实现简单,使用灵活方便,数据传输可靠...
使用临界区对象解决多线程同步问题 Chapter12\ThreadSyn\UseEvent ;使用事件对象解决多线程同步问题 Chapter12\ThreadSyn\UseMutex ;使用互斥对象解决多线程同步问题 Chapter12\ThreadSyn\UseSemaphore ;使用信号灯...
使用信号灯对象解决多线程同步问题 Chapter13\CmdLine ;使用命令行参数 Chapter13\Process ;创建进程的例子 Chapter13\ProcessList ;显示系统中运行的进程列表 Chapter13\Patch1 ;一个内存补丁程序 Chapter13\...