CN105824709B - A kind of critical zone access method and device - Google Patents

A kind of critical zone access method and device Download PDF

Info

Publication number
CN105824709B
CN105824709B CN201610140580.3A CN201610140580A CN105824709B CN 105824709 B CN105824709 B CN 105824709B CN 201610140580 A CN201610140580 A CN 201610140580A CN 105824709 B CN105824709 B CN 105824709B
Authority
CN
China
Prior art keywords
cpu
mutual exclusion
exclusion lock
lock
critical zone
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.)
Active
Application number
CN201610140580.3A
Other languages
Chinese (zh)
Other versions
CN105824709A (en
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.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua 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 Zhejiang Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN201610140580.3A priority Critical patent/CN105824709B/en
Publication of CN105824709A publication Critical patent/CN105824709A/en
Application granted granted Critical
Publication of CN105824709B publication Critical patent/CN105824709B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The invention discloses a kind of critical zone access method and devices, and in the present solution, increasing CPU id information in the information area of mutual exclusion lock, which indicates that operating on the corresponding CPU of CPU ID for task has locked mutual exclusion lock.When task accesses critical zone, whether the mutual exclusion lock of detection critical zone first is in the lock state;If so, reading the central processor CPU stored in the information area of mutual exclusion lock identifies ID;If the CPU ID read is identical as the CPU ID of CPU where itself, enter dormant state.In this way, the task in same CPU can be made to be directly entered dormant state, it is not necessary to be polled, thus due to the number for reducing poll, to achieve the purpose that save process resource.

Description

A kind of critical zone access method and device
Technical field
The present invention relates to critical zone access technique field more particularly to a kind of critical zone access method and devices.
Background technique
Critical zone can not be accessed by multiple tasks (task refers to a thread or process) simultaneously.Face when there is task to access When battery limit (BL), other tasks are had to wait for, to ensure that the critical zone same time is only accessed by a task, to critical zone between task Access mutual exclusion.
The prior art realizes the critical zone same time only by a task with the method by the way that mutual exclusion lock is arranged for critical zone Access.Specifically, any task A is directed to, when task A accesses critical zone, it is necessary to which locking mutual exclusion lock first (obtains critical The access authority in area);If another task B is also required to access critical zone, and when mutual exclusion lock is locked by other tasks, the task B due to not knowing when task A can discharge mutual exclusion lock, then need ceaselessly poll in order to know mutual exclusion lock whether by Then release obtains the permission for accessing critical zone by the mutual exclusion lock that task A discharges by locking.If the number of task B poll Certain number is reached, then will enter dormant state.
In the prior art due to when mutual exclusion lock is locked by other tasks, needing continuous poll competition to obtain mutual exclusion lock, Cause the waste of process resource.
Summary of the invention
The embodiment of the invention provides a kind of critical zone access method and device, to solve presently, there are due to continuous Poll mutual exclusion lock, the problem of causing process resource to waste.
The embodiment of the invention provides a kind of critical zone access methods, comprising:
When accessing critical zone, whether the mutual exclusion lock for detecting critical zone is in the lock state;
If so, reading CPU (Central Processing Unit, the central processing stored in the information area of mutual exclusion lock Device) ID (Identity, mark);The CPU ID indicates that operating on the corresponding CPU of CPU ID for task has locked mutual exclusion lock;
If the CPU ID read is identical as the CPU ID of CPU where itself, enter dormant state.
Further, the method also includes:
If detecting, the mutual exclusion lock of critical zone is to lock mutual exclusion lock in unlocked state;And
The CPU ID of CPU where CPU ID in the information area of mutual exclusion lock is changed to itself;And
It accesses to critical zone.
Further, it is described access to critical zone after, the method also includes:
Before discharging mutual exclusion lock, the CPU ID in the information area of mutual exclusion lock is changed to prepending non-significant value, the prepending non-significant Value is for indicating that mutual exclusion lock is not locked by the task on any CPU;
If the CPU ID of the reading is identical as the CPU ID of CPU where itself, enter before dormant state, the side Method further include:
Determine that the CPU ID read is not prepending non-significant value.
Further, the method also includes:
If the CPU ID read is prepending non-significant value, continue to read the CPU ID stored in the information area of mutual exclusion lock;
If the CPU ID that continuous first preset times are read is prepending non-significant value, enter dormant state.
Further, the method also includes:
If the CPU ID read is not identical as the CPU ID of itself, the wrap count of record is added one;
Judge whether wrap count is greater than or equal to the second preset times;
If wrap count is greater than or equal to the second preset times, enter dormant state;
If wrap count less than the second preset times, returns and executes whether the mutual exclusion lock for detecting critical zone is in locked The step of state.
The present invention also provides a kind of critical zone access mechanisms, comprising:
Lock state detection module, when for accessing critical zone, whether the mutual exclusion lock for detecting critical zone is in the lock state;
CPU ID read module reads storage in the information area of mutual exclusion lock if being in the lock state for mutual exclusion lock CPU ID;The CPU ID indicates that operating on the corresponding CPU of CPU ID for task has locked mutual exclusion lock;
First sleep block enters suspend mode shape if the CPU ID for reading is identical as the CPU ID of CPU where itself State.
Further, described device further include:
Locking module, if the mutual exclusion lock for detecting critical zone is to lock mutual exclusion lock in unlocked state;
First CPU ID modified module, CPU where being changed to itself for the CPU ID in the information area by mutual exclusion lock CPU ID;
Access modules, for accessing to critical zone.
Further, described device further include:
2nd CPU ID modified module, after accessing for the access modules to critical zone, release mutual exclusion lock it Before, the CPU ID in the information area of mutual exclusion lock is changed to prepending non-significant value, the prepending non-significant value for indicate mutual exclusion lock not by Task locking on any CPU;
Prepending non-significant value determining module, if CPU ID and CPU where itself for first sleep block reading CPU ID is identical, then enters before dormant state, determines that the CPU ID read is not prepending non-significant value.
Further, described device further include:
Continue read module, if the CPU ID for reading is prepending non-significant value, continues the information area for reading mutual exclusion lock The CPU ID of interior storage;
Second sleep block enters if the CPU ID for continuous first preset times to be read is prepending non-significant value Dormant state.
Further, described device further include:
The wrap count of record is added one if the CPU ID for reading is not identical as the CPU ID of itself by logging modle;
Judgment module, for judging whether wrap count is greater than or equal to the second preset times;
Third sleep block enters dormant state if being greater than or equal to the second preset times for wrap count;
Return module, if triggering the detection of lock state detection module less than the second preset times for wrap count and facing Whether the mutual exclusion lock of battery limit (BL) is in locked state.
The present invention has the beneficial effect that: in the technical solution described in the embodiment of the present invention, increasing in the information area of mutual exclusion lock Add CPU id information, which indicates that operating on the corresponding CPU of CPU ID for task has locked mutual exclusion lock.Task access When critical zone, whether the mutual exclusion lock of detection critical zone first is in the lock state;If so, reading the information area memory of mutual exclusion lock The central processor CPU of storage identifies ID;If the CPU ID read is identical as the CPU ID of CPU where itself, enter suspend mode shape State.In this way, the task in same CPU can be made to be directly entered dormant state, it is not necessary to be polled, thus due to reducing poll Number, thus achieve the purpose that save process resource.
Detailed description of the invention
To describe the technical solutions in the embodiments of the present invention more clearly, make required in being described below to embodiment Attached drawing is briefly introduced, it should be apparent that, drawings in the following description are only some embodiments of the invention, for this For the those of ordinary skill in field, without creative efforts, it can also be obtained according to these attached drawings other Attached drawing.
Fig. 1 show the flow diagram of critical zone access method described in the embodiment of the present invention one;
Fig. 2 show the flow diagram of critical zone access method described in the embodiment of the present invention two;
Fig. 3 show the structural schematic diagram of critical zone access mechanism described in the embodiment of the present invention three.
Specific embodiment
Inventor has found that same CPU only has task (i.e. a thread or process) in the same time can under study for action With request mutual exclusion lock.So in same CPU, if having there is a task locking mutual exclusion lock, its in the CPU His task poll is attempted to obtain mutual exclusion lock to be nonsensical (because having had task to lock mutual exclusion lock in the CPU).So The embodiment of the invention provides a kind of critical zone access method and device, in the technical solution described in the embodiment of the present invention, mutual Denounce and increase CPU id information in the information area of lock, which indicates the locking of operating on the corresponding CPU of CPU ID for task Mutual exclusion lock.When task accesses critical zone, whether the mutual exclusion lock of detection critical zone first is in the lock state;If so, reading The central processor CPU stored in the information area of mutual exclusion lock identifies ID;If the CPU ID of the CPU ID read and CPU where itself It is identical, then enter dormant state.In this way, the task in same CPU can be made to be directly entered dormant state, it is not necessary to it is polled, Thus due to the number for reducing poll, to achieve the purpose that save process resource.
To make the objectives, technical solutions, and advantages of the present invention clearer, below in conjunction with attached drawing to the present invention make into It is described in detail to one step, it is clear that described embodiments are only a part of the embodiments of the present invention, rather than whole implementation Example.Based on the embodiments of the present invention, obtained by those of ordinary skill in the art without making creative efforts All other embodiment, shall fall within the protection scope of the present invention.
Embodiment one:
As shown in Figure 1, its flow diagram for critical zone access method in the embodiment of the present invention one, critical zone access Method can comprise the following steps that
Step 101: when access critical zone, whether the mutual exclusion lock for detecting critical zone is in the lock state.
Wherein, in one embodiment, the executing subject of the embodiment of the present invention can for any task (i.e. any process or Thread).
Wherein, in one embodiment, mutual exclusion lock can have lock state parameter, so, it can be by the following method Whether the mutual exclusion lock of detection critical zone is in the lock state, comprising:
Step A1: the lock state parameter value of mutual exclusion lock is read.
It is, for example, possible to use 1 expression mutual exclusion locks to be in the lock state, and use 0 indicates that mutual exclusion lock is in unlocked state.
Step A2: if the lock state parameter value read is the parameter value for indicating to be in the lock state, it is determined that mutual exclusion lock It is in the lock state;If the lock state parameter value read is the parameter value for indicating to be in unlocked state, it is determined that mutual exclusion lock In unlocked state.
It should be noted that lock whether can be in by the mutual exclusion lock that other methods in the prior art detect critical zone Determine state, this is not listed one by one in the embodiment of the present invention.
Step 102: if so, reading the CPU ID stored in the information area of mutual exclusion lock;CPU ID expression operates in this Task on the corresponding CPU of CPU ID has locked mutual exclusion lock.
Wherein, the CPU ID stored in the information area is the information area that mutual exclusion lock has been written by having locked the task of mutual exclusion lock.
Step 103: if the CPU ID read is identical as the CPU ID of CPU where itself, entering dormant state.
In this way, in the embodiment of the present invention, if the task of current request mutual exclusion lock is as the CPU ID and itself institute for determining reading The CPU ID of CPU identical (when i.e. same CPU has had other tasks locking mutual exclusion lock), then enter dormant state, no longer into Row poll, in this way, be just able to solve as poll and caused by process resource waste.
The embodiment of the present invention to be described in more detail below convenient for further understanding, including the following contents.
Wherein, in one embodiment, for further include convenient for critical zone can be accessed as soon as possible, in the embodiment of the present invention with Lower step:
Step A1: if detecting, the mutual exclusion lock of critical zone is to lock mutual exclusion lock in unlocked state.
Step A2: the CPU ID of CPU where the CPU ID in the information area of mutual exclusion lock is changed to itself.
Step A3: it accesses to critical zone.
In this way, after locking mutual exclusion lock, being changed to by the CPU ID in the information area by mutual exclusion lock in the embodiment of the present invention The CPU ID of CPU where itself, in order to which other tasks can decide to continue with wheel according to the CPU ID in the information area of mutual exclusion lock Ask or enter dormant state.
Wherein, in one embodiment, it might have some time intervals between execution step A1 and step A2 (to walk It after rapid A1 has been executed, can just have been executed after a period of time step A2).And in this time interval, it may be there are also other Be engaged in be polled to obtain access critical zone permission.And if in this time interval, the information area of mutual exclusion lock stores If CPU ID also have not enough time to modification (i.e. step A1 has been finished, and step A2 has had not carried out), then mutual exclusion lock The information area storage CPU ID may not be inconsistent with actual conditions, this will cause other tasks due to obtain mistake CPU ID and It causes to judge by accident.For example, task A is operated on CPU_0, task B is operated on CPU_0, and task C operates on CPU_1 (CPU_ 0 indicates different CPU from CPU_1).If task A locks mutual exclusion lock first, and the CPU ID of the information area is written as by competition CPU_0.After task A discharges mutual exclusion lock, task C locks mutual exclusion lock, if the CPU ID of the information area is not rewritten as also by task C When CPU_1, task B is polled and reads the CPU ID of the information area, then the result read can be CPU_0 (and actually information The CPU ID in area should be CPU_1), this CPU ID for just causing task B to read does not conform to the actual conditions, and is easy so that task B is caused It judges by accident and enters dormant state.
In the embodiment of the present invention, in order to avoid the CPU ID of reading does not conform to the actual conditions and cause to judge by accident, step can executed After rapid A3 (accessing to critical zone), before discharging mutual exclusion lock, the CPU ID in the information area of mutual exclusion lock is changed For prepending non-significant value, which is used to indicate that mutual exclusion lock not to be locked by the task on any CPU;Then mutual exclusion is discharged again Lock.In this way, can also determine that the CPU ID of reading is not prepending non-significant value in the real-time example of the present invention before executing step 103. In this way, can be made by prepending non-significant value to lock other tasks of mutual exclusion lock and can be learnt at mutual exclusion lock in poll In lock state, but which specific CPU ID is not known, can continue poll waiting, to determine whether itself enters suspend mode State.
Wherein, in one embodiment, the time interval between step A2 and step A3 is longer, then may be due to occurring Failure, at this time, often fault recovery needs the regular hour.And task poll mutual exclusion lock is a kind of processing during failure The waste of resource, so, in the embodiment of the present invention, in order to further save process resource, after executing step 102, if reading The CPU ID taken is prepending non-significant value, then continues to read the CPU ID stored in the information area of mutual exclusion lock;And if continuous first is pre- If the CPU ID that number is read is prepending non-significant value, then enter dormant state.If in this way, continuous first in the embodiment of the present invention The CPU ID that preset times are read is that prepending non-significant value is then considered as the failure for having occurred needing long time treatment reparation, and secondary Number enters dormant state, wastes to avoid process resource caused by poll during failure.
It wherein, in one embodiment,, can be with after executing step 102 for the ease of locking mutual exclusion lock as soon as possible The following steps are included:
Step B1: if the CPU ID read is not identical as the CPU ID of itself, the wrap count of record is added one.
Step B2: judge whether wrap count is greater than or equal to the second preset times.
Step B3: if wrap count is greater than or equal to the second preset times, enter dormant state;If wrap count is less than Second preset times then return and the step of whether mutual exclusion lock for detecting critical zone is in locked state are executed.
Wherein, in one embodiment enter dormant state task, enter dormant state before, can by itself Task ID is recorded in the suspend mode task record prestored, after waiting the wake up instruction for receiving operating system transmission, knot Beam suspend mode simultaneously executes step 101.When it is implemented, can be checked not by the task of locking mutual exclusion lock after discharging mutual exclusion lock Whether task in a dormant state is had in dormancy task record, if so, operating system is then notified to wake up times in a dormant state Business.
Wherein, suspend mode task record can be stored in one embodiment with document form, can also be with database form Storage, it is not limited in the embodiment of the present invention.
It wherein, in one embodiment can also include the preferential of each task in a dormant state in suspend mode task record Grade, then operating system can determine task of which waking up in a dormant state according to priority.Such as wake up highest priority Task so that the low task of priority keeps dormant state, and reduce the number that the low task of priority continues poll.
It should be noted that wake up which task can be determined according to the algorithm of other prior arts, the embodiment of the present invention It does not limit this.
Embodiment two
For ease of understanding, access critical zone is illustrated how to, it is assumed that when beginning, can be locked by operating system to mutual exclusion Mutual exclusion lock (is arranged in unlocked state, and sets default for the CPU ID of the information area of mutual exclusion lock by row initialization Invalid value).If task A has locked mutual exclusion lock first, and sets task A for the CPU ID of the mutual exclusion lock information area by competition The CPU ID of place CPU, then as shown in Fig. 2, task B can execute following steps:
Step 201: when access critical zone, whether the mutual exclusion lock for detecting critical zone is in the lock state, if so, executing step Rapid 202, if it is not, thening follow the steps 209.
Step 202: reading the CPU ID stored in the information area of mutual exclusion lock.
Step 203: judging whether the CPU ID read is prepending non-significant value;If so, thening follow the steps 204;If it is not, then holding Row step 206.
Step 204: continuing to read the CPU ID stored in the information area of mutual exclusion lock;What if continuous first preset times were read CPU ID is prepending non-significant value, then enters dormant state.
Step 205: judging whether the CPU ID read is identical as the CPU ID of CPU where itself;If so, thening follow the steps 206;If it is not, thening follow the steps 207.
Step 206: entering dormant state.
Step 207: the wrap count of record is added one.
Step 208: judging whether wrap count is greater than or equal to the second preset times;If so, thening follow the steps 206;If It is no, then follow the steps 201.
Step 209: locking mutual exclusion lock.
Step 210: the CPU ID of CPU where the CPU ID in the information area of mutual exclusion lock is changed to itself;And to critical Area accesses.
Step 211: before release mutual exclusion lock, the CPU ID in the information area of mutual exclusion lock being changed to prepending non-significant value.
Step 212: release mutual exclusion lock.
Wherein, in one embodiment, it can also be checked after discharging mutual exclusion lock by task B in the embodiment of the present invention Whether task in a dormant state is had in suspend mode task record, if so, operating system is then notified to wake up in a dormant state Task.Specific method, in a kind of explanation of embodiment, details are not described herein.
Embodiment three
Based on identical inventive concept, the embodiment of the present invention also provides a kind of critical zone access mechanism, as shown in figure 3, being The structural schematic diagram of the device, comprising:
Lock state detection module 301, when for accessing critical zone, whether the mutual exclusion lock for detecting critical zone is in locking shape State;
CPU ID read module 302 reads in the information area of mutual exclusion lock and stores if being in the lock state for mutual exclusion lock Central processor CPU identify ID;The CPU ID indicates that operating on the corresponding CPU of CPU ID for task has locked mutual exclusion Lock;
First sleep block 303 enters and stops if the CPU ID for reading is identical as the CPU ID of CPU where itself Dormancy state.
Wherein, in one embodiment, critical zone access mechanism further include:
Locking module, if the mutual exclusion lock for detecting critical zone is to lock mutual exclusion lock in unlocked state;
First CPU ID modified module, CPU where being changed to itself for the CPU ID in the information area by mutual exclusion lock CPU ID;
Access modules, for accessing to critical zone.
Wherein, in one embodiment, critical zone access mechanism further include:
2nd CPU ID modified module, will before discharging mutual exclusion lock after accessing for access modules to critical zone CPU ID in the information area of mutual exclusion lock is changed to prepending non-significant value, and the prepending non-significant value is for indicating that mutual exclusion lock is not any Task locking on CPU;
Prepending non-significant value determining module, if the CPU of the CPU ID and itself place CPU read for the first sleep block ID is identical, then enters before dormant state, determines that the CPU ID read is not prepending non-significant value.
Wherein, in one embodiment, critical zone access mechanism further include:
Continue read module, if the CPU ID for reading is prepending non-significant value, continues the information area for reading mutual exclusion lock The CPU ID of interior storage;
Second sleep block enters if the CPU ID for continuous first preset times to be read is prepending non-significant value Dormant state.
Wherein, in one embodiment, critical zone access mechanism further include:
The wrap count of record is added one if the CPU ID for reading is not identical as the CPU ID of itself by logging modle;
Judgment module, for judging whether wrap count is greater than or equal to the second preset times;
Third sleep block enters dormant state if being greater than or equal to the second preset times for wrap count;
Return module, if triggering the detection of lock state detection module less than the second preset times for wrap count and facing Whether the mutual exclusion lock of battery limit (BL) is in locked state.
About the device in above-described embodiment, wherein modules execute the concrete mode of operation in related this method Embodiment in be described in detail, no detailed explanation will be given here.
It should be understood by those skilled in the art that, the embodiment of the present invention can provide as method, apparatus, system or calculate Machine program product.Therefore, the present invention can be used complete hardware embodiment, complete software embodiment or combine software and hardware side The form of the embodiment in face.Moreover, it wherein includes computer usable program code that the present invention, which can be used in one or more, The computer implemented in computer-usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) The form of program product.
The present invention be referring to according to the method for the embodiment of the present invention, the flow chart of device (device) and computer program product And/or block diagram describes.It should be understood that each process in flowchart and/or the block diagram can be realized by computer program instructions And/or the combination of the process and/or box in box and flowchart and/or the block diagram.It can provide these computer programs to refer to Enable the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing units to generate One machine so that by the instruction that the processor of computer or other programmable data processing units executes generate for realizing The device for the function of being specified in one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing units with spy Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates, Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or The function of being specified in multiple boxes.
These computer program instructions can also be loaded into computer or other programmable data processing units, so that counting Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one The step of function of being specified in a box or multiple boxes.
Although preferred embodiments of the present invention have been described, it is created once a person skilled in the art knows basic Property concept, then additional changes and modifications may be made to these embodiments.So it includes excellent that the following claims are intended to be interpreted as It selects embodiment and falls into all change and modification of the scope of the invention.
Obviously, various changes and modifications can be made to the invention without departing from essence of the invention by those skilled in the art Mind and range.In this way, if these modifications and changes of the present invention belongs to the range of the claims in the present invention and its equivalent technologies Within, then the present invention is also intended to include these modifications and variations.

