CN107133092A - Multi-thread synchronization processing method, terminal and computer-readable recording medium - Google Patents

Multi-thread synchronization processing method, terminal and computer-readable recording medium Download PDF

Info

Publication number
CN107133092A
CN107133092A CN201710374533.XA CN201710374533A CN107133092A CN 107133092 A CN107133092 A CN 107133092A CN 201710374533 A CN201710374533 A CN 201710374533A CN 107133092 A CN107133092 A CN 107133092A
Authority
CN
China
Prior art keywords
thread
shared resource
synchrolock
priority
accessing
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.)
Pending
Application number
CN201710374533.XA
Other languages
Chinese (zh)
Inventor
陈伟韬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nubia Technology Co Ltd
Original Assignee
Nubia Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Nubia Technology Co Ltd filed Critical Nubia Technology Co Ltd
Priority to CN201710374533.XA priority Critical patent/CN107133092A/en
Publication of CN107133092A publication Critical patent/CN107133092A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Abstract

The invention discloses a kind of Multi-thread synchronization processing method, terminal and computer-readable recording medium, the method comprising the steps of:A thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in blocked state;Calculate the limit priority Pmax of the thread of all blocked states;If the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than the limit priority Pmax of the thread of all blocked states calculated, the priority of thread for getting synchrolock and access shared resource is set to Pmax;The thread for getting synchrolock and accessing shared resource discharges synchrolock and recovers priority for P1 after management and running are complete.Invention prevents the relatively low thread of thread priority when accessing resource, because thread priority is relatively low, the chance that obtains management and running it is smaller, so that the thread takes the overlong time of synchrolock, and then cause the thread of the higher wait synchrolock of other thread priorities can not be continued executing with always.

Description

