-
Notifications
You must be signed in to change notification settings - Fork 178
Critical Section doc update #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
d1c1ade
38c98e9
655c655
807375e
8bead55
72310c3
6ac407f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
## CriticalSectionLock | ||
|
||
The CriticalSectionLock class provides a mechanism to access a resource without interruption. With the `lock` API, you can enter critical section with interrupts disabled. The `unlock` API is the exit from critical section, and the state of interrupts is restored upon exit. Nesting of critical section is supported, and interrupts are enabled only when we exit from last nested critical section. | ||
|
||
CriticalSectionLock class is based on RAII approach. In other words, lock is acquired in constructor and destroyed automatically when out of scope as part of destructor. We do not recommend you use CriticalSectionLock as global or a member of a class because you will enter critical section on object creation, and all interrupts will be disabled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Query: Who or what acquires lock in the constructor? Also, who or what destroys lock automatically when it's out of scope? Also, who or what disables all interrupts when you use CriticalSectionLock as global or a member of a class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructor acquires the lock. Destructor destroys lock. |
||
|
||
<span class="notes">**Note:** You must not use time-consuming operations, standard library and RTOS functions inside critical section.</span> | ||
|
||
## CriticalSectionLock class reference | ||
|
||
[](https://os.mbed.com/docs/v5.6/mbed-os-api-doxy/classmbed_1_1_critical_section_lock.html) | ||
|
||
## CriticalSectionLock example | ||
|
||
Here is an example that demonstrates a race condition issue and how CriticalSectionLock helps resolves it. | ||
|
||
[](https://os.mbed.com/teams/mbed_example/code/mbed-os-example-critical-section/file/a88acbffd78b/main.cpp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query: Who or what restores the state of interrupts upon exist? Also, who or what enables interrupts only when we exist from the last critical section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructor - restores the state of interrupts/
Destructor