Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of the example of dual-process daemon in cUniverse +

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

I would like to share with you the example analysis of double-process guardianship in champact +. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

Popular science:

  university self-study operating system when do not understand, slowly also understand. The era of punches and paper cassettes was only programs. In order to solve the inefficient interaction between people and CPU, single-batch processors appeared that year. But still can not meet the demand, at this time multi-batch processing has become a time product (from transistors to small-scale integrated circuits to 3D transistor technology). The process (PCB process control block) is also used to solve the problem that the program is uncontrollable under multi-batch processing and the result is not reusable (the double-edged sword brought by resource sharing). However, time-sharing system, real-time system accuracy requirements, high concurrency requirements, threads are really based on the system and become the smallest scheduling execution unit.

  and atomic operations, critical sections, mutexes and other things are based on multithreading, thread synchronization, asynchronous synchronization. There is also the problem of synchronization between consumers and producers, philosophers and so on. Simple understanding is to ensure that the data is not confused, hierarchical and logical to cooperate with each other to carry out tasks. There are urgent tasks (high priority) that can preempt the processor, and are fair, and each process has a chance to be run; with large throughput, all must have a reasonable scheduling algorithm.

Atomic operation:

To put it simply,   ensures that when a resource is used, the current resource is not preempted by other CPU.

  disadvantages: can only solve a certain variable, such as a variable data to do a simple operation (there is a relative atomic operation API).

Critical area:

Based on the shortcomings of atomic operation, the concept of critical region is gradually formed in  . The critical section can protect a section of code instructions.

By InitializeCriticalSection (..) Initialize a critical area, which belongs to whoever initializes it, and there is the concept of owner.

The   owner's unlimited call to EnterCriticalSection () will not be blocked, and the rest will be blocked until DeleteCriricalSection () is destroyed, and the critical area is protected by InitializeCriticalSection-> LeaveCriticalSection.

Mutex:

What are the disadvantages of   critical zone? He's not a kernel object? What is a kernel object? we can call processes, threads, file IO, mutexes, semaphores, events, thread pools, access tokens, timers, etc., kernel objects. You can refer to the book "windows Core programming".

Since   is a kernel object? Of course, cross-process, critical region is unable to do this, mutex also has a concept similar to the possession rule of the critical region, the important thing is that there are two states: 1, excited state 2, non-excited state. To determine whether the current mutex is used, and if the process or thread within the mutex crashes, the mutex space will be automatically released and excited, but it can only be released by the owner and cannot be released by other threads.

  creates a mutex CreateMutex (), which is generally used to write a single instance process, because the mutex (parameter 3) is globally unique to the system, so you can determine whether the process already exists in the current system, and if it exists, it will no longer be opened or created.

OpenMutexW () opens a mutex

ReleaseMutex releases the existing mutex.

The source code for single process detection using mutexes is as follows:

# include # include # include using std::cout; using std::endl;BOOL IsMutex () {HANDLE hMutex = NULL; hMutex = CreateMutex (NULL, FALSE, L "TEXT"); if (hMutex) {if (ERROR_ALREADY_EXISTS = = GetLastError ()) {ReleaseMutex (hMutex); CloseHandle (hMutex); return TRUE;}} return FALSE } int main (void) {if (IsMutex ()) cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report