Multi-thread synchronization processing method, terminal and computer-readable recording medium
Technical field
The present invention relates to field of terminal technology, more particularly to a kind of Multi-thread synchronization processing method, terminal and computer can Read storage medium.
Background technology
When using multiple threads to access same data, it is very easy to safety problem occur, for example:Multiple threads are all Operating the problem of same data cause data inconsistent or be inaccurate etc..It would therefore be desirable to be solved with synchronization mechanism These problems, that is, thread synchronization.Thread synchronization refers in multiple threads while, it is necessary to ensure when accessing same resource The resource can only be monopolized by a thread every time.
During the present invention is realized, inventor has found that prior art has problems with:Different threads have different Thread priority, thread priority is higher, more has an opportunity to obtain management and running;The relatively low thread of thread priority is accessing resource When, because thread priority is relatively low, the chance for obtaining management and running is smaller so that the thread takes the overlong time of synchrolock, And then cause the thread of the higher wait synchrolock of other thread priorities can not be continued executing with always, eventually result in resistance Overlong time, or even interim card, application program are filled in without response (Application Not Response, ANR).
The content of the invention
It is a primary object of the present invention to propose a kind of Multi-thread synchronization processing method, terminal and computer-readable storage medium Matter, it is intended to solve the problem of prior art is present.
To achieve the above object, first aspect of the embodiment of the present invention provides a kind of Multi-thread synchronization processing method, the side Method includes step:
A thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in blocked state; The priority for wherein getting synchrolock and accessing the thread of shared resource is P1;
Calculate the limit priority Pmax of the thread of all blocked states;
If the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than all obstructions calculated The limit priority Pmax of the thread of state, then set the priority of the thread for getting synchrolock and accessing shared resource It is set to Pmax;
The thread for getting synchrolock and accessing shared resource discharges synchrolock and recovered after management and running are complete Priority is P1.
Further, a thread in the multiple threads of the step get synchrolock and access shared resource by with Lower step is realized:
Receive the shared resource access request that a thread in the multiple thread is sent;
According to the shared resource access request, the shared resource is supplied to a line in the multiple thread Journey.
Further, the shared resource is supplied to described many by the step according to the shared resource access request Also include step before a thread in individual thread:
Judge whether the lock of the shared resource has been released;
If the lock of the shared resource has been released, step is performed according to the shared resource access request, will be described Shared resource is supplied to a thread in the multiple thread.
Further, the management and running for getting synchrolock and accessing the thread of shared resource are real by following steps It is existing:
Synchrolock is got described in receiving and accesses the dispatch request of the thread of resource;
Whether the priority for getting synchrolock described in judging and accessing the thread of resource meets preparatory condition;
If the priority for getting synchrolock and accessing the thread of resource meets preparatory condition, the acquisition is run To synchrolock and access the thread of resource.
Further, methods described also includes step:
Other threads in blocked state are waken up, and continue executing with a thread in the multiple threads of step and are got together Step is locked and accesses shared resource, and other threads are in blocked state.
In addition, to achieve the above object, second aspect of the embodiment of the present invention provides a kind of terminal, the terminal includes:Deposit Reservoir, processor and it is stored in the Multi-thread synchronization processing routine that can be run on the memory and on the processor, institute Following steps are realized when stating Multi-thread synchronization processing routine by the computing device:
A thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in blocked state; The priority for wherein getting synchrolock and accessing the thread of shared resource is P1;
Calculate the limit priority Pmax of the thread of all blocked states;
If the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than all obstructions calculated The limit priority Pmax of the thread of state, then set the priority of the thread for getting synchrolock and accessing shared resource It is set to Pmax;
The thread for getting synchrolock and accessing shared resource discharges synchrolock and recovered after management and running are complete Priority is P1.
Further, the Multi-thread synchronization processing routine by the computing device when be additionally operable to realize following steps:
Receive the shared resource access request that a thread in the multiple thread is sent;
According to the shared resource access request, the shared resource is supplied to a line in the multiple thread Journey.
Further, the Multi-thread synchronization processing routine by the computing device when be additionally operable to realize following steps:
Judge whether the lock of the shared resource has been released;
If the lock of the shared resource has been released, step is performed according to the shared resource access request, will be described Shared resource is supplied to a thread in the multiple thread.
Further, the Multi-thread synchronization processing routine by the computing device when be additionally operable to realize following steps:
Synchrolock is got described in receiving and accesses the dispatch request of the thread of resource;
Whether the priority for getting synchrolock described in judging and accessing the thread of resource meets preparatory condition;
If the priority for getting synchrolock and accessing the thread of resource meets preparatory condition, the acquisition is run To synchrolock and access the thread of resource;
It is additionally operable to realize following steps when the Multi-thread synchronization processing routine is by the computing device:
Other threads in blocked state are waken up, and continue executing with a thread in the multiple threads of step and are got together Step is locked and accesses shared resource, and other threads are in blocked state.
Furthermore, to achieve the above object, the third aspect of the embodiment of the present invention provides a kind of computer-readable recording medium, institute The Multi-thread synchronization processing routine that is stored with computer-readable recording medium is stated, the Multi-thread synchronization processing routine is by processor The step of above-mentioned Multi-thread synchronization processing method is realized during execution.
A kind of Multi-thread synchronization processing method provided in an embodiment of the present invention, terminal and computer-readable recording medium, lead to Cross judge access shared resource thread priority whether be less than all blocked states thread limit priority Pmax, if Priority less than the thread that will then access shared resource is set to Pmax, access the thread of shared resource management and running it is complete it After recover priority;The relatively low thread of thread priority is prevented when accessing resource, because thread priority is relatively low, adjusted The chance for spending operation is smaller so that the thread takes the overlong time of synchrolock, the wait for causing other thread priorities higher The thread of synchrolock can not be continued executing with always, and final caused blocking time is long, or even interim card, application program are without sound The phenomenon answered.
Brief description of the drawings
Fig. 1 is the hardware architecture diagram for the mobile terminal for realizing each embodiment of the invention;
Fig. 2 is a kind of communications network system Organization Chart provided in an embodiment of the present invention;
Fig. 3 is the Multi-thread synchronization process flow schematic diagram of the embodiment of the present invention;
Fig. 4 is another schematic flow sheet of Multi-thread synchronization processing method of the embodiment of the present invention;
Fig. 5 is the terminal structure schematic diagram of the embodiment of the present invention;
Fig. 6 handles schematic diagram for the Multi-thread synchronization of the embodiment of the present invention.
The realization, functional characteristics and advantage of the object of the invention will be described further referring to the drawings in conjunction with the embodiments.
Embodiment
It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, it is not intended to limit the present invention.
In follow-up description, the suffix using such as " module ", " part " or " unit " for representing element is only Be conducive to the explanation of the present invention, itself there is no a specific meaning.Therefore, " module ", " part " or " unit " can be mixed Ground is used.
Terminal can be implemented in a variety of manners.For example, the terminal described in the present invention can include such as mobile phone, flat board Computer, notebook computer, palm PC, personal digital assistant (Personal Digital Assistant, PDA), portable Media player (Portable Media Player, PMP), guider, wearable device, Intelligent bracelet, pedometer etc. are moved Move the fixed terminals such as terminal, and numeral TV, desktop computer.
It will be illustrated in subsequent descriptions by taking mobile terminal as an example, it will be appreciated by those skilled in the art that except special Outside element for moving purpose, construction according to the embodiment of the present invention can also apply to the terminal of fixed type.
Referring to Fig. 1, its hardware architecture diagram for a kind of mobile terminal of realization each embodiment of the invention, the shifting Dynamic terminal 100 can include:RF (Radio Frequency, radio frequency) unit 101, WiFi module 102, audio output unit 103rd, A/V (audio/video) input block 104, sensor 105, display unit 106, user input unit 107, interface unit 108th, the part such as memory 109, processor 110 and power supply 111.It will be understood by those skilled in the art that shown in Fig. 1 Mobile terminal structure does not constitute the restriction to mobile terminal, and mobile terminal can be included than illustrating more or less parts, Either combine some parts or different parts arrangement.
The all parts of mobile terminal are specifically introduced with reference to Fig. 1:
Radio frequency unit 101 can be used for receiving and sending messages or communication process in, the reception and transmission of signal, specifically, by base station Downlink information receive after, handled to processor 110;In addition, up data are sent into base station.Generally, radio frequency unit 101 Including but not limited to antenna, at least one amplifier, transceiver, coupler, low-noise amplifier, duplexer etc..In addition, penetrating Frequency unit 101 can also be communicated by radio communication with network and other equipment.Above-mentioned radio communication can use any communication Standard or agreement, including but not limited to GSM (Global System of Mobile communication, global system for mobile telecommunications System), GPRS (General Packet Radio Service, general packet radio service), CDMA2000 (Code Division Multiple Access 2000, CDMA 2000), WCDMA (Wideband Code Division Multiple Access, WCDMA), TD-SCDMA (Time Division-Synchronous Code Division Multiple Access, TD SDMA), FDD-LTE (Frequency Division Duplexing-Long Term Evolution, FDD Long Term Evolution) and TDD-LTE (Time Division Duplexing-Long Term Evolution, time division duplex Long Term Evolution) etc..
WiFi belongs to short range wireless transmission technology, and mobile terminal can help user's transmitting-receiving electricity by WiFi module 102 Sub- mail, browse webpage and access streaming video etc., it has provided the user wireless broadband internet and accessed.Although Fig. 1 shows Go out WiFi module 102, but it is understood that, it is simultaneously not belonging to must be configured into for mobile terminal, completely can be according to need To be omitted in the essential scope for do not change invention.
Audio output unit 103 can be in call signal reception pattern, call mode, record mould in mobile terminal 1 00 When under the isotypes such as formula, speech recognition mode, broadcast reception mode, it is that radio frequency unit 101 or WiFi module 102 are received or The voice data stored in memory 109 is converted into audio signal and is output as sound.Moreover, audio output unit 103 The audio output related to the specific function that mobile terminal 1 00 is performed can also be provided (for example, call signal receives sound, disappeared Breath receives sound etc.).Audio output unit 103 can include loudspeaker, buzzer etc..
A/V input blocks 104 are used to receive audio or video signal.A/V input blocks 104 can include graphics processor (Graphics Processing Unit, GPU) 1041 and microphone 1042,1041 pairs of graphics processor is in video acquisition mode Or the view data progress of the static images or video obtained in image capture mode by image capture apparatus (such as camera) Reason.Picture frame after processing may be displayed on display unit 106.Picture frame after being handled through graphics processor 1041 can be deposited Storage is transmitted in memory 109 (or other storage mediums) or via radio frequency unit 101 or WiFi module 102.Mike Wind 1042 can connect in telephone calling model, logging mode, speech recognition mode etc. operational mode via microphone 1042 Quiet down sound (voice data), and can be voice data by such acoustic processing.Audio (voice) data after processing can To be converted to the form output that mobile communication base station can be sent to via radio frequency unit 101 in the case of telephone calling model. Microphone 1042 can implement various types of noises and eliminate (or suppression) algorithm to eliminate (or suppression) in reception and send sound The noise produced during frequency signal or interference.
Mobile terminal 1 00 also includes at least one sensor 105, such as optical sensor, motion sensor and other biographies Sensor.Specifically, optical sensor includes ambient light sensor and proximity transducer, wherein, ambient light sensor can be according to environment The light and shade of light adjusts the brightness of display panel 1061, and proximity transducer can close when mobile terminal 1 00 is moved in one's ear Display panel 1061 and/or backlight.As one kind of motion sensor, accelerometer sensor can detect in all directions (general For three axles) size of acceleration, size and the direction of gravity are can detect that when static, the application available for identification mobile phone posture (such as horizontal/vertical screen switching, dependent game, magnetometer pose calibrating), Vibration identification correlation function (such as pedometer, percussion) etc.; The fingerprint sensor that can also configure as mobile phone, pressure sensor, iris sensor, molecule sensor, gyroscope, barometer, The other sensors such as hygrometer, thermometer, infrared ray sensor, will not be repeated here.
Display unit 106 is used for the information for showing the information inputted by user or being supplied to user.Display unit 106 can be wrapped Display panel 1061 is included, liquid crystal display (Liquid Crystal Display, LCD), Organic Light Emitting Diode can be used Forms such as (Organic Light-Emitting Diode, OLED) configures display panel 1061.
User input unit 107 can be used for the numeral or character information for receiving input, and produce the use with mobile terminal The key signals input that family is set and function control is relevant.Specifically, user input unit 107 may include contact panel 1071 with And other input equipments 1072.Contact panel 1071, also referred to as touch-screen, collect touch operation of the user on or near it (such as user is using any suitable objects such as finger, stylus or annex on contact panel 1071 or in contact panel 1071 Neighbouring operation), and corresponding attachment means are driven according to formula set in advance.Contact panel 1071 may include touch detection Two parts of device and touch controller.Wherein, touch detecting apparatus detects the touch orientation of user, and detects touch operation band The signal come, transmits a signal to touch controller;Touch controller receives touch information from touch detecting apparatus, and by it It is converted into contact coordinate, then gives processor 110, and the order sent of reception processing device 110 and can be performed.In addition, can To realize contact panel 1071 using polytypes such as resistance-type, condenser type, infrared ray and surface acoustic waves.Except contact panel 1071, user input unit 107 can also include other input equipments 1072.Specifically, other input equipments 1072 can be wrapped Include but be not limited to physical keyboard, in function key (such as volume control button, switch key etc.), trace ball, mouse, action bars etc. One or more, do not limit herein specifically.
Further, contact panel 1071 can cover display panel 1061, detect thereon when contact panel 1071 or After neighbouring touch operation, processor 110 is sent to determine the type of touch event, with preprocessor 110 according to touch thing The type of part provides corresponding visual output on display panel 1061.Although in Fig. 1, contact panel 1071 and display panel 1061 be input and the output function that mobile terminal is realized as two independent parts, but in certain embodiments, can By contact panel 1071 and the input that is integrated and realizing mobile terminal of display panel 1061 and output function, not do specifically herein Limit.
Interface unit 108 is connected the interface that can pass through as at least one external device (ED) with mobile terminal 1 00.For example, External device (ED) can include wired or wireless head-band earphone port, external power source (or battery charger) port, wired or nothing Line FPDP, memory card port, the port for connecting the device with identification module, audio input/output (I/O) end Mouth, video i/o port, ear port etc..Interface unit 108 can be used for receiving the input from external device (ED) (for example, number It is believed that breath, electric power etc.) and the input received is transferred to one or more elements in mobile terminal 1 00 or can be with For transmitting data between mobile terminal 1 00 and external device (ED).
Memory 109 can be used for storage software program and various data.Memory 109 can mainly include storing program area And storage data field, wherein, application program (the such as sound that storing program area can be needed for storage program area, at least one function Sound playing function, image player function etc.) etc.;Storage data field can be stored uses created data (such as according to mobile phone Voice data, phone directory etc.) etc..In addition, memory 109 can include high-speed random access memory, it can also include non-easy The property lost memory, for example, at least one disk memory, flush memory device or other volatile solid-state parts.
Processor 110 is the control centre of mobile terminal, utilizes each of various interfaces and the whole mobile terminal of connection Individual part, by operation or performs and is stored in software program and/or module in memory 109, and calls and be stored in storage Data in device 109, perform the various functions and processing data of mobile terminal, so as to carry out integral monitoring to mobile terminal.Place Reason device 110 may include one or more processing units;It is preferred that, processor 110 can integrated application processor and modulatedemodulate mediate Device is managed, wherein, application processor mainly handles operating system, user interface and application program etc., and modem processor is main Handle radio communication.It is understood that above-mentioned modem processor can not also be integrated into processor 110.
Mobile terminal 1 00 can also include the power supply 111 (such as battery) powered to all parts, it is preferred that power supply 111 Can be logically contiguous by power-supply management system and processor 110, so as to realize management charging by power-supply management system, put The function such as electricity and power managed.
Although Fig. 1 is not shown, mobile terminal 1 00 can also will not be repeated here including bluetooth module etc..
For the ease of understanding the embodiment of the present invention, the communications network system that the mobile terminal of the present invention is based on is entered below Row description.
Referring to Fig. 2, Fig. 2 is a kind of communications network system Organization Chart provided in an embodiment of the present invention, the communication network system Unite as the LTE system of universal mobile communications technology, UE (User Equipment, use of the LTE system including communicating connection successively Family equipment) 201, E-UTRAN (Evolved UMTS Terrestrial Radio Access Network, evolved UMTS lands Ground wireless access network) 202, EPC (Evolved Packet Core, evolved packet-based core networks) 203 and operator IP operation 204。
Specifically, UE201 can be above-mentioned terminal 100, and here is omitted.
E-UTRAN202 includes eNodeB2021 and other eNodeB2022 etc..Wherein, eNodeB2021 can be by returning Journey (backhaul) (such as X2 interface) is connected with other eNodeB2022, and eNodeB2021 is connected to EPC203, ENodeB2021 can provide UE201 to EPC203 access.
EPC203 can include MME (Mobility Management Entity, mobility management entity) 2031, HSS (Home Subscriber Server, home subscriber server) 2032, other MME2033, SGW (Serving Gate Way, Gateway) 2034, PGW (PDN Gate Way, grouped data network gateway) 2035 and PCRF (Policy and Charging Rules Function, policy and rate functional entity) 2036 etc..Wherein, MME2031 be processing UE201 and There is provided carrying and connection management for the control node of signaling between EPC203.HSS2032 is all to manage for providing some registers Such as function of attaching position register (not shown) etc, and some are preserved about the use such as service features, data rate The special information in family.All customer data can be transmitted by SGW2034, and PGW2035 can provide UE 201 IP Address is distributed and other functions, and PCRF2036 is strategy and the charging control strategic decision-making of business data flow and IP bearing resources Point, it selects and provided available strategy and charging control decision-making with charge execution function unit (not shown) for strategy.
IP operation 204 can include internet, Intranet, IMS (IP Multimedia Subsystem, IP multimedia System) or other IP operations etc..
Although above-mentioned be described by taking LTE system as an example, those skilled in the art it is to be understood that the present invention not only Suitable for LTE system, be readily applicable to other wireless communication systems, such as GSM, CDMA2000, WCDMA, TD-SCDMA with And following new network system etc., do not limit herein.
Based on above-mentioned mobile terminal hardware configuration and communications network system, each embodiment of the inventive method is proposed.
First embodiment
As shown in figure 3, first embodiment of the invention provides a kind of Multi-thread synchronization processing method, methods described includes step Suddenly:
31st, a thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in obstruction shape State;The priority for wherein getting synchrolock and accessing the thread of shared resource is P1.
It should be noted that it is any one line in multiple threads to get synchrolock and access the thread of shared resource Journey.The priority of thread can be configured or change in advance, by taking JAVA as an example, can obtain current by getPriority () The priority of thread, can change the priority of thread by setPriority ().
In the present embodiment, get synchrolock and access shared resource can be by following for a thread in multiple threads Step realizes (accompanying drawing is not shown):
Receive the shared resource access request that a thread in the multiple thread is sent;
According to the shared resource access request, the shared resource is supplied to a line in the multiple thread Journey.
As illustratively, shared resource access request may include the mark of thread and ask the resource name of shared resource, According to the mark of thread and the resource name for asking shared resource, shared resource is supplied to a line in the multiple thread Journey;Or shared resource access request may include shared resource parameter and weight parameter, according to shared resource parameter, by shared money Source is supplied to the maximum thread of weighted value.
Further, the shared resource is supplied to the multiple according to the shared resource access request in step Step is may also include before a thread in thread:
Judge whether the lock of the shared resource has been released;
If the lock of the shared resource has been released, step is performed according to the shared resource access request, will be described Shared resource is supplied to a thread in the multiple thread.
32nd, the limit priority Pmax of the thread of all blocked states is calculated.
If the 33, the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than all resistances calculated The limit priority Pmax of the thread of plug-like state, then by the priority of the thread for getting synchrolock and accessing shared resource It is set to Pmax.
34th, the thread for getting synchrolock and accessing shared resource discharges synchrolock simultaneously after management and running are complete Recovery priority is P1.
In the present embodiment, the management and running for getting synchrolock and accessing the thread of shared resource are real by following steps Existing (accompanying drawing is not shown):
Synchrolock is got described in receiving and accesses the dispatch request of the thread of resource;
Whether the priority for getting synchrolock described in judging and accessing the thread of resource meets preparatory condition;
In the present embodiment, get synchrolock and access the thread of resource priority whether meet preparatory condition can be with Including but not limited to scenario described below:Whether the priority for getting synchrolock and accessing the thread of resource is preferential in all threads Level highest thread;Whether the priority for getting synchrolock and accessing the thread of resource is more than a certain priority.
If the priority for getting synchrolock and accessing the thread of resource meets preparatory condition, the acquisition is run To synchrolock and access the thread of resource.
It refer again to shown in Fig. 4, in another embodiment, methods described also includes step:
35th, other threads in blocked state are waken up, and continue executing with the acquisition of a thread in the multiple threads of step To synchrolock and shared resource is accessed, other threads are in blocked state.Continue executing with step 31.
For a better understanding of the present invention, it refer to shown in Fig. 6:
Include n thread, i.e. thread 1, thread 2, thread 3 ... thread n in Fig. 6, thread 1, thread 2 ... thread n it is excellent First level is respectively P1, P2, P3 ... Pn.
Assuming that thread priority gets synchronization object for P1 thread 1, that is, get synchrolock and access shared resource, Then (thread 2, thread 3 ... thread n) are in blocked state to other threads.
At this moment, the limit priority Pmax of the thread of all blocked states can be calculated, wherein Pmax is max (P2, P3 ... Pn)。
If the priority P 1 of thread 1 is less than the limit priority Pmax of the thread of all blocked states calculated, The priority of thread 1 can be set to or be revised as Pmax.By the way that the priority of thread 1 to be set to or be revised as Pmax, can prevent thread 1 from cannot get management and running because priority is relatively low, so as to take synchronization object overlong time, cause Other thread block overlong times.
Thread 1 discharges synchrolock and recovers priority for P1 after management and running are complete.
A kind of Multi-thread synchronization processing method provided in an embodiment of the present invention, the thread of shared resource is accessed by judgement Whether priority is less than the limit priority Pmax of the thread of all blocked states, if the thread that shared resource will be accessed less than if Priority be set to Pmax, the thread for accessing shared resource recovers priority after management and running are complete;Prevent thread excellent The relatively low thread of first level when accessing resource, because thread priority is relatively low, the chance that obtains management and running it is smaller so that the line The overlong time of Cheng Zhanyong synchrolocks, cause the higher wait synchrolock of other thread priorities thread can not be able to always after Continuous to perform, final caused blocking time is long, or even the phenomenon of interim card, application program without response.
Second embodiment
Reference picture 5, Fig. 5 provides a kind of terminal for second embodiment of the invention, and the terminal 40 includes:Memory 41, place Manage device 42 and be stored in the Multi-thread synchronization processing routine that can be run on the memory 41 and on the processor 42, it is described Multi-thread synchronization processing routine realizes following steps when being performed by the processor 42:
A thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in blocked state; The priority for wherein getting synchrolock and accessing the thread of shared resource is P1;
It should be noted that it is any one line in multiple threads to get synchrolock and access the thread of shared resource Journey.The priority of thread can be configured or change in advance, by taking JAVA as an example, can obtain current by getPriority () The priority of thread, can change the priority of thread by setPriority ().
In the present embodiment, realization is additionally operable to when the Multi-thread synchronization processing routine is performed by the processor 42 following Step:
Receive the shared resource access request that a thread in the multiple thread is sent;
According to the shared resource access request, the shared resource is supplied to a line in the multiple thread Journey.
As illustratively, shared resource access request may include the mark of thread and ask the resource name of shared resource, According to the mark of thread and the resource name for asking shared resource, shared resource is supplied to a line in the multiple thread Journey;Or shared resource access request may include shared resource parameter and weight parameter, according to shared resource parameter, by shared money Source is supplied to the maximum thread of weighted value.
Further, it is additionally operable to realize following step when the Multi-thread synchronization processing routine is performed by the processor 42 Suddenly:
Judge whether the lock of the shared resource has been released;
If the lock of the shared resource has been released, step is performed according to the shared resource access request, will be described Shared resource is supplied to a thread in the multiple thread.
Calculate the limit priority Pmax of the thread of all blocked states;
If the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than all obstructions calculated The limit priority Pmax of the thread of state, then set the priority of the thread for getting synchrolock and accessing shared resource It is set to Pmax;
The thread for getting synchrolock and accessing shared resource discharges synchrolock and recovered after management and running are complete Priority is P1.
In the present embodiment, realization is additionally operable to when the Multi-thread synchronization processing routine is performed by the processor 42 following Step:
Synchrolock is got described in receiving and accesses the dispatch request of the thread of resource;
Whether the priority for getting synchrolock described in judging and accessing the thread of resource meets preparatory condition;
In the present embodiment, get synchrolock and access the thread of resource priority whether meet preparatory condition can be with Including but not limited to scenario described below:Whether the priority for getting synchrolock and accessing the thread of resource is preferential in all threads Level highest thread;Whether the priority for getting synchrolock and accessing the thread of resource is more than a certain priority.
If the priority for getting synchrolock and accessing the thread of resource meets preparatory condition, the acquisition is run To synchrolock and access the thread of resource.
In another embodiment, reality is additionally operable to when the Multi-thread synchronization processing routine is performed by the processor 42 Existing following steps:
Other threads in blocked state are waken up, and continue executing with a thread in the multiple threads of step and are got together Step is locked and accesses shared resource, and other threads are in blocked state.
For a better understanding of the present invention, it refer to shown in Fig. 6:
Include n thread, i.e. thread 1, thread 2, thread 3 ... thread n in Fig. 6, thread 1, thread 2 ... thread n it is excellent First level is respectively P1, P2, P3 ... Pn.
Assuming that thread priority gets synchronization object for P1 thread 1, that is, get synchrolock and access shared resource, Then (thread 2, thread 3 ... thread n) are in blocked state to other threads.
At this moment, the limit priority Pmax of the thread of all blocked states can be calculated, wherein Pmax is max (P2, P3 ... Pn)。
If the priority P 1 of thread 1 is less than the limit priority Pmax of the thread of all blocked states calculated, The priority of thread 1 can be set to or be revised as Pmax.By the way that the priority of thread 1 to be set to or be revised as Pmax, can prevent thread 1 from cannot get management and running because priority is relatively low, so as to take synchronization object overlong time, cause Other thread block overlong times.
Thread 1 discharges synchrolock and recovers priority for P1 after management and running are complete.
Terminal provided in an embodiment of the present invention, by judging it is all whether the priority of thread of access shared resource is less than The limit priority Pmax of the thread of blocked state, the priority if the thread that shared resource will be accessed less than if is set to Pmax, the thread for accessing shared resource recovers priority after management and running are complete;Prevent the thread that thread priority is relatively low When accessing resource, because thread priority is relatively low, the chance that obtains management and running it is smaller so that the thread takes synchrolock Overlong time, causing the thread of the higher wait synchrolock of other thread priorities can not be continued executing with always, finally be drawn The blocking time risen is long, or even the phenomenon of interim card, application program without response.
3rd embodiment
Third embodiment of the invention is provided deposits on a kind of computer-readable recording medium, the computer-readable recording medium Multi-thread synchronization processing routine is contained, the Multi-thread synchronization processing routine is realized described in first embodiment when being executed by processor Multi-thread synchronization processing method the step of.
As illustratively, it refer to shown in Fig. 6:
Include n thread, i.e. thread 1, thread 2, thread 3 ... thread n in Fig. 6, thread 1, thread 2 ... thread n it is excellent First level is respectively P1, P2, P3 ... Pn.
Assuming that thread priority gets synchronization object for P1 thread 1, that is, get synchrolock and access shared resource, Then (thread 2, thread 3 ... thread n) are in blocked state to other threads.
At this moment, the limit priority Pmax of the thread of all blocked states can be calculated, wherein Pmax is max (P2, P3 ... Pn)。
If the priority P 1 of thread 1 is less than the limit priority Pmax of the thread of all blocked states calculated, The priority of thread 1 can be set to or be revised as Pmax.By the way that the priority of thread 1 to be set to or be revised as Pmax, can prevent thread 1 from cannot get management and running because priority is relatively low, so as to take synchronization object overlong time, cause Other thread block overlong times.
Thread 1 discharges synchrolock and recovers priority for P1 after management and running are complete.
Computer-readable recording medium provided in an embodiment of the present invention, by judge access shared resource thread it is preferential Whether level is less than the limit priority Pmax of the thread of all blocked states, if the excellent of the thread that shared resource will be accessed less than if First level is set to Pmax, and the thread for accessing shared resource recovers priority after management and running are complete;Prevent thread priority Relatively low thread when accessing resource, because thread priority is relatively low, the chance that obtains management and running it is smaller so that the thread is accounted for With the overlong time of synchrolock, causing the thread of the higher wait synchrolock of other thread priorities can not be able to continue to hold always OK, final caused blocking time is long, or even the phenomenon of interim card, application program without response.
It should be noted that herein, term " comprising ", "comprising" or its any other variant are intended to non-row His property is included, so that process, method, article or device including a series of key elements not only include those key elements, and And also including other key elements being not expressly set out, or also include for this process, method, article or device institute inherently Key element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that including this Also there is other identical element in process, method, article or the device of key element.
The embodiments of the present invention are for illustration only, and the quality of embodiment is not represented.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment side Method can add the mode of required general hardware platform to realize by software, naturally it is also possible to by hardware, but in many cases The former is more preferably embodiment.Understood based on such, technical scheme is substantially done to prior art in other words Going out the part of contribution can be embodied in the form of software product, and the computer software product is stored in a storage medium In (such as ROM/RAM, magnetic disc, CD), including some instructions are to cause a station terminal (can be mobile phone, computer, service Device, air conditioner, or network equipment etc.) perform method described in each of the invention embodiment.
Embodiments of the invention are described above in conjunction with accompanying drawing, but the invention is not limited in above-mentioned specific Embodiment, above-mentioned embodiment is only schematical, rather than restricted, one of ordinary skill in the art Under the enlightenment of the present invention, in the case of present inventive concept and scope of the claimed protection is not departed from, it can also make a lot Form, these are belonged within the protection of the present invention.

