CN109213577A - A kind of method, apparatus and computer equipment of thread sleep - Google Patents
A kind of method, apparatus and computer equipment of thread sleep Download PDFInfo
- Publication number
- CN109213577A CN109213577A CN201710523203.2A CN201710523203A CN109213577A CN 109213577 A CN109213577 A CN 109213577A CN 201710523203 A CN201710523203 A CN 201710523203A CN 109213577 A CN109213577 A CN 109213577A
- Authority
- CN
- China
- Prior art keywords
- gsec
- sleep
- time
- thread
- current thread
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/466—Transaction processing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Measurement Of The Respiration, Hearing Ability, Form, And Blood Characteristics Of Living Organisms (AREA)
- Telephone Function (AREA)
Abstract
The present invention provides the method, apparatus and computer equipment of a kind of sleep of thread, which comprises the gsec for each thread history sleep duration that will acquire is stored into the array pre-established;Obtain the mark ID of current thread;Based on ID, search whether there is time term corresponding with ID in array;Time term if it exists obtains the first gsec of historical sleep duration corresponding with ID;Using preset when previous current thread need to sleep the second gsec of duration and the first gsec determines total gsec that current thread need to sleep;It determines millisecond time M of total gsec relative to unit millisecond, judges that millisecond time M is no and call sleep function that current thread is slept M milliseconds if millisecond time M is positive number as positive number;In this way, the sleep function called can be as accurate as microsecond when executing sleeping time, it is ensured that thread can precisely revive after sleep, improve the execution efficiency of thread.
Description
Technical field
The invention belongs to method, apparatus and computer equipment that field of communication technology more particularly to a kind of thread are slept.
Background technique
When being developed in Windows system, in order to reduce central processing unit (CPU, Central Processing
Unit consumption), it will usually application program function (API, the Application Programming that calling system provides
Interface) Sleep makes program sleep certain time.
But the precision of the function is inadequate, in some cases when calling the function to make one millisecond of program sleep, no
It can wake up as scheduled, and influence the execution logic of thread, and then influence the operational efficiency of thread.
Based on this, the present invention provides the method, apparatus and computer equipment of a kind of thread sleep, to solve in the prior art
The above problem.
Summary of the invention
In view of the problems of the existing technology, the embodiment of the invention provides the method, apparatus and meter of a kind of sleep of thread
Machine equipment is calculated, makes thread sleep certain time length in the sleep function provided by calling system in the prior art for solving,
When being used to reduce CPU power consumption, since the precision of sleep function is not high, thread cannot precisely revive, and lead to thread executes effect
The technical issues of rate declines.
The present invention provides a kind of method of thread sleep, which comprises
The gsec for each thread history sleep duration that will acquire is stored into each time term of array, the array
It pre-establishes;
Obtain the mark (ID, Identity) of current thread;
Based on the ID, search whether there is time term corresponding with the ID in the array;When described if it exists
Between item, obtain the first gsec of corresponding with ID historical sleep duration;
Using it is preset when the previous current thread need to sleep duration the second gsec and when first microsecond
Between determine total gsec that the current thread need to sleep;
It determines millisecond time M of the total gsec relative to unit millisecond, judges that the millisecond time M is no and be positive
Number calls sleep function that the current thread is slept M milliseconds if millisecond time M is positive number.
In above scheme, if the time term is not present in the array, further includes:
Add the corresponding time term of the current ID in the array, and by the gsec of the time term of addition
It is set as preset numerical value.
In above scheme, it is described using preset when the previous current thread needs to sleep the second gsec of duration
And first gsec determines total gsec that the current thread need to sleep, comprising:
Total gsec that the current thread need to sleep is determined using formula T1=(timeArray [id]+T) * delta
T1, wherein the timeArray [id] is first gsec, and the T is second gsec;The delta
For thread response error.
In above scheme, the thread response error delta is determined according to formula delta=T2/ (Tend-Tstart);
Wherein, the T2 be the practical third gsec slept of current thread, the Tstart be start execute sleep function when
Between point, the Tend be the sleep function execute terminate time point.
In above scheme, when the delta is greater than 1, total gsec that the current thread need to sleep utilizes formula
T3=timeArray [id]+T+ (timeArray [id]+T) * (delta -1) is determined;Wherein, described (timeArray [id]+
T) * (delta -1) is time difference offset.
In above scheme, when the delta is less than 1, total gsec that the current thread need to sleep utilizes formula
T4=timeArray [id]+T- (timeArray [id]+T) * (delta -1) is determined;Wherein, described (timeArray [id]+
T) * (delta -1) is time difference offset.
In above scheme, after determination total gsec is relative to one millisecond of millisecond time M, further includes:
Determine the remaining gsec U of total gsec using formula U=T1-M*1000, and when by the remaining microsecond
Between U save into the corresponding time term of the ID;Wherein, the T1 is total gsec that the current thread need to sleep.
The present invention also provides a kind of device of thread sleep, described device includes:
The gsec of storage unit, each thread history sleep duration for will acquire was stored to each time of array
Xiang Zhong, the array pre-establish;
Acquiring unit, for obtaining the mark ID of current thread;Based on the ID, search whether exist in the array
Time term corresponding with the ID;The time term if it exists, obtain historical sleep duration corresponding with the ID first are micro-
Time second;
Determination unit, for using it is preset when the previous current thread need to sleep duration the second gsec and institute
It states the first gsec and determines total gsec that the current thread need to sleep;
Call unit judges the millisecond for determining millisecond time M of the total gsec relative to unit millisecond
Time M no is positive number, if millisecond time M is positive number, calls sleep function that the current thread is slept M milliseconds.
The present invention also provides a kind of computer readable storage mediums, are stored thereon with computer program, and the program is processed
Device performs the steps of when executing
The gsec for each thread history sleep duration that will acquire is stored into each time term of array, the array
It pre-establishes;
Obtain the mark ID of current thread;
Based on the ID, search whether there is time term corresponding with the ID in the array;When described if it exists
Between item, obtain the first gsec of corresponding with ID historical sleep duration;
Using it is preset when the previous current thread need to sleep duration the second gsec and when first microsecond
Between determine total gsec that the current thread need to sleep;
It determines millisecond time M of the total gsec relative to unit millisecond, judges that the millisecond time M is no and be positive
Number calls sleep function that the current thread is slept M milliseconds if millisecond time M is positive number.
The present invention also provides a kind of computer equipments of thread sleep, comprising:
At least one processor;And
At least one processor being connect with the processor communication, wherein
The memory is stored with the program instruction that can be executed by the processor, and the processor calls described program to refer to
Order is able to carry out such as any of the above-described method.
The present invention provides the method, apparatus and computer equipment of a kind of sleep of thread, which comprises will acquire
Each thread history sleep duration gsec store into each time term of array, the array pre-establishes;It obtains
Take the mark ID of current thread;Based on the ID, search whether there is time term corresponding with the ID in the array;If
There are the time terms, obtain the first gsec of historical sleep duration corresponding with the ID;Using preset when previous
The current thread need to sleep the second gsec of duration and first gsec determines that the current thread needs to sleep
Total gsec;It determines millisecond time M of the total gsec relative to unit millisecond, judges that the millisecond time M is no
Call sleep function that current thread is slept M milliseconds if millisecond time M is positive number for positive number;In this way, due to
It is as unit of Microsecond grade, the sleep function of calling is executing sleep when determining total gsec that current thread need to sleep
It can be as accurate as microsecond when the time, and then improve the precision of sleep function, it is ensured that thread can precisely revive after sleep,
Improve the execution efficiency of thread.
Detailed description of the invention
Fig. 1 is the flow diagram for the thread sleep method that the embodiment of the present invention one provides;
Fig. 2 is the overall structure diagram of thread sleeping apparatus provided by Embodiment 2 of the present invention;
Fig. 3 is the overall structure diagram for the thread sleep computer equipment that inventive embodiments three provide.
Specific embodiment
For solving to make thread sleep certain time length in the sleep function provided by calling system in the prior art,
When being used to reduce CPU power consumption, since the precision of sleep function is not high, thread cannot precisely revive, and lead to thread executes effect
The technical issues of rate declines, the present invention provides the method, apparatus and computer equipment of a kind of sleep of thread, the method packets
Include: the gsec for each thread history sleep duration that will acquire is stored into each time term of array, and the array is pre-
First establish;Obtain the mark ID of current thread;Based on the ID, search whether to exist in the array corresponding with the ID
Time term;The time term if it exists obtains the first gsec of historical sleep duration corresponding with the ID;Using pre-
If when the previous current thread need to sleep the second gsec of duration and first gsec determine it is described current
Total gsec that thread need to sleep;It determines millisecond time M of the total gsec relative to unit millisecond, judges the milli
Second time M no is positive number, if millisecond time M is positive number, calls sleep function that current thread is slept M milliseconds.
Technical solution of the present invention is described in further detail below by drawings and the specific embodiments.
Embodiment one
The present embodiment provides a kind of methods of thread sleep, as shown in Figure 1, the method includes
The gsec of S101, each thread history sleep duration that will acquire are stored into each time term of array;
In this step, an array timeArray is pre-established, each time term of the array is gone through for saving each thread
The gsec of history sleep duration.It should be noted that each thread history sleep duration refers to that each thread executes every time and sleeps
After dormancy function, the superposition summation of remaining gsec (gsec i.e. less than one millisecond).
S102 obtains the mark ID of current thread;Based on the ID, search whether exist and the ID in the array
Corresponding time term;The time term if it exists obtains the first gsec of historical sleep duration corresponding with the ID;
In this step, if want the sleeping time for calling sleep function Usleep to execute current thread, need to utilize
GetCurrentThreadId function obtains the mark ID of current thread, and is based on the ID, in the array timeArray
In search whether exist time term corresponding with the ID;The time term if it exists obtains history corresponding with the ID and sleeps
First gsec of dormancy duration.
If in the array be not present the time term, it is also necessary to added in the array the current ID it is corresponding when
Between item, and set preset numerical value for the gsec in the time term of addition;In general preset numerical value is 0.
S103, when using preset the second gsec that need to be slept when the previous current thread and first microsecond
Between determine total gsec that the current thread need to sleep;
In this step, after getting the first gsec of the ID corresponding historical sleep duration, utilization is preset
The second gsec and first gsec that need to be slept when the previous current thread determine that the current thread need to be slept
The total gsec slept;It is described it is preset when previous current thread need to sleep duration the second gsec be hypothesis this work as
The gsec that preceding thread need to sleep.
Specifically, total gsec T1 that the current thread need to sleep is determined using formula (1);
T1=(timeArray [id]+T) * delta (1)
Wherein, in formula (1), the timeArray [id] is first gsec, first gsec
Substantially refer to current thread before executing this sleep function, when the microsecond less than one millisecond stored in the array
Between;The T is the second gsec;The delta is thread response error.The thread response error is for measuring system
The accuracy of sleep function Usleep is executed, i.e., is when calling sleep function Usleep makes the current thread practical time slept
When third gsec T2, until current thread sleep terminates to continue to start consumed time ratio at the time of execution.It will open herein
The time point for beginning to execute sleep function is denoted as Tstart, and the time point that the sleep function executes end is denoted as Tend.
It is possible to calculate the thread response error delta using formula (2):
Delta=T2/ (Tend-Tstart) (2)
It should be noted that when the delta is equal to 1, illustrate preset to work as previous current thread and need to sleep duration
Second gsec T is just equal to the practical third gsec T2 to sleep of current thread;So the second gsec T is very
Accurately.
When the delta is greater than 1, illustrate preset to work as previous current thread and need to sleep the second gsec T of duration
The third gsec T2 that sleeps practical greater than current thread;So to calculate actual current thread using formula (3) at this time
The total gsec T3 that need to be slept:
T3=timeArray [id]+T+ (timeArray [id]+T) * (delta -1) (3)
Wherein, described (timeArray [id]+T) * (delta -1) is time difference offset.
When the delta is less than 1, illustrate preset when previous current thread need to sleep the second gsec T of duration
The third gsec T2 that sleeps practical less than current thread;So to calculate actual current thread using formula (4) at this time
The total gsec T4 that need to be slept:
T4=timeArray [id]+T- (timeArray [id]+T) * (delta -1) (4)
Wherein, described (timeArray [id]+T) * (delta -1) is time difference offset.
And when the error between delta and 1 is smaller, illustrate that the precision of sleep function USleep is bigger, CPU is consumed at this time
It is smaller, when the error between delta and 1 is bigger, illustrate that the precision of sleep function USleep is smaller, CPU consumption at this time is bigger.
S104 determines millisecond time M of the total gsec relative to unit millisecond, judges that the millisecond time M is no
Call sleep function that current thread is slept M milliseconds if millisecond time M is positive number for positive number.
In this step, after getting total gsec T1, determine total gsec relative to unit using formula (5)
Sleep function precision, has thus been navigated to Microsecond grade, has improved the precision of sleep function by the millisecond time M of millisecond:
M=floor (T1,1000) (5)
Wherein, floor is bracket function
Then the remaining gsec U of total gsec is determined using formula (6), and utilizes formula (7) by the residue
Gsec U was saved into the historical sleep time corresponding with the ID.
U=T1-M*1000 (6)
TimeArray [id]=U (7)
After getting millisecond time M, judge that the millisecond time M is no for positive number, i.e., whether is greater than 0;If when the millisecond
Between M be positive number, then call sleep function make current thread sleep M milliseconds.If millisecond time M is 0, institute will not be called
State sleep function.
Embodiment two
Corresponding to embodiment one, the present embodiment also provides a kind of device of thread sleep, as shown in Fig. 2, described device packet
It includes: storage unit 21, acquiring unit 22, determination unit 23 and call unit 24;Wherein,
The time term storage of the gsec for each thread history sleep duration that the storage unit 21 is used to will acquire
Into each time term of array timeArray, the array timeArray is pre-established.It should be noted that described each
After thread history sleep duration refers to that each thread executes sleep function every time, remaining gsec is (i.e. micro- less than one millisecond
Second time) superposition summation.
And if when wanting to call sleeping time of the sleep function Usleep to execute current thread, the acquiring unit 22 is used for
The mark ID of current thread is obtained using GetCurrentThreadId function;Based on the ID, in the array timeArray
In search whether exist time term corresponding with the ID;The time term if it exists obtains history corresponding with the ID and sleeps
First gsec of dormancy duration;
If the time term is not present in the array, the acquiring unit 22 is also needed in the array timeArray
It is middle to add the corresponding time term of the current ID, and preset number is set by the gsec in the time term of addition
Value;In general preset numerical value is 0.
It is described true after the acquiring unit 22 gets the first gsec of the ID corresponding historical sleep duration
Order member 23 for using preset when the previous current thread need to sleep the second gsec of duration and described first micro-
Time second determines total gsec that the current thread need to sleep.It is described preset when previous current thread need to sleep duration
Second gsec is the gsec that this current thread assumed need to sleep.
Specifically, the determination unit 23 determines total gsec T1 that the current thread need to sleep using formula (1);
T1=(timeArray [id]+T) * delta (1)
Wherein, in formula (1), the timeArray [id] is first gsec, first gsec
Substantially refer to current thread before executing this sleep function, when the microsecond less than one millisecond stored in the array
Between;The T is the second gsec;The delta is thread response error.The thread response error is for measuring system
The accuracy of sleep function Usleep is executed, i.e., is when calling sleep function Usleep makes the current thread practical time slept
When third gsec T2, until current thread sleep terminates to continue to start consumed time ratio at the time of execution.It will open herein
The time point for beginning to execute sleep function is denoted as Tstart, and the time point that the sleep function executes end is denoted as Tend.
So, the determination unit 23 can also calculate the thread response error delta using formula (2):
Delta=T2/ (Tend-Tstart) (2)
It should be noted that when the delta is equal to 1, illustrate preset to work as previous current thread and need to sleep duration
Second gsec T is just equal to the practical third gsec T2 to sleep of current thread;So the second gsec T is very
Accurately.
When the delta is greater than 1, illustrate preset to work as previous current thread and need to sleep the second gsec T of duration
The third gsec T2 that sleeps practical greater than current thread;So the determination unit 23 will be calculated at this time using formula (3)
Total gsec T3 that actual current thread need to sleep:
T3=timeArray [id]+T+ (timeArray [id]+T) * (delta -1) (3)
Wherein, described (timeArray [id]+T) * (delta -1) is time difference offset.
When the delta is less than 1, illustrate preset when previous current thread need to sleep the second gsec T of duration
The third gsec T2 that sleeps practical less than current thread;So the determination unit 23 will be calculated at this time using formula (4)
Total gsec T4 that actual current thread need to sleep:
T4=timeArray [id]+T- (timeArray [id]+T) * (delta -1) (4)
Wherein, described (timeArray [id]+T) * (delta -1) is time difference offset.
And when the error between delta and 1 is smaller, illustrate that the precision of sleep function USleep is bigger, CPU is consumed at this time
It is smaller, when the error between delta and 1 is bigger, illustrate that the precision of sleep function USleep is smaller, CPU consumption at this time is bigger.
After determining total gsec T1, when the call unit 24 is used to determine total microsecond using formula (5)
Between millisecond time M of the T1 relative to unit millisecond, sleep function precision has thus been navigated to Microsecond grade, has improved sleep letter
Several precision:
M=floor (T1,1000) (5)
Wherein, floor is bracket function
Then the call unit 24 determines the remaining gsec U of total gsec using formula (6), and utilizes formula
(7) the residue gsec U was saved into the historical sleep time corresponding with the ID.
U=T1-M*1000 (6)
TimeArray [id]=U (7)
After getting millisecond time M, call unit 24 judges that the millisecond time M is no for positive number, i.e., whether is greater than 0;If
Millisecond time M is positive number, then calls sleep function that current thread is slept M milliseconds.If millisecond time M is 0,
The sleep function will not be called.
Embodiment three
The present embodiment also provides a kind of computer equipment of thread sleep, as shown in figure 3, the computer equipment includes:
Radio frequency (Radio Frequency, RF) circuit 310, memory 320, input unit 330, display unit 340, voicefrequency circuit
350, the components such as WiFi module 360, processor 370 and power supply 380.It will be understood by those skilled in the art that being shown in Fig. 3
Computer equipment structure do not constitute the restriction to computer equipment, may include than illustrating more or fewer components, or
Person combines certain components or different component layouts.
It is specifically introduced below with reference to each component parts of the Fig. 3 to computer equipment:
RF circuit 310 can be used for sending and receiving for signal, particularly, after the downlink information of base station is received, to processing
The processing of device 350.In general, RF circuit 310 includes but is not limited at least one amplifier, transceiver, coupler, low noise amplification
Device (Low Noise Amplifier, LNA), duplexer etc..
Memory 320 can be used for storing software program and module, and processor 350 is stored in memory 320 by operation
Software program and module, thereby executing the various function application and data processing of computer equipment.Memory 320 can be led
It to include storing program area and storage data area, wherein storing program area can be needed for storage program area, at least one function
Application program etc.;Storage data area, which can be stored, uses created data etc. according to computer equipment.In addition, memory 320
May include high-speed random access memory, can also include nonvolatile memory, a for example, at least disk memory,
Flush memory device or other volatile solid-state parts.
Input unit 330 can be used for receiving the number or character information of input, and generate the user with computer equipment
Setting and the related key signals input of function control.Specifically, input unit 330 may include keyboard 331 and other inputs
Equipment 332.Keyboard 331 collects the input operation of user on it, and drives corresponding connection according to preset formula
Device.Keyboard 331 gives processor 350 after collecting output information again.In addition to keyboard 331, input unit 330 can also include
Other input equipments 332.Specifically, other input equipments 332 can include but is not limited to touch panel, function key (such as sound
Measure control button, switch key etc.), trace ball, mouse, one of operating stick etc. or a variety of.
Display unit 340 can be used for showing information input by user or the information and computer equipment that are supplied to user
Various menus.Display unit 340 may include display panel 341, optionally, can use liquid crystal display (Liquid
Crystal Display, LCD), the forms such as Organic Light Emitting Diode (Organic Light-Emitting Diode, OLED)
To configure display panel 341.Further, keyboard 331 can cover display panel 341, when keyboard 331 detect it is on it or attached
After close touch operation, processor 350 is sent to determine the type of touch event, is followed by subsequent processing device 350 according to incoming event
Type corresponding visual output is provided on display panel 341.Although keyboard 331 and display panel 341 are conducts in Fig. 3
Two independent components realize the input and input function of computer equipment, but in some embodiments it is possible to by keyboard
331 is integrated with display panel 341 and that realizes computer equipment output and input function.
Voicefrequency circuit 350, loudspeaker 351, microphone 352 can provide the audio interface between user and computer equipment.
Electric signal after the audio data received conversion can be transferred to loudspeaker 351, be converted by loudspeaker 351 by voicefrequency circuit 350
For voice signal output;
WiFi belongs to short range wireless transmission technology, and computer equipment can help user to receive and dispatch by WiFi module 360
Email, browsing webpage and access streaming video etc., it provides wireless broadband internet access for user.Although Fig. 3
WiFi module 360 is shown, but it is understood that, and it is not belonging to must be configured into for computer equipment, it completely can root
It is omitted within the scope of not changing the essence of the invention according to needs.
Processor 370 is the control centre of computer equipment, utilizes various interfaces and the entire computer equipment of connection
Various pieces, by running or execute the software program and/or module that are stored in memory 320, and call and be stored in
Data in memory 320 execute the various functions and processing data of computer equipment, to carry out to computer equipment whole
Monitoring.Optionally, processor 370 may include one or more processing units;Preferably, processor 370 can be integrated using processing
Device, wherein the main processing operation system of application processor, user interface and application program etc..
Computer equipment further includes the power supply 380 (such as power supply adaptor) powered to all parts, it is preferred that power supply can
With logically contiguous by power-supply management system and processor 370.
The method, apparatus and computer equipment energy bring beneficial effect of thread sleep provided by the invention are at least:
The present invention provides the method, apparatus and computer equipment of a kind of sleep of thread, which comprises will acquire
Each thread history sleep duration gsec store in each time term into array, the array pre-establishes;
Obtain the mark ID of current thread;Based on the ID, search whether there is time term corresponding with the ID in the array;
The time term if it exists obtains the first gsec of historical sleep duration corresponding with the ID;Using preset current
The secondary current thread need to sleep the second gsec of duration and first gsec determines that the current thread need to be slept
The total gsec slept;It determines millisecond time M of the total gsec relative to unit millisecond, judges the millisecond time M
No is positive number, if millisecond time M is positive number, calls sleep function that the current thread is slept M milliseconds;In this way,
Due to when determining total gsec that current thread need to sleep, being as unit of Microsecond grade, the sleep function of calling is being held
It can be as accurate as microsecond when row sleeping time, and then improve the precision of sleep function, it is ensured that thread after sleep can essence
Quasi- revival, improves the execution efficiency of thread.
Algorithm and display are not inherently related to any particular computer, virtual system, or other device provided herein.
Various general-purpose systems can also be used together with teachings based herein.As described above, it constructs required by this kind of system
Structure be obvious.In addition, the present invention is also not directed to any particular programming language.It should be understood that can use various
Programming language realizes summary of the invention described herein, and the description done above to language-specific is to disclose this hair
Bright preferred forms.
In the instructions provided here, numerous specific details are set forth.It is to be appreciated, however, that implementation of the invention
Example can be practiced without these specific details.In some instances, well known method, structure is not been shown in detail
And technology, so as not to obscure the understanding of this specification.
Similarly, it should be understood that in order to simplify the disclosure and help to understand one or more of the various inventive aspects,
Above in the description of exemplary embodiment of the present invention, each feature of the invention is grouped together into single implementation sometimes
In example, figure or descriptions thereof.However, the disclosed method should not be interpreted as reflecting the following intention: i.e. required to protect
Shield the present invention claims features more more than feature expressly recited in each claim.More precisely, as following
Claims reflect as, inventive aspect is all features less than single embodiment disclosed above.Therefore,
Thus the claims for following specific embodiment are expressly incorporated in the specific embodiment, wherein each claim itself
All as a separate embodiment of the present invention.
Those skilled in the art will understand that can be carried out adaptively to the module in the equipment in embodiment
Change and they are arranged in one or more devices different from this embodiment.It can be the module or list in embodiment
Member or component are combined into a module or unit or component, and furthermore they can be divided into multiple submodule or subelement or
Sub-component.Other than such feature and/or at least some of process or unit exclude each other, it can use any
Combination is to all features disclosed in this specification (including adjoint claim, abstract and attached drawing) and so disclosed
All process or units of what method or apparatus are combined.Unless expressly stated otherwise, this specification is (including adjoint power
Benefit require, abstract and attached drawing) disclosed in each feature can carry out generation with an alternative feature that provides the same, equivalent, or similar purpose
It replaces.
In addition, it will be appreciated by those of skill in the art that although some embodiments in this include institute in other embodiments
Including certain features rather than other feature, but the combination of the feature of different embodiment means in the scope of the present invention
Within and form different embodiments.For example, in the following claims, embodiment claimed it is any it
One can in any combination mode come using.
Various component embodiments of the invention can be implemented in hardware, or to run on one or more processors
Software module realize, or be implemented in a combination thereof.It will be understood by those of skill in the art that can be used in practice
Microprocessor or digital signal processor (DSP) realize gateway according to an embodiment of the present invention, proxy server, in system
Some or all components some or all functions.The present invention is also implemented as executing side as described herein
Some or all device or device programs (for example, computer program and computer program product) of method.It is such
It realizes that program of the invention can store on computer readable storage medium, or can have one or more signal
Form.Such signal can be downloaded from an internet website to obtain, and perhaps be provided on the carrier signal or with any other
Form provides;The program performs the steps of the microsecond for each thread history sleep duration that will acquire when being executed by processor
Time stores in each time term into array, and the array pre-establishes;Obtain the mark ID of current thread;Based on institute
ID is stated, searches whether there is time term corresponding with the ID in the array;The time term if it exists, obtain with it is described
First gsec of the corresponding historical sleep duration of ID;Using preset when the previous current thread need to sleep the of duration
Two gsecs and first gsec determine total gsec that the current thread need to sleep;Determine total microsecond
Millisecond time M of the time relative to unit millisecond, judges that the millisecond time M is no for positive number, if the millisecond time M is positive
Number then calls sleep function that the current thread is slept M milliseconds.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and ability
Field technique personnel can be designed alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference symbol between parentheses should not be configured to limitations on claims.Word "comprising" does not exclude the presence of not
Element or step listed in the claims.Word "a" or "an" located in front of the element does not exclude the presence of multiple such
Element.The present invention can be by means of including the hardware of several different elements and being come by means of properly programmed computer real
It is existing.In the unit claims listing several devices, several in these devices can be through the same hardware branch
To embody.The use of word first, second, and third does not indicate any sequence.These words can be explained and be run after fame
Claim.
The foregoing is only a preferred embodiment of the present invention, is not intended to limit the scope of the present invention, it is all
Made any modifications, equivalent replacements, and improvements etc. within the spirit and principles in the present invention, should be included in protection of the invention
Within the scope of.
Claims (10)
1. a kind of method of thread sleep, which is characterized in that the described method includes:
The gsec for each thread history sleep duration that will acquire is stored into each time term of array, and the array is pre-
First establish;
Obtain the mark ID of current thread;
Based on the ID, search whether there is time term corresponding with the ID in the array;The time term if it exists,
Obtain the first gsec of historical sleep duration corresponding with the ID;
Using it is preset when the previous current thread need to sleep duration the second gsec and first gsec it is true
Total gsec that the fixed current thread need to sleep;
It determines millisecond time M of the total gsec relative to unit millisecond, judges that the millisecond time M is no for positive number, if
Millisecond time M is positive number, then calls sleep function that the current thread is slept M milliseconds.
2. the method as described in claim 1, which is characterized in that if the time term is not present in the array, further includes:
The corresponding time term of the current ID is added in the array, and the gsec of the time term of addition is arranged
For preset numerical value.
3. the method as described in claim 1, which is characterized in that the utilization is preset when the previous current thread needs are slept
Second gsec of dormancy duration and first gsec determine total gsec that the current thread need to sleep, packet
It includes:
Total gsec T1 that the current thread need to sleep is determined using formula T1=(timeArray [id]+T) * delta,
Wherein, the timeArray [id] is first gsec, and the T is second gsec;The delta is
Thread response error.
4. method as claimed in claim 3, which is characterized in that the thread response error delta is according to formula delta=
T2/ (Tend-Tstart) is determined;Wherein, the T2 is the practical third gsec slept of current thread, and the Tstart is
Start the time point of execution sleep function, the Tend is that the sleep function executes the time point terminated.
5. method as claimed in claim 3, which is characterized in that when the delta is greater than 1, the current thread needs to sleep
Total gsec utilize formula T3=timeArray [id]+T+ (timeArray [id]+T) * (delta -1) determine;Wherein,
(timeArray [id]+T) * (delta -1) is time difference offset.
6. method as claimed in claim 3, which is characterized in that when the delta is less than 1, the current thread needs to sleep
Total gsec utilize formula T4=timeArray [id]+T- (timeArray [id]+T) * (delta -1) determine;Wherein,
(timeArray [id]+T) * (delta -1) is time difference offset.
7. the method as described in claim 1, which is characterized in that determination total gsec is relative to one millisecond of milli
After second time M, further includes:
The remaining gsec U of total gsec is determined using formula U=T1-M*1000, and the residue gsec U is protected
It deposits into the corresponding time term of the ID;Wherein, the T1 is total gsec that the current thread need to sleep.
8. a kind of device of thread sleep, which is characterized in that described device includes:
The gsec of storage unit, each thread history sleep duration for will acquire is stored to each time term of array
In, the array pre-establishes;
Acquiring unit, for obtaining the mark ID of current thread;Based on the ID, search whether exist and institute in the array
State the corresponding time term of ID;The time term if it exists, when obtaining the first microsecond of historical sleep duration corresponding with the ID
Between;
Determination unit, for using preset when the previous current thread need to sleep the second gsec and described the of duration
One gsec determines total gsec that the current thread need to sleep;
Call unit judges the millisecond time for determining millisecond time M of the total gsec relative to unit millisecond
M no is positive number, if millisecond time M is positive number, calls sleep function that the current thread is slept M milliseconds.
9. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the program is held by processor
It is performed the steps of when row
The gsec for each thread history sleep duration that will acquire is stored into each time term of array, and the array is pre-
First establish;
Obtain the mark ID of current thread;
Based on the ID, search whether there is time term corresponding with the ID in the array;The time term if it exists,
Obtain the first gsec of historical sleep duration corresponding with the ID;
Using it is preset when the previous current thread need to sleep duration the second gsec and first gsec it is true
Total gsec that the fixed current thread need to sleep;
It determines millisecond time M of the total gsec relative to unit millisecond, judges that the millisecond time M is no for positive number, if
Millisecond time M is positive number, then calls sleep function that the current thread is slept M milliseconds.
10. a kind of computer equipment of thread sleep characterized by comprising
At least one processor;And
At least one processor being connect with the processor communication, wherein
The memory is stored with the program instruction that can be executed by the processor, and the processor calls described program to instruct energy
Enough methods executed as described in claim 1 to 7 is any.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710523203.2A CN109213577B (en) | 2017-06-30 | 2017-06-30 | Thread sleep method and device and computer equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710523203.2A CN109213577B (en) | 2017-06-30 | 2017-06-30 | Thread sleep method and device and computer equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109213577A true CN109213577A (en) | 2019-01-15 |
CN109213577B CN109213577B (en) | 2020-09-08 |
Family
ID=64976435
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710523203.2A Active CN109213577B (en) | 2017-06-30 | 2017-06-30 | Thread sleep method and device and computer equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109213577B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2023004662A1 (en) * | 2021-07-29 | 2023-02-02 | 华为技术有限公司 | Delay generation method and related device |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101090547A (en) * | 2007-07-24 | 2007-12-19 | 北京天碁科技有限公司 | Method and device for calibrating sleep clock of TD-SCDMA terminal |
CN101122870A (en) * | 2007-09-30 | 2008-02-13 | 金蝶软件(中国)有限公司 | Thread wakening control systems and method |
CN101206584A (en) * | 2006-12-18 | 2008-06-25 | 上海未来宽带技术及应用工程研究中心有限公司 | Method for implementing non accumulation inaccuracy and self-adaption timer |
US20080155549A1 (en) * | 2006-12-20 | 2008-06-26 | Blinick Stephen L | Method and Apparatus for Adjusting Sleep Time of Fixed High-Priority Threads |
CN106775620A (en) * | 2016-11-14 | 2017-05-31 | 武汉斗鱼网络科技有限公司 | A kind of timing method and device |
CN106815065A (en) * | 2015-11-27 | 2017-06-09 | 腾讯科技(深圳)有限公司 | The awakening method and device of background application, electronic equipment |
-
2017
- 2017-06-30 CN CN201710523203.2A patent/CN109213577B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101206584A (en) * | 2006-12-18 | 2008-06-25 | 上海未来宽带技术及应用工程研究中心有限公司 | Method for implementing non accumulation inaccuracy and self-adaption timer |
US20080155549A1 (en) * | 2006-12-20 | 2008-06-26 | Blinick Stephen L | Method and Apparatus for Adjusting Sleep Time of Fixed High-Priority Threads |
CN101090547A (en) * | 2007-07-24 | 2007-12-19 | 北京天碁科技有限公司 | Method and device for calibrating sleep clock of TD-SCDMA terminal |
CN101122870A (en) * | 2007-09-30 | 2008-02-13 | 金蝶软件(中国)有限公司 | Thread wakening control systems and method |
CN106815065A (en) * | 2015-11-27 | 2017-06-09 | 腾讯科技(深圳)有限公司 | The awakening method and device of background application, electronic equipment |
CN106775620A (en) * | 2016-11-14 | 2017-05-31 | 武汉斗鱼网络科技有限公司 | A kind of timing method and device |
Non-Patent Citations (4)
Title |
---|
KING_HHUANG: "VC实现微秒(十万分之一秒)休眠", 《HTTPS://BLOG.CSDN.NET/KING_HHUANG/ARTICLE/DETAILS/6370712》 * |
WU SHUKUI ET.AL: "FPGA-based high-precision network time synchronization research and Implementation", 《THE TENTH INTERNATIONAL CONFERENCE ON ELECTRONIC MEASUREMENT & INSTRUMENTS》 * |
李群: "Linux2.6内核新型高精度定时器的设计与实现", 《中国优秀硕士学位论文全文数据库信息科技辑(月刊)》 * |
胡通: "Android休眠机制设计与实现综述", 《中国优秀硕士学位论文全文数据库信息科技辑(月刊)》 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2023004662A1 (en) * | 2021-07-29 | 2023-02-02 | 华为技术有限公司 | Delay generation method and related device |
Also Published As
Publication number | Publication date |
---|---|
CN109213577B (en) | 2020-09-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103500002B (en) | The method of application program management, device and terminal unit | |
US9436521B2 (en) | TCP/IP stack-based operating system | |
CN102740321B (en) | Techniques to determine user presence | |
CN101657783B (en) | Method to control core duty cycles using low power modes | |
CN105830016B (en) | Power management method and power management device for user equipment | |
WO2014039207A1 (en) | Power sub-state monitoring and recording | |
CN106484555B (en) | The method and mobile terminal of abnormality detection and recovery | |
KR20150035576A (en) | Power efficient location notification | |
CN107368400A (en) | CPU monitoring methods, device, computer-readable recording medium and mobile terminal | |
CN106557407A (en) | A kind of monitoring method and device of apparatus of load | |
US9519338B2 (en) | Task processing apparatus and method including scheduling current and next-level task processing apparatus | |
CN109978482A (en) | Workflow processing method, device, equipment and storage medium | |
CN109392139A (en) | It is a kind of to receive the resource location indicating means to broadcast the message, apparatus and system | |
US20170178011A1 (en) | User pattern recognition and prediction system for wearables | |
CN106020962B (en) | A kind of course control method and terminal device | |
CN106155717A (en) | A kind of method and apparatus that SDK is integrated into third party APK | |
KR102060431B1 (en) | Apparatus and method for managing power in multi-core system | |
US10121210B2 (en) | Tracking power states of a peripheral device | |
WO2016179900A1 (en) | Routing device, power saving method and apparatus therefor, and storage medium | |
CN103455333A (en) | Desktop icon processing method and device and mobile terminal | |
CN109213577A (en) | A kind of method, apparatus and computer equipment of thread sleep | |
CN110321203A (en) | The seemingly-dead processing method of background process and client | |
WO2013101228A1 (en) | Middleware power management | |
US20140244190A1 (en) | Power usage analysis | |
CN107741883A (en) | A kind of method, apparatus and computer equipment for avoiding thread block |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right |
Effective date of registration: 20230724 Address after: 200000 building 10, No. 860, Xinyang Road, Lingang New District, China (Shanghai) pilot Free Trade Zone, Fengxian District, Shanghai Patentee after: Shanghai Langyu Health Technology (Group) Co.,Ltd. Address before: 430000 East Lake Development Zone, Wuhan City, Hubei Province, No. 1 Software Park East Road 4.1 Phase B1 Building 11 Building Patentee before: WUHAN DOUYU NETWORK TECHNOLOGY Co.,Ltd. |
|
TR01 | Transfer of patent right |