开发者

thread synchronization vs process synchronization

  1. can we use the same synchronization mechanisams for both thread synchronization and process synchronization
  2. what are thes synchroniz开发者_如何学Goation mechanisams that are avilable only within the process


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.


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.


An application consists of one or more processes. A process, in the simplest terms, is an executing program. One or more threads run in the context of the process. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the process code, including parts currently being executed by another thread.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