In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Description
When OnIdle CPU is idle, processing messages, if you need timing function, you need to use timer wxTimer.
problem
For example, the timer function takes 10 seconds to run, the timing time is 10 milliseconds, whether to execute the timer function every 10 milliseconds, or wait for the timer function to finish before starting the re-timing
Result
Execute:: Sleep (10000) in the timer function; wait 10 seconds and find that you actually need to wait for the timer function execution to finish before starting the re-timing. So you need to be very careful in the following scenarios: you need to read the data regularly, and after reading the data, you perform a lot of time-consuming operations, and at this time, you need to start the thread to process it, which cannot be done in the timer function.
Examples
# include "wx/timer.h"
Private:
WxTimer * m_timer
/ / specify the ID of the timer
# define TIMER_ID 1000
/ / Associate timer ID with timing execution function
EVT_TIMER (TIMER_ID, CFlightInstrumentPanel::OnTimer)
/ / create a timer and specify which timer ID uses
M_timer = new wxTimer (this, TIMER_ID)
/ / start the timer. The parameter is the timing interval.
Masking timer-> Start (1000)
Write the execution content of the timer
Void CFlightInstrumentPanel::OnTimer (wxTimerEvent& event)
{
Static int x = 0
If (xStop ()
Be careful
A timer is a resource, similar to a file handle, that cannot be created indefinitely. After the timing ends, the timer is finally stopped, the resource is released, and if the timer is not stopped before closing the window, it will appear.
0xC0000005: an access conflict error occurred while reading the location 0xFEEEFF06. Check other articles for related content.
Efficiency Analysis of timer SetTimer scenario Analysis
The wxWidgets framework is used in the project, in which the timer wxTimer of the framework is applied, which is turned on and off frequently. In the embedded operating system, performance is the top priority, so I want to try to analyze whether the current application scenario will consume the resources of CPU and memory, track the source code of wxWidgets, and find that the timer uses SetTimer and KillTimer functions to start and destroy the timer in the windows system.
Doubt
The first point: whether the startup timer starts a thread, and then the Sleep wait time is triggered
The second point: frequently start the timer, and then turn it off, whether it needs to consume a lot of resources
If the first rule is true, thread creation and switching are very
Considerable expenses
Solve the puzzle
First point: to start the timer SetTimer is not to start a thread. This function mainly sets the new
The timer structure adds the kernel global variable gptmrFirst to the linked list, using the
KillTimer removes the structure of the timer. The system traverses the linked list regularly
Once the timing time is ready, a WM_TIMER message is sent to the program, and the application program
Receive the message and start processing logic
The second point: starting and closing timers only add or remove structures, and the efficiency should be
The higher one. The overhead of creating a thread and the stack it takes is considerable, although
You can set the thread stack size
Premise
The source code of the windows timer has not been found.
Reference: http://bbs.csdn.net/topics/360222963
Based on the following assertions:
There is a global variable gptmrFirst in win32k, which stores the pointer of the first timer structure, which is stored in the form of a linked list.
The thread calls GetMessageW- > NtUserGetMessage- > xxxInternalGetMessage- > xxxRealInternalGetMessage in the message loop
XxxRealInternalGetMessage will then call DoTimer,DoTimer to traverse the entire timer list and compare whether the Win32Thread pointer of each Timer is on the win32k.
The global variable gptiCurrent,gptiCurrent holds the pointer to the Win32Thread structure of the current thread (many win32k functions begin with EnterCrit, which sets the
Set gptiCurrent to the return value of PsGetThreadWin32Thread)
If so, it indicates that the Timer belongs to the current thread, so check to see if the Timer is ready (then), and if so, call StoreQMessage to place a WM_TIMER or
WM_SYSTIMER message, which will be retrieved by xxxRealInternalGetMessage later
The csrss.exe process has a kernel thread called raw input thread, whose kernel object address is placed in the win32k global variable gptiRit.
This thread handles keyboard input, mouse input, etc., and, of course, timers. It uses KeWaitForMultipleObjects to wait for a set of kernel objects, including master timing.
If the master timer arrives, execute TimerProc
The TimerProc function traverses the gptmrFirst linked list, reduces the remaining time for each timer, and sets the expired timer to be ready.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.