A wonderful discussion of key code segments: critical

xiaoxiao2021-03-06  70

Since the toilet on the plane is small, only one person can enter the use of toilet (protected resources) each time.

If there are multiple resources that are not used (there are multiple toilets, but can not be used together), such as Thread1 and Thread2 access one resource, Thread1 and Thread3 access another resource, then create a toilet for each resource!

If there are multiple resources to always be used together (multiple toilets can be used in a toilet), put all them in a toilet. You can create a critical_section structure to protect all resources.

Now, threads, whenever you want to access resources (in toilet), you first want to check the "Some" flag on the toilet door (call EntercriticalSECTION function).

Someone: Just waiting outside the door. what? Do you want to strive to squeeze? Resources will be destroyed

No one: cool, use it!

转载请注明原文地址:https://www.9cbs.com/read-87587.html

New Post(0)