No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:aih:lab:nrf52threads2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:edu:zmitac:s2:aih:lab:nrf52threads2 [2023/12/03 13:24] – ktokarz | en:edu:zmitac:s2:aih:lab:nrf52threads2 [2023/12/03 13:25] (current) – ktokarz | ||
|---|---|---|---|
| Line 173: | Line 173: | ||
| Function “Give” will increment the semaphore value up to the maximum limit, in which case the semaphore will not be modified. “Give” can be called from any thread or ISR because it does not stop program execution in any case. | Function “Give” will increment the semaphore value up to the maximum limit, in which case the semaphore will not be modified. “Give” can be called from any thread or ISR because it does not stop program execution in any case. | ||
| Function “Take” will decrement the semaphore count down to zero (the semaphore is unavailable). “Take” can be called only from threads but not from ISR, because if a thread is trying to " | Function “Take” will decrement the semaphore count down to zero (the semaphore is unavailable). “Take” can be called only from threads but not from ISR, because if a thread is trying to " | ||
| - | ===== Mutexes ===== | ||
| - | Mutexes are similar to the semaphores but present two values only: locked and unlocked. Despite this, they are implemented also as the counter in which zero value means that the resource is unlocked, and any other value means that the resource is locked. If the mutex is locked three times it also must be unlocked three times to make it unlocked. Another feature that differs between mutexes and semaphores is that the mutex can be unlocked only by the same thread which locks it. Mutexes are mainly used to synchronize the critical shared code that can be executed from many threads. | ||
| - | ===== Functions for semaphores and mutexes ===== | ||
| To create the semaphore with the name " | To create the semaphore with the name " | ||
| < | < | ||
| Line 197: | Line 194: | ||
| </ | </ | ||
| As you can see the k_sem_take() function has a timeout that can prevent the thread from hanging. This argument can also be K_NO_WAIT (returns immediately) and K_FOREVER (blocks the thread).\\ | As you can see the k_sem_take() function has a timeout that can prevent the thread from hanging. This argument can also be K_NO_WAIT (returns immediately) and K_FOREVER (blocks the thread).\\ | ||
| + | ===== Mutexes ===== | ||
| + | Mutexes are similar to the semaphores but present two values only: locked and unlocked. Despite this, they are implemented also as the counter in which zero value means that the resource is unlocked, and any other value means that the resource is locked. If the mutex is locked three times it also must be unlocked three times to make it unlocked. Another feature that differs between mutexes and semaphores is that the mutex can be unlocked only by the same thread which locks it. Mutexes are mainly used to synchronize the critical shared code that can be executed from many threads. | ||
| To create the mutex you can use the macro | To create the mutex you can use the macro | ||
| < | < | ||
en/edu/zmitac/s2/aih/lab/nrf52threads2.1701606280.txt.gz · Last modified: by ktokarz
