From 674c40b2bccfafc11fe7ba065536b54811464cb9 Mon Sep 17 00:00:00 2001 From: mohanson Date: Thu, 14 Nov 2024 13:56:54 +0800 Subject: [PATCH] Add running state --- rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md b/rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md index cc76429e..1239094e 100644 --- a/rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md +++ b/rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md @@ -215,20 +215,21 @@ Five new error types added: ## Deadlock -Deadlock is a situation where two or more processes are unable to proceed because they are each waiting for resources or conditions that can only be provided by another waiting process. In the context of this scheduler, where processes communicate via pipes and can enter various states, such as `Runnable`, `Wait`, `WaitForWrite`, `WaitForRead`, `Terminated`. In our scheduler, deadlock will occur if all unterminated processes are waiting and no process is in a runnable state. +Deadlock is a situation where two or more processes are unable to proceed because they are each waiting for resources or conditions that can only be provided by another waiting process. In the context of this scheduler, where processes communicate via pipes and can enter various states, such as `Runnable`, `Running`, `Terminated`, `WaitForExit`, `WaitForRead`, `WaitForWrite`. In our scheduler, deadlock will occur if all unterminated processes are waiting and no process is in a runnable state. -- The process enters the `Wait` state by calling the `wait()` -- The process enters the `WaitForWrite` state by calling the `write()` -- The process enters the `WaitForRead` state by calling the `read()` - The process enters the `Runnable` when a process is created, or it get returned from `wait()`, `write()` and `read()`. +- The process enters the `Running` when a process is running. - The process enters the `Terminated` when a process is terminated. +- The process enters the `WaitForExit` state by calling the `wait()` +- The process enters the `WaitForRead` state by calling the `read()` +- The process enters the `WaitForWrite` state by calling the `write()` Here are the main scenarios that may lead to deadlock: 0. **Circular Waiting**: If multiple processes are in the `Wait`, `WaitForWrite`, or `WaitForRead` states and are waiting on each other in a circular dependency, a deadlock can occur. For example, if: - Process A is in `WaitForRead` for data from Process B - - Process B is in `WaitForRead` for Process A. Both processes will wait indefinitely, as each is waiting for the other to proceed. -0. **Buffer Limits**: The pipe in ckb-vm is unbuffered. If one process blocks on a `WaitForWrite` state because the data is not fully read, and the reader process is also blocked in a `WaitForRead` state (but on a different file descriptor), this can create a deadlock if neither can proceed: + - Process B is in `WaitForRead` for data from Process A. Both processes will wait indefinitely, as each is waiting for the other to proceed. +0. **Buffer Limits**: Essentially, it's another circular waiting. The pipe in ckb-vm is unbuffered. If one process blocks on a `WaitForWrite` state because the data is not fully read, and the reader process is also blocked in a `WaitForRead` state (but on a different file descriptor), this can create a deadlock if neither can proceed: - Process A wants to read 10 bytes from fd0, and then read 10 bytes from fd1, and finally read 10 bytes from fd0. - Process B writes 20 bytes into fd0, and then write 10 bytes into fd1.