Claims (8)

1. a kind of critical zone access method characterized by comprising
When accessing critical zone, whether the mutual exclusion lock for detecting critical zone is in the lock state;
If so, reading the central processor CPU stored in the information area of mutual exclusion lock identifies ID;CPU ID expression operates in this Task on the corresponding CPU of CPU ID has locked mutual exclusion lock;
If the CPU ID read is identical as the CPU ID of CPU where itself, enter dormant state;
If detecting, the mutual exclusion lock of critical zone is to lock mutual exclusion lock in unlocked state;And
The CPU ID of CPU where CPU ID in the information area of mutual exclusion lock is changed to itself;And
It accesses to critical zone.
2. the method according to claim 1, wherein it is described access to critical zone after, the method is also Include:
Before discharging mutual exclusion lock, the CPU ID in the information area of mutual exclusion lock is changed to prepending non-significant value, which uses It is not locked by the task on any CPU in expression mutual exclusion lock;
If the CPU ID of the reading is identical as the CPU ID of CPU where itself, enter before dormant state, the method is also Include:
Determine that the CPU ID read is not prepending non-significant value.
3. according to the method described in claim 2, it is characterized in that, the method also includes:
If the CPU ID read is prepending non-significant value, continue to read the CPU ID stored in the information area of mutual exclusion lock;
If the CPU ID that continuous first preset times are read is prepending non-significant value, enter dormant state.
4. method according to claim 1 to 3, which is characterized in that the method also includes:
If the CPU ID read is not identical as the CPU ID of itself, the wrap count of record is added one;
Judge whether wrap count is greater than or equal to the second preset times;
If wrap count is greater than or equal to the second preset times, enter dormant state;
If wrap count less than the second preset times, returns and executes whether the mutual exclusion lock for detecting critical zone is in locked state The step of.
5. a kind of critical zone access mechanism characterized by comprising
Lock state detection module, when for accessing critical zone, whether the mutual exclusion lock for detecting critical zone is in the lock state;
CPU ID read module reads the center stored in the information area of mutual exclusion lock if being in the lock state for mutual exclusion lock Processor CPU identifies ID;The CPU ID indicates that operating on the corresponding CPU of CPU ID for task has locked mutual exclusion lock;
First sleep block enters dormant state if the CPU ID for reading is identical as the CPU ID of CPU where itself;
Locking module, if the mutual exclusion lock for detecting critical zone is to lock mutual exclusion lock in unlocked state;
First CPU ID modified module, the CPU of CPU where being changed to itself for the CPU ID in the information area by mutual exclusion lock ID;
Access modules, for accessing to critical zone.
6. device according to claim 5, which is characterized in that described device further include:
2nd CPU ID modified module, will before discharging mutual exclusion lock after accessing for the access modules to critical zone CPU ID in the information area of mutual exclusion lock is changed to prepending non-significant value, and the prepending non-significant value is for indicating that mutual exclusion lock is not any Task locking on CPU;
Prepending non-significant value determining module, if the CPU of the CPU ID and itself place CPU read for first sleep block ID is identical, then enters before dormant state, determines that the CPU ID read is not prepending non-significant value.
7. device according to claim 6, which is characterized in that described device further include:
Continue read module, if the CPU ID for reading is prepending non-significant value, continues the information area memory for reading mutual exclusion lock The CPU ID of storage;
Second sleep block enters suspend mode if the CPU ID for continuous first preset times to be read is prepending non-significant value State.
8. according to the device any in claim 5-7, which is characterized in that described device further include:
The wrap count of record is added one if the CPU ID for reading is not identical as the CPU ID of itself by logging modle;
Judgment module, for judging whether wrap count is greater than or equal to the second preset times;
Third sleep block enters dormant state if being greater than or equal to the second preset times for wrap count;
Return module, if triggering lock state detection module detection critical zone less than the second preset times for wrap count Mutual exclusion lock whether be in locked state.
CN201610140580.3A 2016-03-11 2016-03-11 A kind of critical zone access method and device Active CN105824709B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610140580.3A CN105824709B (en) 2016-03-11 2016-03-11 A kind of critical zone access method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610140580.3A CN105824709B (en) 2016-03-11 2016-03-11 A kind of critical zone access method and device

