1.临界区(Critical Section)
A synchronization object that allows one thread at a time to access a resource or section of code. Critical sections are useful when only one
thread at a time can be allowed to modify data or some other controlled resource. For example, adding nodes to a linked list is a process that should
only be allowed by one thread at a time.
Critical sections are used instead of mutexes when speed is critical and the resource will not be used across process boundaries.
一种【同步】对象,在一个时刻只允许一个线程访问临界资源或临界代码段。
当需要更快的速度时可用临界区代替互斥量,注意:临界资源只允许在一个进程中使用。
Critical Sections(临界段),源代码中如果有不能由两个或两个以上线程同时执行的部分,可以用临界段来使这部分的代码执行串行化。它只能在一个独立的
进程或一个独立的应用程序中使用。
优点:
速度快,原因是:临界区是用户方式的同步,其他是内核。(原因是什么呢?计算量小?)
缺点:
临界区不是内核对象,只能用于进程内部的线程同步。
VC可使用 CCriticalSection 参见atlmfc\include\afxmt.h