Claims (10)

1. a kind of Multi-thread synchronization processing method, methods described includes step:
A thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in blocked state;Wherein The priority for getting synchrolock and accessing the thread of shared resource is P1;
Calculate the limit priority Pmax of the thread of all blocked states;
If the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than all blocked states calculated Thread limit priority Pmax, then the priority of the thread for getting synchrolock and accessing shared resource is set to Pmax;
The thread for getting synchrolock and accessing shared resource discharges synchrolock and recovers preferential after management and running are complete Level is P1.
2. a kind of Multi-thread synchronization processing method according to claim 1, it is characterised in that in the multiple threads of step A thread get synchrolock and access shared resource and realized by following steps:
Receive the shared resource access request that a thread in the multiple thread is sent;
According to the shared resource access request, the shared resource is supplied to a thread in the multiple thread.
3. a kind of Multi-thread synchronization processing method according to claim 2, it is characterised in that the step is according to described common Resource access request is enjoyed, step is also included before the thread that the shared resource is supplied in the multiple thread:
Judge whether the lock of the shared resource has been released;
If the lock of the shared resource has been released, step is performed according to the shared resource access request, will be described shared Resource is supplied to a thread in the multiple thread.
4. a kind of Multi-thread synchronization processing method according to claim 1, it is characterised in that described to get synchrolock simultaneously The management and running for accessing the thread of shared resource are realized by following steps:
Synchrolock is got described in receiving and accesses the dispatch request of the thread of resource;
Whether the priority for getting synchrolock described in judging and accessing the thread of resource meets preparatory condition;
If the priority for getting synchrolock and accessing the thread of resource meets preparatory condition, operation is described to be got together Step is locked and accesses the thread of resource.
5. a kind of Multi-thread synchronization processing method according to claim 1, it is characterised in that methods described also includes step Suddenly:
Other threads in blocked state are waken up, and continue executing with a thread in the multiple threads of step and get synchrolock And shared resource is accessed, other threads are in blocked state.
6. a kind of terminal, it is characterised in that the terminal includes:Memory, processor and it is stored on the memory and can The Multi-thread synchronization processing routine run on the processor, the Multi-thread synchronization processing routine is by the computing device Shi Shixian following steps:
A thread in multiple threads gets synchrolock and accesses shared resource, and other threads are in blocked state;Wherein The priority for getting synchrolock and accessing the thread of shared resource is P1;
Calculate the limit priority Pmax of the thread of all blocked states;
If the priority P 1 for getting synchrolock and accessing the thread of shared resource is less than all blocked states calculated Thread limit priority Pmax, then the priority of the thread for getting synchrolock and accessing shared resource is set to Pmax;
The thread for getting synchrolock and accessing shared resource discharges synchrolock and recovers preferential after management and running are complete Level is P1.
7. a kind of terminal according to claim 6, it is characterised in that the Multi-thread synchronization processing routine is by the processing Device is additionally operable to realize following steps when performing:
Receive the shared resource access request that a thread in the multiple thread is sent;
According to the shared resource access request, the shared resource is supplied to a thread in the multiple thread.
8. a kind of terminal according to claim 7, it is characterised in that the Multi-thread synchronization processing routine is by the processing Device is additionally operable to realize following steps when performing:
Judge whether the lock of the shared resource has been released;
If the lock of the shared resource has been released, step is performed according to the shared resource access request, will be described shared Resource is supplied to a thread in the multiple thread.
9. a kind of terminal according to claim 6, it is characterised in that the Multi-thread synchronization processing routine is by the processing Device is additionally operable to realize following steps when performing:
Synchrolock is got described in receiving and accesses the dispatch request of the thread of resource;
Whether the priority for getting synchrolock described in judging and accessing the thread of resource meets preparatory condition;
If the priority for getting synchrolock and accessing the thread of resource meets preparatory condition, operation is described to be got together Step is locked and accesses the thread of resource;
It is additionally operable to realize following steps when the Multi-thread synchronization processing routine is by the computing device:Wake up in obstruction shape Other threads of state, and continue executing with a thread in the multiple threads of step and get synchrolock and access shared resource, its He is in blocked state by thread.
10. a kind of computer-readable recording medium, it is characterised in that be stored with multithreading on the computer-readable recording medium Synchronization process program, is realized such as any one of claim 1 to 5 institute when the Multi-thread synchronization processing routine is executed by processor The step of Multi-thread synchronization processing method stated.
CN201710374533.XA 2017-05-24 2017-05-24 Multi-thread synchronization processing method, terminal and computer-readable recording medium Pending CN107133092A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710374533.XA CN107133092A (en) 2017-05-24 2017-05-24 Multi-thread synchronization processing method, terminal and computer-readable recording medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710374533.XA CN107133092A (en) 2017-05-24 2017-05-24 Multi-thread synchronization processing method, terminal and computer-readable recording medium

