μC/OS-II—Semaphore management 1 (os_sem.c)

Directory Semaphore management Semaphore creation Semaphore deletion Get/wait for semaphore emit semaphore Semaphore management Semaphore creation OS_EVENT *OSSemCreate (INT16U cnt) {<!– –> OS_EVENT *pevent; #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr = 0u; #endif #ifdef OS_SAFETY_CRITICAL_IEC61508 \t if (OSSafetyCriticalStartFlag == OS_TRUE) {<!– –> OS_SAFETY_CRITICAL_EXCEPTION(); return ((OS_EVENT *)0); } […]

Semaphores–System V semaphores and Posix semaphores

What is a semaphore A semaphore is a counter used to control access to resources shared by multiple processes/threads. Often used together with locks. When a process/thread is accessing a resource, the semaphore can prevent another process/thread from disturbing it. Producer and consumer models are typical uses of semaphores. Why are there two sets of […]

Synchronization Quest: Understanding the differences and applications of System V and POSIX semaphores

Directory title 1. Introduction 1.1 Overview of the importance of semaphores 1.2 Purpose of this article: Compare System V and POSIX semaphores 2. Basics of Semaphores 2.1 Definition and Function of Semaphores 2.2 The role of semaphores in process synchronization (Role in Process Synchronization) Synchronization and Mutual Exclusion The similarity between the psychology of semaphores […]

Linux kernel critical section, mutex, semaphore

1. Critical section: Access public resources or a piece of code through serialization of multi-threads. It is fast and suitable for controlling data access. 2. Mutex: Designed to coordinate individual access to a shared resource. 3. Semaphore: Designed to control a resource with a limited number of users. Critical Section A simple way to ensure […]

Experiment 4-Implementation and application of semaphore

Implementation and application of semaphore Corresponding experiment manual: https://hoverwinter.gitbooks.io/hit-oslab-manual/content/sy4_sem.html Supplementary knowledge Semaphore operations Reference links: https://c.biancheng.net/view/8632.html https://www.cnblogs.com/Suzkfly/p/14351449.html head File: #include<fcntl.h> #include<sys/stat.h> #include<semaphore.h> Operation function: //Open the named semaphore sem_t * sem_open(const char * name, int oflag, mode_t mode, unsigned int value); //Close the semaphore int sem_close(sem_t * sem); //Delete semaphore file int sem_unlink(const cahr * […]

Linux system V semaphore

In Linux, a semaphore is a mechanism for synchronization and mutual exclusion between processes. It can be used to control access to shared resources to avoid race conditions caused by simultaneous access by multiple processes. Linux provides two types of semaphores: System V semaphores and POSIX semaphores. System V semaphores are operated through system calls […]

FreeRTOS mutual exclusion semaphore (mutex lock)

1. Mutually exclusive semaphore A mutually exclusive semaphore is actually a binary semaphore with priority inheritance, which is mostly used for mutually exclusive access to shared resources between different tasks. 2. Mutual exclusion semaphore reduces the impact of priority flipping When a mutex semaphore is being used by task L, and a task H also […]

FreeRTOS_mutually exclusive semaphore of semaphore

Table of Contents 1. Mutually exclusive semaphore 1.1 Introduction to mutually exclusive semaphores 1.2 Create a mutually exclusive semaphore 1.2.1 Function xSemaphoreCreateMutex() 1.2.2 Function xSemaphoreCreateMutexStatic() 1.2.3 Analysis of the Mutex Semaphore Creation Process 1.2.4 Release the mutex semaphore 1.2.5 Obtain mutex semaphore 2. Mutually exclusive semaphore operation experiment 2.1 Experimental procedures 2.1.1 main.c 2.1.2 Experimental […]

FreeRTOS task notification (use task notification to simulate binary semaphore)

Task notification is an event. FreeRTOS has added task notification function starting from version v8.2.0. There is a 32-bit member variable ulNotifiedValue in each TCB, which is specifically used for task notification. Task notifications can be used to replace semaphores, event flag groups, etc. on certain occasions, and have higher execution efficiency. A task that […]