Publications (2)

Publication Number Publication Date
CN105824709A CN105824709A (en) 2016-08-03
CN105824709B true CN105824709B (en) 2019-09-17

Family

ID=56988003

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610140580.3A Active CN105824709B (en) 2016-03-11 2016-03-11 A kind of critical zone access method and device

Country Status (1)

Country Link
CN (1) CN105824709B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106776050B (en) * 2016-10-17 2019-12-17 广州视源电子科技股份有限公司 Multi-user process mutual exclusion method and device
CN106569897B (en) * 2016-11-07 2019-11-12 许继集团有限公司 The polling method and device of shared bus based on collaborative multi-task scheduling mechanism
CN111414337B (en) * 2019-01-08 2023-05-26 阿里巴巴集团控股有限公司 File reading method and device, computing equipment and storage medium
CN109947575B (en) * 2019-03-21 2021-08-24 恒生电子股份有限公司 Locking and releasing method of read-write lock and related system
CN111913810B (en) * 2020-07-28 2024-03-19 阿波罗智能技术(北京)有限公司 Task execution method, device, equipment and storage medium in multithreading scene

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1920780A (en) * 2006-08-15 2007-02-28 杭州华为三康技术有限公司 Method and system for accessing critical region
CN1924816A (en) * 2006-09-26 2007-03-07 杭州华为三康技术有限公司 Method and apparatus for improving speed of multi-core system accessing critical resources
CN101051281A (en) * 2007-05-16 2007-10-10 杭州华三通信技术有限公司 Method and device for mutual repulsion access of multiple CPU to critical resources
WO2014183510A1 (en) * 2013-05-17 2014-11-20 Hangzhou H3C Technologies Co., Ltd. Spinlock resources processing

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7610585B2 (en) * 2004-06-03 2009-10-27 Intel Corporation Thread synchronization methods and apparatus for managed run-time environments

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1920780A (en) * 2006-08-15 2007-02-28 杭州华为三康技术有限公司 Method and system for accessing critical region
CN1924816A (en) * 2006-09-26 2007-03-07 杭州华为三康技术有限公司 Method and apparatus for improving speed of multi-core system accessing critical resources
CN101051281A (en) * 2007-05-16 2007-10-10 杭州华三通信技术有限公司 Method and device for mutual repulsion access of multiple CPU to critical resources
WO2014183510A1 (en) * 2013-05-17 2014-11-20 Hangzhou H3C Technologies Co., Ltd. Spinlock resources processing