Publications (1)

Publication Number Publication Date
CN107133092A true CN107133092A (en) 2017-09-05

Family

ID=59731933

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710374533.XA Pending CN107133092A (en) 2017-05-24 2017-05-24 Multi-thread synchronization processing method, terminal and computer-readable recording medium

Country Status (1)

Country Link
CN (1) CN107133092A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107783858A (en) * 2017-10-31 2018-03-09 努比亚技术有限公司 Terminal freezes solution method, terminal and the computer-readable recording medium of screen
CN107861817A (en) * 2017-11-30 2018-03-30 努比亚技术有限公司 Memory Optimize Method, mobile terminal and readable storage medium storing program for executing based on thread block
CN108052390A (en) * 2017-11-30 2018-05-18 努比亚技术有限公司 Memory method for cleaning, mobile terminal and readable storage medium storing program for executing based on thread block
CN108809363A (en) * 2018-08-27 2018-11-13 优视科技新加坡有限公司 Near-field Data transmission method and its device
CN109918141A (en) * 2019-03-15 2019-06-21 Oppo广东移动通信有限公司 Thread execution method, device, terminal and storage medium
CN110611746A (en) * 2019-09-03 2019-12-24 苏宁云计算有限公司 Multi-camera synchronization method and distributed system
CN107861817B (en) * 2017-11-30 2021-11-16 努比亚技术有限公司 Thread blocking-based memory optimization method, mobile terminal and readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040216112A1 (en) * 2003-04-23 2004-10-28 International Business Machines Corporation System and method for thread prioritization during lock processing
CN1615472A (en) * 2002-01-24 2005-05-11 皇家飞利浦电子股份有限公司 Executing processes in a multiprocessing environment
CN101216785A (en) * 2007-01-05 2008-07-09 三星电子株式会社 Multi-tasking method according to simple priority inheritance scheme and embedded system therefor
CN105893120A (en) * 2016-04-21 2016-08-24 北京京东尚科信息技术有限公司 Acquisition method and device for thread synchronization resources

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1615472A (en) * 2002-01-24 2005-05-11 皇家飞利浦电子股份有限公司 Executing processes in a multiprocessing environment
US20040216112A1 (en) * 2003-04-23 2004-10-28 International Business Machines Corporation System and method for thread prioritization during lock processing
CN101216785A (en) * 2007-01-05 2008-07-09 三星电子株式会社 Multi-tasking method according to simple priority inheritance scheme and embedded system therefor
CN105893120A (en) * 2016-04-21 2016-08-24 北京京东尚科信息技术有限公司 Acquisition method and device for thread synchronization resources

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
FZZJOY: "操作系统_优先级反转、优先级继承", 《HTTPS://BLOG.CSDN.NET/U010275850/ARTICLE/DETAILS/49103245》 *
PHILIAI: "线程调度的问题:Lock Convoy(锁封护)与Priority Inversion(优先级反转)", 《HTTPS://WWW.CNBLOGS.COM/PHILIP-TELL-TRUTH/P/6444267.HTML》 *
郭长国 等: "一个基于多线程的优先级继承协议锁的算法研究", 《计算机研究与发展》 *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107783858A (en) * 2017-10-31 2018-03-09 努比亚技术有限公司 Terminal freezes solution method, terminal and the computer-readable recording medium of screen
CN107861817A (en) * 2017-11-30 2018-03-30 努比亚技术有限公司 Memory Optimize Method, mobile terminal and readable storage medium storing program for executing based on thread block
CN108052390A (en) * 2017-11-30 2018-05-18 努比亚技术有限公司 Memory method for cleaning, mobile terminal and readable storage medium storing program for executing based on thread block
CN108052390B (en) * 2017-11-30 2021-11-16 努比亚技术有限公司 Thread blocking-based memory cleaning method, mobile terminal and readable storage medium
CN107861817B (en) * 2017-11-30 2021-11-16 努比亚技术有限公司 Thread blocking-based memory optimization method, mobile terminal and readable storage medium
WO2020044091A1 (en) * 2018-08-27 2020-03-05 优视科技新加坡有限公司 Near field data transmission method and apparatus thereof
CN108809363A (en) * 2018-08-27 2018-11-13 优视科技新加坡有限公司 Near-field Data transmission method and its device
CN109918141A (en) * 2019-03-15 2019-06-21 Oppo广东移动通信有限公司 Thread execution method, device, terminal and storage medium
CN110611746A (en) * 2019-09-03 2019-12-24 苏宁云计算有限公司 Multi-camera synchronization method and distributed system
CN110611746B (en) * 2019-09-03 2021-06-29 深圳市云网万店电子商务有限公司 Multi-camera synchronization method and distributed system

