process - 时间戳可以用于同步具有竞争条件的进程吗?
问题描述
我想知道当竞争条件发生时,时间戳是否可以用来解决进程同步问题?
下面是每个想要进入临界区的进程的进入和退出部分的算法。入口部分使用 FCFS(先到先服务)技术来访问关键部分。
interested[N] is shared array of N integers where N is number of processes.
// This section executed when process enters critical section.
entry_section (int processNumber) {
interested [processNumber] = getCurrentTimeStamp (); // Gets the current timestamp.
index = findOldestProcessNumber (interested); // Find the process number with least timestamp.
while (index != processNumber);
}
// This section executed when process leaves critical section.
exit_section (int processNumber) {
interested [processNumber] = NULL;
}
据我说,这个算法满足同步的所有条件,即互斥、进度、有界等待和可移植性。那么,我说的对吗?
感谢您抽出时间。
解决方案
简短而甜蜜,这是这种方法的两个问题。
- 您的所有进程都在忙于等待。这意味着即使进程不能进入临界区,它仍然不能休息。这意味着 os 调度程序需要不断地调度所有感兴趣的进程,即使它们没有产生有意义的输出。这会损害性能和功耗。
- 这是最大的。不能保证两个进程不会有相同的时间戳。这可能不太可能,但当您想要保证互斥以防止竞争条件时,可能性并不是您要寻找的。
推荐阅读
- java - 为什么我的 Java 代码不能与 JavaFX 一起使用?
- cakephp - Cakephp 3.7 如何禁用身份验证错误消息
- sql - 如何获取关联的关联id是给定值的记录
- arrays - 使用具有多个值的过滤列中的唯一值填充数组
- android - 模态底片与持久底片性能
- r - R bvbox 中的 MVA 库 - 更改 yaxis 范围
- python - 如何在调整图像大小并将其保存到另一个文件夹时保留图像的文件名?
- php - 如何仅在组件类或插件上在十月 CMS 上创建中间件?
- python - 制作一个 0 到 nxn 矩阵并将其重塑为对
- google-bigquery - app_store_subscription_* 事件不会导出到 BigQuery