(Summary) high-concurrency Message Queue common notification and queue mechanisms
I recently studied a high-performance lock-free shared memory message queue, which uses fifo notifications. Combined with the previous article "millions of concurrent persistent connection server models based on pipeline notifications", we will summarize the commonly used notification mechanisms.
The following are typical notification mechanisms:
1. signal
In this mechanism, we send a special signal (such as SIGUSR1) to the notified process so that the sleeping read process is interrupted by signals and then wakes up.
This method has the following advantages: the read process does not need to listen to an additional eventfd, which is suitable for some scenarios where eventfd is not convenient. In addition, you can choose to use real-time signals (SIGRTMIN + 1 ), or use non-real-time signal (SIGUSR1 ).
The disadvantage of this method is that the notification is not real-time. Because the signal check is only performed when the response is interrupted, this time is related to the HZ and jiffies of the operating system.
2. socket
In this mechanism, the write process writes a character to the socket (domain socket), and then the read process obtains the data Arrival notification through epoll.
3. fifo
Similar to socket, the write process writes a character to the fifo, and then the read process uses epoll to receive data Arrival notifications.
4. pipe
Similar to 2 and 3.
5. eventfd/signalfd
It is similar to the previous one, but the kernel helps us with fifo and signal notifications in advance. Only new kernel versions are supported. The problem with this method is that the handle needs to be transferred between different processes. Non-fork implementation is complicated.
These methods all need to fall into the kernel. The notified process can receive notifications only in the kernel state. In scenarios with high processing performance requirements, fewer notifications should be used. Therefore, of course, it depends on whether the overhead of sending notifications in business scenarios is large. If the number of requests is large and the read process is busy with processing and the notification is not triggered frequently, it is appropriate.
Processing Windows api message queues
Both WM_PAINT and WM_TIMER have different priorities. WM_TIMER has the lowest priority. Only messages in the queue are executed, while WM_PAINT has a higher priority.
Start from Window Creation:
Createdomainwex, which will directly deliver WM_CREATE to the window routine without entering the message queue. Other messages are normally transmitted through the message queue, then, use GetMessage and DispatchMessage to retrieve and distribute the message to the corresponding routine until WM_QUITE is obtained, and the message loop ends.
For buttons and mouse messages, the system queue is first entered, and then the system queue is distributed to the corresponding thread message queue.
Remember, message queues are all threads, not all windows and processes, except system queues.
Programming experiences
I vaguely remember reading a chapter, saying that Borland's original Turbo Pascal was mainly written by a cool user. Haha, if someone writes a VC-like interface to GCC, I give both hands and feet to approve, and help him test it for free :-) sometimes I am thinking, borland used C ++ instead of Pascal when developing Delphi. What is the current market share of development tools? (I have never looked down on Pascal. In fact, my first language is Pascal. It's just because Pascal's books in the library have been borrowed to learn C by myself)
If I write an interface to Gcc, of course it is GCC. People who have used GCC never say that GCC is inferior to Visual C ++. There is no way to compare the two, not on a single order of magnitude. GCC is a powerful compiler that supports N types of hardware platforms and official software standards. It also introduces the features that many software developers urgently need. Most Excellent libraries are rarely compiled on GCC. Hey, what do you think about advertising for GCC?
As for the commercialization of GCC, I have seen some companies selling hardware products. Their accompanying compilers are GCC or their variants. Besides, a large number of software can be compiled using GCC. In terms of stability, I don't think it is worse than Visual C ++. In fact, I encountered the so-called Internal Error when I used Visual C ++, And I never complained about such an inexplicable Internal Error when I used GCC. I think GCC has the potential of commercial software. Haha, it is not as good as Visual C ++ in terms of visualization, although there are some GCC graphics front ends.
Opportunities come from patience. The more patience you have, the more opportunities you have.
Famous saying, famous saying, I have patience, and the opportunity is coming soon.
Let's take a hard time. Don't take the opportunity. You're not ready yet ~~
If you start with MFC or VC, you need to make a general software that can be used in the personal field, and there will be a lot of detours.
It's strange. How can we start with MFC or VB to take a lot of detours? It is very direct to call Win32 APIs from MFC or VB, especially in Visual C ++ MFC. Proverbs attaches great importance to the underlying layer. Isn't Win32 API far from the underlying layer? Do I have to write real general-purpose software at the Assembly level? Then I simply write a microcode to the CPU ~~~. VB is rarely used. As for the MFC, if you really understand the MFC, you are almost all proficient in all aspects of Windows (of course, I refer to the user space outside the Windows Kernel ).
).
Computer, whether it is hardware or software, is very important. One of the most important aspects of development is to figure out at what level you need to do. How much is necessary for a developer who writes middleware in java to master the underlying system? I think if you don't do anything at your own level, and do anything across layers at random, the result may be nothing but thankfulness. It's okay to study it yourself. If you are still unclear at work, it's dangerous.
Of course, I didn't want everyone to study it, but I 'd better ask a senior to develop a learning plan based on their own interests. Human energy is limited after all. We need to devote our limited energy to serving the people. Don't waste it.
I just want to mix up and eat, find a job, maybe it is enough to teach you to become a master of MFC and other books.
I think that only skilled use of a language is essential for every programmer. Other capabilities should be different for different development directions. For example, proverbs believes that the second stage is an interface that is proficient in a certain platform (such as Win32 API ). However, many senior developers tend to have little access to these underlying APIs, because the operating system has already accumulated many layers. For example, if you use Java to program on Win32, you almost do not need to deal with system APIs. This actually reflects the idea of software hierarchy: each layer is only responsible for its own functions, and only communicates with its adjacent layers.
1. "The software industry will soon mature and the threshold is getting higher and higher ." That's right. With the development of the software industry, I want to be successful... the rest of the article>