Also Published As

Publication number Publication date
CN105824709A (en) 2016-08-03

Similar Documents

Publication Publication Date Title
CN105824709B (en) A kind of critical zone access method and device
TWI384356B (en) Method and system for validating a computer system
CN104572568B (en) Read lock operation method, write lock operation method and system
US10977092B2 (en) Method for efficient task scheduling in the presence of conflicts
US20090320028A1 (en) System and method for load-adaptive mutual exclusion with waiting process counts
US20060130061A1 (en) Use of rollback RCU with read-side modifications to RCU-protected data structures
TWI667588B (en) Computing device, method and machine readable storage media for detecting unauthorized memory accesses
CN111488290B (en) Thread testing method and device based on intelligent electric meter operating system
EP3472684B1 (en) Wake lock aware system wide job scheduling for energy efficiency on mobile devices
US8713262B2 (en) Managing a spinlock indicative of exclusive access to a system resource
EP3241116B1 (en) Memory access protection using processor transactional memory support
JP2010061522A (en) Computer system for permitting exclusive access to shared data, method for the computer system, and computer readable recording medium
US20150052529A1 (en) Efficient task scheduling using a locking mechanism
US9411661B2 (en) Deadlock avoidance
CN109409087B (en) Anti-privilege-raising detection method and device
WO2007028807A1 (en) Managing a resource lock
CN112363846B (en) Deadlock detection method and device for database transaction and electronic equipment
JP2016517102A (en) Method and apparatus for processing replay data in a database
CN106716348A (en) Shared resources in a data processing appartus for executing a plurality of threads
KR20170131366A (en) Shared resource access control method and apparatus
CN103530197B (en) A kind of method for detecting and solving Linux system deadlock
CN105404559A (en) Debugging in a data processing apparatus
CN106068497A (en) Transaction memory is supported
Madalinski et al. Predictability verification with parallel LTL-X model checking based on Petri net unfoldings
KR102443089B1 (en) Synchronization in a computing device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant