TencentOS-tiny tasks between communication (b)

First, the inter-task communication

1, mutex

Outline

Also known as mutex mutex, generally used for the protection of exclusive exclusive access to shared resources.

Mutex in at any time and will only be in the unlocked or locked state, when a task to get a lock (mutex locking), other tasks will fail when attempting to get the lock or into the blocked state, when the when the task releases the locks held (mutex unlock), wakes up a positive blocking wait mutex task, the task will be awakened acquire the lock.

In a multitasking operating environment, some shared resource does not have a multi-threaded reentrancy for resources (critical resources) such not want to be accessed simultaneously multi-tasking, mutex can be used to protect programming examples later chapters We will demonstrate this programming paradigm.

API to explain

Programming Example

1, in tos_config.h, the switch assembly arranged mutex TOS_CFG_MUTEX_EN:

#define TOS_CFG_MUTEX_EN 1u

2, preparation of the sample code main.c:

Published 45 original articles · won praise 71 · views 700 000 +

Guess you like

Origin blog.csdn.net/qq_36075612/article/details/104969006