Similar Documents

Publication Publication Date Title
CN108052302A (en) Association display methods, terminal and the computer readable storage medium of double-sided screen
CN107219974A (en) A kind of method, mobile terminal and storage medium for showing application software
CN107566635A (en) Screen intensity method to set up, mobile terminal and computer-readable recording medium
CN107133092A (en) Multi-thread synchronization processing method, terminal and computer-readable recording medium
CN106961706A (en) Method, mobile terminal and the computer-readable recording medium of communication pattern switching
CN107517494A (en) A kind of display methods of terminal battery electricity quantity, terminal and computer-readable recording medium
CN107436779A (en) A kind of application management method, equipment and computer-readable recording medium
CN107343083A (en) One kind lifting game experiencing method, apparatus and computer-readable recording medium
CN107181700A (en) Control method, mobile terminal and the storage medium of application program for mobile terminal
CN107145385A (en) A kind of multitask interface display methods, mobile terminal and computer-readable storage medium
CN107181865A (en) Processing method, terminal and the computer-readable recording medium of unread short messages
CN106953989A (en) Incoming call reminding method and device, terminal, computer-readable recording medium
CN107193779A (en) Residue charging duration calculation method, terminal and computer-readable recording medium
CN107390856A (en) A kind of method, mobile terminal and storage medium for reducing mobile terminal power consumption
CN108172161A (en) Display methods, mobile terminal and computer readable storage medium based on flexible screen
CN108156325A (en) A kind of double-sided screen Incoming-call control method, equipment and computer readable storage medium
CN107247606A (en) Application management method, device and computer-readable recording medium
CN107423065A (en) Method, mobile terminal and the computer-readable recording medium that a kind of application is attended to anything else
CN107807857A (en) Method, equipment and the computer for clearing up running memory can storage mediums
CN107562343A (en) A kind of interactive regulation and control method, equipment and computer-readable recording medium
CN107450796A (en) A kind of image processing method, mobile terminal and computer-readable recording medium
CN107124466A (en) One kind prevents caching penetrating method and device, computer-readable recording medium
CN107172605A (en) A kind of Emmergency call method, mobile terminal and computer-readable recording medium
CN107566607A (en) One kind notice display methods, mobile terminal and computer-readable recording medium
CN108038834A (en) A kind of method, terminal and computer-readable recording medium for reducing noise

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20170905

RJ01 Rejection of invention patent application after publication