I. What Is a Deadlock?
A deadlock is a phenomenon in which multiple threads or processes, while executing, form a circular wait due to competing for resources, causing all participants to be unable to continue.
Simply put:
Every thread is waiting for other threads to release resources, while those other threads are waiting for it to release resources, so ultimately no one can continue.
For example, suppose the system has two locks:
- Lock A.
- Lock B.
Two threads acquire different locks:
- Thread A has acquired Lock A and is waiting for Lock B.
- Thread B has acquired Lock B and is waiting for Lock A.
At this point:
- Thread A does not release Lock A because it has not finished its operation.
- Thread B does not release Lock B because it has not finished its operation either.
- Thread A waits for Thread B.
- Thread B waits for Thread A.
The two threads form a circular wait, and the program cannot continue executing.
1. A Simple Deadlock Example
Here is a simulation using Python:
import threading
import time
lock_a = threading.Lock()
lock_b = threading.Lock()
def thread_a():
with lock_a:
print("线程 A 获得锁 A")
time.sleep(0.1)
with lock_b:
print("线程 A 获得锁 B")
def thread_b():
with lock_b:
print("线程 B 获得锁 B")
time.sleep(0.1)
with lock_a:
print("线程 B 获得锁 A")
t1 = threading.Thread(target=thread_a)
t2 = threading.Thread(target=thread_b)
t1.start()
t2.start()
t1.join()
t2.join()
The following execution may occur:
Thread A acquired Lock A
Thread B acquired Lock B
After that, the program waits indefinitely.
The reason is that each thread holds the lock the other needs.
The use of time.sleep() here is only to increase the probability that the two threads will interleave; it does not guarantee that a deadlock will occur on every run.
2. What Is the Difference Between a Deadlock and Normal Blocking?
A blocked thread does not necessarily mean a deadlock has occurred.
For example:
- A thread waits for network data.
- A thread waits for a file read to complete.
- A thread waits for a condition variable notification.
- A thread waits for another thread to finish executing.
These can all be normal blocking behavior.
A true deadlock requires a circular wait that cannot be resolved on its own, or another resource dependency that permanently prevents the system's participants from making progress.
| Aspect | Normal blocking | Deadlock |
|---|---|---|
| Reason for waiting | Waiting for an event or resource | Circular resource dependency |
| Recoverability | Usually yes | Usually cannot recover on its own |
| Whether other threads can make progress | Usually yes | Involved participants block each other |
| Typical scenario | Waiting for a network response | Two threads wait for each other's locks |
| Solution | Wait for the event to complete | Break the deadlock conditions or recover the system |
II. How Do Deadlocks Occur?
Deadlocks do not occur randomly; they are usually related to resource contention, lock acquisition order, and thread execution timing.
1. Threads Compete for Shared Resources
Suppose there are two threads in the system:
- Thread A needs resource X and resource Y.
- Thread B also needs resource X and resource Y.
If the two threads acquire the resources in different orders, a deadlock may occur.
For example:
Thread A: first acquires resource X, then requests resource Y
Thread B: first acquires resource Y, then requests resource X
After Thread A acquires X and Thread B acquires Y:
- A waits for B to release Y.
- B waits for A to release X.
This creates a circular wait.
2. Inconsistent Resource Acquisition Order
This is a very typical cause of deadlocks in software engineering.
For example:
def transfer_a_to_b():
with account_a_lock:
with account_b_lock:
transfer()
def transfer_b_to_a():
with account_b_lock:
with account_a_lock:
transfer()
A transfer needs to be made between two accounts.
If two threads perform transfers in opposite directions, the following may occur:
Thread 1:
acquires account_a_lock
waits for account_b_lock
Thread 2:
acquires account_b_lock
waits for account_a_lock
The key to solving this problem is to use a consistent lock acquisition order.
3. Performing Time-Consuming Operations While Holding a Lock
For example:
with lock:
update_shared_data()
call_remote_api()
write_file()
If a network request never returns, the lock may remain occupied for a long time.
Other threads may therefore keep waiting.
If other functions that need to acquire locks are also called while holding a lock, this may further create complex lock dependency relationships.
Therefore, while holding a lock, try to avoid the following as much as possible:
- Network requests.
- Remote database operations.
- Long-running I/O.
- Uncontrolled callbacks.
- Waiting for other threads to finish.
- Calling unknown third-party code.
4. Threads Waiting for Each Other
Deadlock does not necessarily occur only between mutex locks.
For example:
thread_a.join()
thread_b.join()
If Thread A waits for Thread B, and Thread B in turn waits for Thread A through other synchronization logic, a circular wait may form.
Condition variables, semaphores, thread completion notifications, and resource pools may also be involved in deadlocks.
Therefore, deadlock analysis cannot focus only on lock() and unlock(); it also needs to analyze the complete waiting relationships among threads.
5. Basic Process of Deadlock Formation
flowchart TD
A["Multiple threads start execution"] --> B["Compete for shared resources"]
B --> C["Threads each acquire some resources"]
C --> D["Continue requesting other resources"]
D --> E["Required resources are already held by other threads"]
E --> F["Thread enters waiting state"]
F --> G["Other threads are also waiting"]
G --> H["Circular wait forms"]
H --> I["Deadlock occurs"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style C fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style E fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style F fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style G fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style H fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style I fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
III. The Four Necessary Conditions for Deadlock
In operating system theory, there are four classic necessary conditions for deadlock.
These four conditions are commonly called the Coffman conditions.
As long as all four conditions hold simultaneously, the system may deadlock.
1. Mutual Exclusion
A resource can be used exclusively by only one execution unit at a time.
For example:
Lock A is currently held by Thread A.
Thread B requests Lock A and can only wait.
Common resources with mutual exclusion properties include:
- Mutex locks.
- Exclusive file access permissions.
- Exclusive devices.
- Certain database resource locks.
Not all resources must be mutually exclusive.
For example, immutable data that can be read by multiple threads at the same time does not necessarily require exclusive access.
2. Hold and Wait
A thread already holds some resources while continuing to request other resources.
For example:
Thread A:
Already holds Lock A
Continues to request Lock B
If Lock B is occupied by another thread, Thread A will wait while holding Lock A.
This is hold and wait.
3. No Preemption
Resources already acquired by a thread cannot be forcibly taken away by the system; they can only be released voluntarily by the holder.
For example:
Thread A acquires Lock A.
Thread B needs Lock A.
The system cannot simply force Thread A to release Lock A.
Mutex locks usually have this characteristic.
If the system can safely revoke resource allocation, or allow a task to roll back and then request resources again, this condition may be broken.
4. Circular Wait
Multiple threads form a chain of waiting relationships, one after another.
For example:
Thread A waits for a resource held by Thread B.
Thread B waits for a resource held by Thread C.
Thread C waits for a resource held by Thread A.
This forms a circular wait.
5. Relationship Between the Four Conditions
| Necessary Condition | Core Meaning | Typical Manifestation |
|---|---|---|
| Mutual Exclusion | A resource cannot be exclusively used by multiple threads at the same time | A lock can be held by only one thread |
| Hold and Wait | Continue requesting other resources while holding resources | Request Lock B after acquiring Lock A |
| No Preemption | Resources cannot be forcibly reclaimed | Must be released by the thread holding the lock |
| Circular Wait | Threads form a circular wait | A waits for B, B waits for A |
Pay special attention to the following:
The four conditions are necessary conditions for deadlock to occur; they do not mean that deadlock will necessarily occur as long as any one of them exists.
For example, a mutex lock by itself does not automatically cause deadlock. Only when the other conditions are also satisfied can a deadlock possibly form.
6. Relationship Diagram of the Four Conditions
flowchart TD
A["Mutual exclusion"] --> E["Deadlock may occur"]
B["Hold and wait"] --> E
C["No preemption"] --> E
D["Circular wait"] --> E
E --> F["All four conditions hold simultaneously"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style C fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style D fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style E fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style F fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
4. How to Understand Deadlock? Resource Allocation Graph
The resource allocation graph (Resource Allocation Graph) is an important tool for operating systems to analyze deadlock.
It uses a graph structure to represent processes, resources, and the request and allocation relationships involving resources.
1. Basic Elements in the Graph
A resource allocation graph mainly contains two types of nodes.
Process nodes:
They are usually represented by circles, for example:
- P1: process 1.
- P2: process 2.
- P3: process 3.
Resource nodes:
They are usually represented by rectangles, for example:
- R1: resource 1.
- R2: resource 2.
The dots inside a resource node can represent the number of instances of that resource.
The graph mainly contains two types of directed edges.
Request edge:
Process → Resource
It indicates that a process is requesting a resource but has not yet obtained it.
Assignment edge:
Resource → Process
It indicates that a resource has already been allocated to a process.
2. A Deadlock Example with Two Processes and Two Resources
Suppose:
- P1 has already acquired R1.
- P2 has already acquired R2.
- P1 is requesting R2.
- P2 is requesting R1.
Resource allocation relationships:
flowchart LR
P1(("P1")) -->|"Request"| R2["R2"]
R2 -->|"Allocated"| P2(("P2"))
P2 -->|"Request"| R1["R1"]
R1 -->|"Allocated"| P1
style P1 fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style P2 fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style R1 fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style R2 fill:#FFF3D6,stroke:#E7C77D,color:#75551D
A cycle is formed in the graph:
P1 → R2 → P2 → R1 → P1
The two processes are each waiting for the other to release a resource.
3. What Does a Cycle in a Resource Allocation Graph Mean?
You need to distinguish the number of resource instances.
Case 1: Each resource has only one instance
If every resource has only one instance, then the presence of a cycle in the resource allocation graph means that the system is deadlocked.
Case 2: A resource has multiple instances
If a resource has multiple instances, the appearance of a cycle in the graph does not necessarily mean deadlock.
This is because other resource instances may still be available, and a waiting process may eventually obtain the resource and continue executing.
For example:
R1 has 3 instances.
P1 holds 1 instance.
P2 holds 1 instance.
1 more instance is still available for allocation.
Even if a cyclic relationship appears in the graph, you still need to further analyze the number of resource instances, the current allocation state, and the remaining demands of the processes.
Therefore, you cannot simply assume that every cycle in a resource allocation graph equals a deadlock.
5. What Strategies Are There for Handling Deadlock?
Operating systems and applications usually handle deadlock from four directions:
- Deadlock prevention.
- Deadlock avoidance.
- Deadlock detection.
- Deadlock recovery.
These four approaches have different goals.
| Strategy | Core idea | Main characteristics |
|---|---|---|
| Deadlock prevention | Break one of the four necessary conditions | Prevent deadlock from occurring by design |
| Deadlock avoidance | Determine whether it is safe before allocating resources | Requires knowledge of resource demand information |
| Deadlock detection | Allow it to occur and check periodically | Can identify deadlocks that have already formed |
| Deadlock recovery | Resolve deadlocks that have already occurred | May require rolling back or terminating tasks |
Each is described below.
6. Deadlock Prevention: Breaking the Necessary Conditions by Design
The core idea of deadlock prevention (Deadlock Prevention) is:
By designing resource allocation rules, make at least one of the four necessary conditions impossible to hold.
1. Breaking the Mutual Exclusion Condition
If a resource itself can be shared, try to avoid exclusive access.
For example:
If multiple threads only need to read a single immutable piece of configuration data, they do not need to acquire a mutex for every read.
You can use:
- Immutable objects.
- Shared read-only data.
- Replicated resources.
- Lock-free read structures.
However, not all resources can be shared.
For example, two threads modifying the same account balance at the same time still require a synchronization mechanism.
Therefore, breaking the mutual exclusion condition only applies to resources that can be safely shared.
2. Breaking the Hold-and-Wait Condition
One approach is to require threads to request all needed resources at once before starting execution.
For example:
Thread A needs lock A and lock B.
Before execution:
Request lock A and lock B at the same time.
If both locks can be acquired:
Enter the critical section.
If they cannot both be acquired:
Release the resources already acquired and wait for the next request.
This prevents a thread from continuing to wait for other resources while holding some resources.
Advantages:
- It can break the hold-and-wait condition.
- It reduces the complexity of resource dependencies.
Disadvantages:
- All resource requirements must be known in advance.
- Resource utilization may decrease.
- Some resources may remain idle for a long time.
- It is not easy to implement in scenarios with dynamic resource requirements.
3. Breaking the No-Preemption Condition
If a thread cannot continue to acquire resources, you can try requiring it to release the resources it already holds.
For example:
Thread A already holds resource X.
Thread A requests resource Y, but Y is unavailable.
The system requires thread A to release X.
Thread A waits until both resources X and Y are available, then requests them again.
This method is suitable for tasks that can be safely paused, have their state saved, and be resumed.
For example:
- Database transaction rollback.
- Task state snapshots.
- Retryable computational tasks.
- System tasks that support resource revocation.
However, for some device operations, irreversible I/O, or operations that cannot be safely rolled back, forcibly preempting resources may not be practical.
4. Breaking the Circular Wait Condition
This is one of the most common and practical deadlock prevention methods in engineering.
Core idea:
Establish a unified acquisition order for all locks.
For example:
lock_a: number 1
lock_b: number 2
lock_c: number 3
All threads must acquire locks in ascending order by number.
Regardless of what business logic is being executed, a thread must not acquire a lock with a larger number first and then request a lock with a smaller number.
Code example:
import threading
lock_a = threading.Lock()
lock_b = threading.Lock()
def transfer_a_to_b():
with lock_a:
with lock_b:
print("执行转账")
def transfer_b_to_a():
with lock_a:
with lock_b:
print("执行转账")
Both operations follow the same locking order.
This prevents these two locks from forming a circular wait.
For a dynamic number of locks, you can first sort them by unique resource identifier and then request them in a fixed order.
def acquire_all(locks):
ordered_locks = sorted(locks, key=id)
for lock in ordered_locks:
lock.acquire()
return ordered_locks
def release_all(locks):
for lock in reversed(locks):
lock.release()
In a production environment, you also need to ensure:
- If an exception occurs during acquisition, locks already acquired can be released.
- All callers follow the same lock ordering rule.
- Lock identity and the ordering basis remain stable.
- Do not perform uncontrolled external operations while holding a lock.
You can further use context managers to encapsulate resource acquisition and release.
5. Workflow for Unified Lock Ordering
flowchart TD
A["Thread needs multiple locks"] --> B["Collect locks to request"]
B --> C["Sort by unique ID"]
C --> D["Request in a fixed order"]
D --> E{"All acquired?"}
E -->|Yes| F["Execute critical section operations"]
E -->|No| G["Release acquired resources according to policy"]
G --> H["Wait or request again"]
H --> D
F --> I["Release locks in reverse order"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style C fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style D fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style E fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style H fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style I fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
6. Summary of Four Prevention Methods
| Condition to Break | Prevention Method | Practical Difficulty |
|---|---|---|
| Mutual Exclusion | Use shared resources whenever possible | Resources may not be shareable |
| Hold and Wait | Request all resources at once | Resource requirements may change dynamically |
| No Preemption | Release resources and roll back | Resources may not be safely revoked |
| Circular Wait | Enforce a consistent resource acquisition order | Requires global adherence to the same rule |
In practical software engineering, enforcing a consistent lock order, narrowing critical sections, and reducing multiple-lock nesting are the prevention measures most worth prioritizing.
7. Deadlock Avoidance: Determine Safety Before Allocating Resources
Deadlock avoidance (Deadlock Avoidance) differs from deadlock prevention.
Deadlock prevention breaks the necessary conditions by design.
Deadlock avoidance, by contrast, determines before each resource allocation whether the system will still be in a safe state after the allocation.
The classic algorithm is the banker's algorithm (Banker's Algorithm).
1. What Is a Safe State?
A safe state (Safe State) means there exists at least one process execution order under which all processes can obtain the resources they need, complete their tasks, and release resources in turn.
This execution order is called a safe sequence (Safe Sequence).
For example:
There are 10 resource instances in the system.
Process P1 needs 3 resources.
Process P2 needs 4 resources.
Process P3 needs 2 resources.
The system currently has 5 available resources.
If there is an execution order under which every process can complete and release resources, then the current state is a safe state.
Note the following:
- A safe state means there is at least one order in which all processes can complete.
- An unsafe state means there is no guarantee that all processes can complete successfully.
- An unsafe state does not necessarily mean a deadlock has already occurred.
2. Core Idea of the Banker's Algorithm
The banker's algorithm treats system resource allocation as a bank lending to customers.
A bank does not approve a loan request immediately just because a customer asks; instead, it checks:
If this loan is approved, can the bank still satisfy all customers' eventual needs?
If a safe sequence still exists in the system, the request can be approved.
If the system would enter an unsafe state, this resource request is temporarily denied.
3. Key Data Structures in the Banker's Algorithm
Suppose the system has multiple processes and multiple resource types.
The algorithm needs to maintain the following data:
Available: Available Resources
How many resources the system currently has left.
Max: Maximum Demand
The maximum number of resources each process may need.
Allocation: Allocated Resources
The number of resources currently allocated to each process.
Need: Remaining Need
How many more resources each process needs to complete.
Calculation formula:
For example:
| Process | Max | Allocation | Need |
|---|---|---|---|
| P1 | 7 | 3 | 4 |
| P2 | 5 | 2 | 3 |
| P3 | 3 | 1 | 2 |
Assume the currently available resources are:
4. Safety Check
The basic steps of the safety check are:
- Initialize Work = Available.
- Initialize Finish, marking all unfinished processes as False.
- Find a process for which Need is less than or equal to Work.
- Assume that process completes and releases the resources it currently holds.
- Update Work.
- Continue searching for the next process that can complete.
- If all processes can complete, the system is safe.
- If no process that can continue to complete can be found, but unfinished processes still exist, then the system is unsafe.
Pseudocode:
def is_safe(available, allocation, need):
work = available[:]
finished = [False] * len(need)
safe_sequence = []
while True:
found = False
for i in range(len(need)):
if finished[i]:
continue
can_finish = all(
need[i][j] <= work[j]
for j in range(len(work))
)
if can_finish:
for j in range(len(work)):
work[j] += allocation[i][j]
finished[i] = True
safe_sequence.append(i)
found = True
if not found:
break
return all(finished), safe_sequence
This assumes that each resource has only one corresponding quantity in the resource-type vector; the actual algorithm can be extended to multiple resource types.
5. Complete Flow of the Banker's Algorithm
flowchart TD
A["Process requests resources"] --> B["Check whether the resource request is valid"]
B --> C{"Does the request exceed the remaining need?"}
C -->|Yes| D["Reject request"]
C -->|No| E{"Are available resources sufficient?"}
E -->|No| F["Process waits"]
E -->|Yes| G["Simulate resource allocation"]
G --> H["Perform safety check"]
H --> I{"Does a safe sequence exist?"}
I -->|Yes| J["Formally allocate resources"]
I -->|No| K["Undo simulated allocation"]
K --> F
J --> L["Process continues execution"]
L --> M["Release resources after completion"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style C fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style D fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style E fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style F fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style G fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style I fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style J fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style K fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style L fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style M fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
6. Advantages and Disadvantages of the Banker's Algorithm
Advantages:
- It can determine system safety before resource allocation.
- In theory, it can prevent the system from entering an unsafe state.
- It is suitable for scenarios where resource types and maximum demands can be determined in advance.
Disadvantages:
- It requires advance knowledge of each process's maximum resource demand.
- A safety check must be performed for every resource request.
- It is not flexible enough for dynamic resource demands.
- As the number of resources and the process scale increase, the checking cost rises.
The banker's algorithm is mainly used in theoretical teaching of operating system deadlock avoidance. Modern general-purpose operating systems and business applications usually do not run the complete banker's algorithm for every thread lock request.
VIII. Deadlock Detection: How Can We Detect Deadlocks That Have Already Occurred?
The idea behind deadlock detection is:
Allow the system to allocate resources normally, but periodically check whether the system has entered a deadlock state.
This strategy is suitable for scenarios where deadlocks are unlikely to occur but the system still needs the ability to detect and handle them.
1. Detecting Deadlocks Based on the Wait-for Graph
A wait-for graph is a simplified form of the resource allocation graph.
It retains only the waiting relationships between processes.
For example:
P1 waits for a resource held by P2.
P2 waits for a resource held by P3.
P3 waits for a resource held by P1.
It can be represented as:
flowchart LR
P1(("P1")) --> P2(("P2"))
P2 --> P3(("P3"))
P3 --> P1
style P1 fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style P2 fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style P3 fill:#EDE7F8,stroke:#B9A4DC,color:#514174
If each resource has only one instance, then the presence of a directed cycle in the wait-for graph means that a deadlock exists.
For example:
P1 → P2 → P3 → P1
2. Deadlock Detection for Resources with Multiple Instances
If some resources in the system have multiple instances, a simple cycle check is not sufficient.
The following factors must be considered together:
- The number of currently available resources.
- The resources already held by each process.
- The requests of each process that remain unsatisfied.
- Whether resource release can enable other processes to complete.
Its detection approach is similar to the safety check of the banker's algorithm, but it uses currently unsatisfied resource requests instead of each process's maximum resource demand.
3. When to Perform Deadlock Detection
It can be triggered by:
- Detection at fixed intervals.
- Detection when a resource request fails.
- Detection when system load is abnormal.
- Detection when a thread has been waiting for a long time.
- Detection when a critical business operation times out.
Different scenarios require a trade-off between detection cost and detection latency.
4. Deadlock Detection Workflow
flowchart TD
A["System running normally"] --> B["Collect resource allocation information"]
B --> C["Build wait-for relationships"]
C --> D["Perform deadlock detection"]
D --> E{"Does a deadlock exist?"}
E -->|No| F["Continue running"]
F --> A
E -->|Yes| G["Record deadlock participants"]
G --> H["Analyze wait chain and resource usage"]
H --> I["Choose recovery strategy"]
I --> J["Execute recovery"]
J --> K["Re-verify system state"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style C fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style D fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style E fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
style G fill:#FCE7E7,stroke:#E5A3A3,color:#8A3636
style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style I fill:#FFF3D6,stroke:#E7C77D,color:#75551D
style J fill:#EDE7F8,stroke:#B9A4DC,color:#514174
style K fill:#DCEFE5,stroke:#8EBFA5,color:#24563F