线程同步与进程同步

发布于 2024-10-10 11:18:46 字数 68 浏览 1 评论 0原文

  1. 我们可以对线程同步和进程同步使用相同的同步机制吗?
  2. 哪些同步机制仅在进程内可用
  1. can we use the same synchronization mechanisams for both thread synchronization and process synchronization
  2. what are thes synchronization mechanisams that are avilable only within the process

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

落花浅忆 2024-10-17 11:18:46

信号量通常用于共享内存访问等方面的多进程同步。

临界区、互斥体和条件是进程内线程同步的更常见工具。

一般来说,用于同步线程的方法并不用于同步进程,但反之通常则不然。事实上,使用信号量进行线程同步是相当常见的。

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.

‖放下 2024-10-17 11:18:46

有多个同步实体。它们有不同的目的和范围。不同的语言和操作系统以不同的方式实现它们。例如,在 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.

墨小墨 2024-10-17 11:18:46

一个应用程序由一个或多个
流程。一个过程,最简单的
术语,是一个正在执行的程序。一个或
更多线程在上下文中运行
过程。 线程是基本单位
操作系统分配的
处理器时间。一个线程可以执行
进程代码的任何部分,
包括目前正在处理的部分
由另一个线程执行。

参考

至于具体的同步结构,这将取决于操作系统/环境/语言

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

浊酒尽余欢 2024-10-17 11:18:46

一个区别是:进程内的线程对进程的内存具有同等的访问权限。内存通常是进程私有的,但可以显式共享。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文