You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added image of the spinlock semaphore
- In osSemaphoreWait we burn CPU cycles when signal has not been received
- Updated main.c with semaphore example
Copy file name to clipboardExpand all lines: Semaphore/README.md
+10-2Lines changed: 10 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,22 @@
8
8
9
9

10
10
11
-
- In the above example we are writing data to the UART from thread 1 and thread 2
11
+
- In this example we are writing data to the UART from thread 1 and thread 2
12
12
- As you can see in the image above when writing to the UART Task1/Task2 might be pre-empted before the entire data can be written to the UART
13
13
- The above problem of shared resources can be solved using Semaphores
14
14
- Semaphores are essentially signals that can signal certain parts of the code when something is done/needs to be done.
15
15
16
16
# Spinlock Semaphore
17
17
18
-
> TODO,
18
+
- Wait for a signal to be raised to gain access to a shared resource
19
+
- During a **wait** this shared resource burns CPU cycles till it gets a signal from another thread.
20
+
21
+

22
+
23
+
- In this example since UART is a common resource between the thread1 and thread2 we use a form of communication between the two threads
24
+
- When the first thread has access to the UART the second thread is in the **wait** state (semaphore value is 0)
25
+
- Once the first thread is done writing data to the UART it gives a **signal** to the second thread.
26
+
- Conversely now the first thread is in the **wait** state. Once the second thread is done writing data to the UART it gives a **signal** to the first thread.
0 commit comments