Resources sharing

As i understand Two tasks can share the same resources but not at same time.

What are examples of resources sharing other than CPU time and memory in an RTOS application?

For instance 2 or more tasks access the same piece of hardware like a (the same) UART controller.
Then the access of each task must be protected against getting preempted by the other task e.g. using a mutex in an appropriate way.

2 Likes

Do you use mutex when your two task share the CPU?

Generally no - that’s the purpose of FreeRTOS. FreeRTOS tasks are swapped in an out (or scheduled and unscheduled) according to their priority and their ability to run. For more, I’d reference this page on scheduling

If you want true parallelism, you’ll need to have the two tasks running in different cores (see FreeRTOS AMP or SMP however this can bring up the problem of shared memory which would require a mutex.

The one case to use a mutex for sharing a “CPU” is if using some special feature of the CPU that isn’t saved as part of a context switch. This is a very unusual situation.

Have you solved a problem in which resources was time critical?

can you explain this problem a bit, it will give me a real idea

Using a mutex to protect shared resources or data is a common multi-tasking programming idiom. You’ll find lots of explanations and use cases in the web.