Skip to content

Commit e797d64

Browse files
committed
Follow xxuejie's advice
1 parent 674c40b commit e797d64

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,20 @@ Five new error types added:
217217
218218
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.
219219
220-
- The process enters the `Runnable` when a process is created, or it get returned from `wait()`, `write()` and `read()`.
221-
- The process enters the `Running` when a process is running.
220+
- The process enters the `Runnable` when a process is created, or it's blocking condition is resolved.
221+
- The process enters the `Running` when a process starts running.
222222
- The process enters the `Terminated` when a process is terminated.
223-
- The process enters the `WaitForExit` state by calling the `wait()`
224-
- The process enters the `WaitForRead` state by calling the `read()`
225-
- The process enters the `WaitForWrite` state by calling the `write()`
223+
- The process enters the `WaitForExit` state by calling the `wait()` on another process still running.
224+
- The process enters the `WaitForRead` state by calling the `read()`. A process might not actually enter `WaitForRead` state by calling `read()`, if data are already available at the other end. It only enters this state when it wants data but data are not ready, in other words, it has a blocking condition.
225+
- The process enters the `WaitForWrite` state by calling the `write()`. A process might not actually enter `WaitForRead` state by calling `write()`, if the other end is in `WaitForRead` state and is able to read all the data.
226226
227-
Here are the main scenarios that may lead to deadlock:
227+
If multiple processes are in the `WaitForExit`, `WaitForWrite`, or `WaitForRead` states and are waiting on each other in a circular dependency, a deadlock can occur. Here are two examples:
228228
229-
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:
230-
- Process A is in `WaitForRead` for data from Process B
231-
- Process B is in `WaitForRead` for data from Process A. Both processes will wait indefinitely, as each is waiting for the other to proceed.
232-
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:
229+
1. A simple deadlock scenario, both processes are waiting for the other process to send data:
230+
- Process A is in `WaitForRead` for data from process B
231+
- Process B is in `WaitForRead` for data from process A. Both processes will wait indefinitely, as each is waiting for the other to proceed.
232+
233+
2. Deadlock caused by unbuffered pipes. Note that 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:
233234
- Process A wants to read 10 bytes from fd0, and then read 10 bytes from fd1, and finally read 10 bytes from fd0.
234235
- Process B writes 20 bytes into fd0, and then write 10 bytes into fd1.
235236

0 commit comments

Comments
 (0)