线程同步与进程同步
- 我们可以对线程同步和进程同步使用相同的同步机制吗?
- 哪些同步机制仅在进程内可用
- can we use the same synchronization mechanisams for both thread synchronization and process synchronization
- what are thes synchronization mechanisams that are avilable only within the process
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
信号量通常用于共享内存访问等方面的多进程同步。
临界区、互斥体和条件是进程内线程同步的更常见工具。
一般来说,用于同步线程的方法并不用于同步进程,但反之通常则不然。事实上,使用信号量进行线程同步是相当常见的。
semaphores are generally what are used for multi process synchronization in terms of shared memory access, etc.
critical sections, mutexes and conditions are the more common tools for thread synchronization within a process.
generally speaking, the methods used to synchronize threads are not used to synchronize processes, but the reverse is usually not true. In fact its fairly common to use semaphores for thread synchronization.
有多个同步实体。它们有不同的目的和范围。不同的语言和操作系统以不同的方式实现它们。例如,在 Windows 上,您可以使用监视器来同步进程内的线程,或使用互斥体来同步进程。有信号量、事件、障碍……这一切都取决于具体情况。 .NET 提供了所谓的精简版本,该版本提高了性能,但仅针对进程内同步。
但要记住一件事。同步进程需要系统资源,分配和操作(锁定和释放)需要相当长的时间。
There are several synchronization entities. They have different purposes and scope. Different languages and operating system implement them differently. On Windows, for one, you can use monitors for synching threads within a processes, or mutex for synching processes. There are semaphores, events, barriers... It all depends on the case. .NET provides so called slim versions that have improved performance but target only in-process synching.
One thing to remember though. Synching processes requires system resource, allocation and manipulation (locking and releasing) of which take quite a while.
参考。
至于具体的同步结构,这将取决于操作系统/环境/语言
Ref.
As to specific synchronisation constructs, that will depend on the OS/Environment/language
一个区别是:进程内的线程对进程的内存具有同等的访问权限。内存通常是进程私有的,但可以显式共享。
One difference: Threads within a process have equal access to the memory of the process. Memory is typically private to a process, but can be explicitly shared.