Skip to content

Commit 28eaaed

Browse files
author
Amanda Butler
authored
Merge pull request #298 from deepikabhavnani/CriticalSectionLock
Critical Section doc update
2 parents c7e842c + 6ac407f commit 28eaaed

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
## CriticalSectionLock
22

3+
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 destructor restores the state of interrupts upon exit. Nesting of critical section is supported, and the destructor enables interrupts only when you exit from the last nested critical section.
4+
5+
CriticalSectionLock class is based on RAII approach. In other words, the constructor acquires the lock, and the destructor destroys it automatically when it is out of scope. 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.
6+
7+
<span class="notes">**Note:** You must not use time-consuming operations, standard library and RTOS functions inside critical section.</span>
8+
9+
## CriticalSectionLock class reference
10+
311
[![View code](https://www.mbed.com/embed/?type=library)](https://os.mbed.com/docs/v5.6/mbed-os-api-doxy/classmbed_1_1_critical_section_lock.html)
12+
13+
## CriticalSectionLock example
14+
15+
Here is an example that demonstrates a race condition issue and how CriticalSectionLock helps resolves it.
16+
17+
[![View code](https://www.mbed.com/embed/?url=https://os.mbed.com/teams/mbed_example/code/mbed-os-example-critical-section/)](https://os.mbed.com/teams/mbed_example/code/mbed-os-example-critical-section/file/a88acbffd78b/main.cpp)

0 commit comments

Comments
 (0)