Select Page

Mutex

Mutex Asssignment

  • A shared resource is a resource that can be used by more than one task. Each task should gain exclusive access to the shared resource to prevent data corruption. This is called mutual exclusion.
  • Shared I/O devices require the use of mutual exclusion; for example, a task might need exclusive access to a printer.
  • We will consider printf (uses UART) function as a shared resource because any task may call at any time to print some thing.
  • Create two tasks, Task1 and Task2 with equal priorities as continuous processing tasks.
  • Task1 displays as “Task1 is running …” and Task2 as “Task2 is running …”
  • Observe the output. Do you see any data corruption in the output?
  • Now, use mutual exclusion for printf function in both the Tasks.
    Observe the output

Note: Use atomMutexCreate()atomMutexGet() and atomMutexPut() functions.

References

  1. Introduction to atomthreads
  2. atomthreads kernel Reference
  3. atomthreads Documentation