CN103793267B - The access method and device of queue - Google Patents

The access method and device of queue Download PDF

Info

Publication number
CN103793267B
CN103793267B CN201410033780.XA CN201410033780A CN103793267B CN 103793267 B CN103793267 B CN 103793267B CN 201410033780 A CN201410033780 A CN 201410033780A CN 103793267 B CN103793267 B CN 103793267B
Authority
CN
China
Prior art keywords
value
pointer variable
node
dummy node
queue
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
CN201410033780.XA
Other languages
Chinese (zh)
Other versions
CN103793267A (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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201410033780.XA priority Critical patent/CN103793267B/en
Publication of CN103793267A publication Critical patent/CN103793267A/en
Application granted granted Critical
Publication of CN103793267B publication Critical patent/CN103793267B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a kind of access method of queue and device, belong to data access technology field.Including:Create the Section Point of enqueue to be added;The value of rear pointer variable is obtained, whether the value for judging the pointer variable included in the first node pointed by the value got is empty;If the value of the pointer variable included in the first node pointed by the value got is non-NULL, then determine that the value of rear pointer variable is updated, obtain the value after rear pointer variable update, until judging the value of the pointer variable included in the first node pointed by the value after rear pointer variable update for sky, Section Point is added into queue, and the value for the pointer variable that the first node pointed by the value got is included points to Section Point.The present invention remains able to continue executing with the enqueue operation of node, so as to realize the concurrent access of queue in the case where not locked to queue, and then improves the efficiency of access queue after the value of rear pointer variable updates because of concurrent access.

Description

The access method and device of queue
Technical field
The present invention relates to data access technology field, the access method and device of more particularly to a kind of queue.
Background technology
During data access technology is carried out, queue is as a kind of data structure, due to its FIFO (First Input First Output, first in first out) characteristic, be applied in many occasions, the design of such as algorithm.Wherein, exist When being conducted interviews to queue, in order to improve the speed of resource utilization and program operation, program is in logical meaning in most cases On be divided into several threads, using multi-thread concurrent mechanism, queue is conducted interviews by multithreading.
A kind of access method of queue is provided in correlation technique, in the method, when thread A needs access queue, First the queue can be locked, thread A can just be released lock after access queue terminates.According to above-mentioned access mode, line Journey A is during access queue, if the new thread B that arrived needs to conduct interviews to queue again, because lock is not solved Remove, now thread B can not conduct interviews to queue, correlated variables in queue cannot also be modified.
During the present invention is realized, inventor has found that correlation technique at least has problems with:
When the method using locking realizes that multiple threads conduct interviews to queue, a thread accesses queue, to the team Row are locked, if another thread needs to conduct interviews to queue, because the queue has been locked, now the thread can be by operation shape State is changed into wait state, and carries out context switching.And the process for carrying out context switching needs the resource taken more, and consumption It is time-consuming longer.If in addition, taking the thread not unblock in time of queue, being likely to result in other threads for needing to access the queue The long period is waited, it is therefore, inefficient when realizing the access of queue by the method for locking.
The content of the invention
In order to solve problem of the prior art, the embodiments of the invention provide a kind of access method of queue and device.Institute State technical scheme as follows:
On the one hand there is provided a kind of access method of queue, methods described includes:
The Section Point of the queue to be added is created, it is empty pointer variable that the Section Point, which includes value,;
Obtain the value of the rear pointer variable, and judge the pointer that is included in the first node pointed by the value got Whether the value of variable is empty;
If the value of the pointer variable included in the first node pointed by the value got is non-NULL, it is determined that the tail of the queue The value of pointer variable is updated, and obtains the value after the rear pointer variable update, until judging the rear pointer variable more The value of the pointer variable included in the first node pointed by value after new is sky, and the Section Point is added into the queue, And the value for the pointer variable for including the first node pointed by the value got points to the Section Point;
The value of team's head pointer variable is obtained, and judges that the pointer included in the dummy node pointed by the value got becomes Whether the value of amount is empty;
If the value of the pointer variable included in the dummy node is non-NULL, obtained respectively on two different time points The value of team's head pointer variable, and judge whether the value of team's head pointer variable got twice is identical;If obtaining twice The value for the team's head pointer variable got is different, it is determined that the dummy node is updated, again two different time points The upper value for obtaining team's head pointer variable respectively, until the value for team's head pointer variable that judgement is got twice is identical, Discharge the dummy node that is updated, and using the node pointed by the value of the pointer variable included in the dummy node being updated as New dummy node, the new dummy node is not belonging to the queue;Or,
If the value of the pointer variable included in the dummy node is non-NULL, obtained respectively on two different time points The value of the pointer variable included in the dummy node, and the pointer variable for judging to include in the dummy node that gets twice Whether value is identical;If the value of the pointer variable included in the dummy node got twice is different, it is determined that the dummy node Next node be updated, obtain the pointer variable included in the dummy node respectively on two different time points again Value, until judging that the value of pointer variable included in the dummy node that gets twice is identical, delete in the dummy node Comprising pointer variable value pointed by node.
On the other hand there is provided a kind of access mechanism of queue, described device includes:
Creation module, the Section Point for creating the queue to be added, it is empty finger that the Section Point, which includes value, Pin variable;
First acquisition module, the value for obtaining the rear pointer variable;
First judge module, the value of the pointer variable for judging to include in the first node pointed by the value that gets is No is sky;
Module is added, for being non-NULL when the value of the pointer variable included in the first node pointed by the value got When, it is determined that the value of the rear pointer variable is updated, and obtains the value after the rear pointer variable update, until judging institute It is sky to state the value of the pointer variable included in the first node pointed by the value after rear pointer variable update, by the second section Point adds the queue, and the value for the pointer variable that the first node pointed by the value got is included points to the second section Point;
Described device also includes:
Second acquisition module, the value for obtaining team's head pointer variable;
Whether the value of the pointer variable included in the second judge module, the dummy node pointed by value got for judgement For sky;
3rd acquisition module, for when the pointer variable included in the dummy node value be non-NULL when, then at two not The value of team's head pointer variable is obtained on same time point respectively;3rd judge module, for the institute for judging to get twice Whether identical state group value of head pointer variable;First removing module, for the team's head pointer variable that ought get twice When being worth different, it is determined that the dummy node is updated, team's head pointer is obtained respectively on two different time points again The value of variable, until the value for team's head pointer variable that judgement is got twice is identical, discharges the dummy node being updated, and will Node pointed by the value of the pointer variable included in the dummy node being updated is as new dummy node, the new pseudo- section Point is not belonging to the queue;Or,
Described device also includes:
4th acquisition module, the value for obtaining team's head pointer variable;
Whether the value of the pointer variable included in the 4th judge module, the dummy node pointed by value got for judgement For sky;
5th acquisition module, for being non-NULL when the value of the pointer variable included in the dummy node pointed by the value got When, then obtain the value of the pointer variable included in the dummy node respectively on two different time points;
5th judge module, for the value of pointer variable that judges to include in the dummy node that gets twice whether phase Together;
Second removing module, for when the value of the pointer variable included in the dummy node got twice is different, Then determine that the next node of the dummy node is updated, obtain the dummy node respectively on two different time points again In the value of pointer variable that includes, until judge that the value of pointer variable included in the dummy node got twice is identical, Delete the node pointed by the value of the pointer variable included in the dummy node.
The beneficial effect of technical scheme provided in an embodiment of the present invention is:
By creating the Section Point of enqueue to be added, the value of rear pointer variable, and the value institute that judgement is got are obtained The value of the pointer variable included in the first node of sensing is non-NULL, it is determined that after the value of rear pointer variable is updated, again The value after rear pointer variable update is obtained, until judging to wrap in the first node pointed by the value after rear pointer variable update The value of the pointer variable contained is sky, and Section Point added into queue, and the first node pointed by the value got is included The value of pointer variable points to Section Point.Realize after the value of rear pointer variable updates because of concurrent access, still It can continue to perform the enqueue operation of node, so that without that can be visited in the case of being locked to queue queue in parallel Ask, and then improve the efficiency of access queue.
Brief description of the drawings
Technical scheme in order to illustrate the embodiments of the present invention more clearly, makes required in being described below to embodiment Accompanying drawing is briefly described, it should be apparent that, drawings in the following description are only some embodiments of the present invention, for For those of ordinary skill in the art, on the premise of not paying creative work, other can also be obtained according to these accompanying drawings Accompanying drawing.
Fig. 1 is a kind of access method flow chart for queue that the embodiment of the present invention one is provided;
Fig. 2 is a kind of access method flow chart for queue that the embodiment of the present invention two is provided;
Fig. 3 is a kind of access method schematic diagram for queue that the embodiment of the present invention two is provided;
Fig. 4 is a kind of access method flow chart for queue that the embodiment of the present invention three is provided;
Fig. 5 is a kind of access method schematic diagram for queue that the embodiment of the present invention three is provided;
Fig. 6 is a kind of access method flow chart for queue that the embodiment of the present invention four is provided;
Fig. 7 is a kind of access method schematic diagram for queue that the embodiment of the present invention four is provided;
Fig. 8 is a kind of structural representation of the access mechanism for queue that the embodiment of the present invention three is provided;
Fig. 9 is a kind of structural representation for terminal that the embodiment of the present invention four is provided.
Embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing to embodiment party of the present invention Formula is described in further detail.
Embodiment one
Due to when carrying out queue accesses, if realizing that multiple threads conduct interviews to queue using the method for locking, one Thread accesses queue, is locked to the queue, if another thread needs to conduct interviews to queue, because the queue has been locked, Now the thread can be changed into wait state from running status, and carry out context switching.And the process for carrying out context switching is needed The resource to be taken is more, and it is longer to expend the time.If in addition, taking the thread not unblock in time of queue, being likely to result in it It needs the thread for accessing the queue to wait the long period, therefore, and efficiency when realizing queue accesses by the method for locking is not It is high.
In order to improve queue accesses efficiency, the embodiments of the invention provide a kind of access method of queue, this method can be with Applied to terminal, the terminal includes but is not limited to mobile phone, computer, tablet personal computer etc., and the present embodiment is not to the specific of terminal Form is defined.Referring to Fig. 1, the method flow that the present embodiment is provided includes:
101:The Section Point of enqueue to be added is created, it is empty pointer variable that Section Point, which includes value,;
102:Obtain the value of rear pointer variable;
103:Whether the value for judging the pointer variable included in the first node pointed by the value got is empty, if obtaining To value pointed by first node in the value of pointer variable that includes be non-NULL, then step 102 is re-executed, if getting The value of the pointer variable included in the pointed first node of value is sky, then performs step 104;
104:Section Point is added into queue, and the pointer variable that the first node pointed by the value got is included Value points to Section Point.
Wherein, Section Point is added into queue, and the pointer variable that the first node pointed by the value got is included Value point to Section Point after, in addition to:
The value of rear pointer variable is updated to point to the value of Section Point.
Wherein, a dummy node is also included outside queue, dummy node includes pointer variable, and queue also includes team's head pointer Variable, the value of team's head pointer variable is used to point to dummy node, and this method also includes:
The value of team head pointer variable is obtained, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in dummy node is non-NULL, team's head is obtained respectively on two different time points The value of pointer variable, and judge whether the value of team's head pointer variable got twice is identical;
If the value of the team's head pointer variable got twice is different, it is determined that dummy node is updated, again in two differences Time point on obtain the value of team's head pointer variable respectively, until judge that the value of team's head pointer variable got twice is identical, Discharge the dummy node that is updated, and using the node pointed by the value of the pointer variable included in the dummy node being updated as new Dummy node.
Wherein, by the node updates pointed by the value of the pointer variable included in dummy node be new dummy node after, also Including:
The value of team's head pointer variable is updated to point to the value of new dummy node.
Wherein, a dummy node is also included outside queue, queue also includes team's head pointer variable, the value of team's head pointer variable For pointing to dummy node, this method also includes:
The value of team head pointer variable is obtained, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in the dummy node pointed by the value got is non-NULL, when two different Between obtain the value of the pointer variable included in dummy node respectively on point, and judge the pointer that is included in the dummy node got twice Whether the value of variable is identical;
If the value of the pointer variable included in the dummy node got twice is different, it is determined that the next node of dummy node It is updated, obtains the value of the pointer variable included in dummy node respectively on two different time points again, until judges two The value of the pointer variable included in the secondary dummy node got is identical, pointed by the value for deleting the pointer variable included in dummy node Node.
Wherein, after the node pointed by the value of the pointer variable included in deletion dummy node, in addition to:
The value of the pointer variable included in dummy node is pointed to the next node of deleted node.
Wherein, after judging whether the value of the pointer variable included in the dummy node that gets is sky, in addition to:
If the value of the pointer variable included in the dummy node pointed by the value of team's head pointer variable is sky, returns and delete section The prompting of point failure.
The method that the present embodiment is provided, by creating the Section Point of enqueue to be added, and judges that the value got is signified To first node in the value of pointer variable that includes be non-NULL, after determining that the value of rear pointer variable is updated, reacquire Value after rear pointer variable update, until judging what is included in the first node pointed by the value after rear pointer variable update The value of pointer variable is sky, and Section Point is added into queue, and the pointer that the first node pointed by the value got is included The value of variable points to Section Point.The value when rear pointer variable is realized after queue is updated by concurrent access, still It so can continue to perform the enqueue operations of node.In addition, the value by obtaining team's head pointer variable, and the value got in judgement The value of the pointer variable included in pointed dummy node is non-NULL, and the value for team's head pointer variable that judgement is got twice is not Together, when determining that dummy node is updated, the value of team's head pointer variable is obtained respectively on two different time points again, until sentencing The value of the disconnected team's head pointer variable got twice is identical, discharges the dummy node being updated, and will be wrapped in the dummy node being updated Node pointed by the value of the pointer variable contained is as new dummy node, or deletes the value of the pointer variable included in dummy node Pointed node, realizes the next node when dummy node or dummy node after queue is updated by concurrent access, Remain able to continue executing with the dequeue operation of node.So that in the case of without be locked to queue, can be to queue in parallel Access, and then improve the efficiency of access queue.
Embodiment two
The embodiments of the invention provide a kind of access method of queue, with reference to the content of above-described embodiment one, the present embodiment So that the access of queue is enqueue operation as an example, the method that the present embodiment is provided is illustrated.Referring to Fig. 2, this implementation The method flow that example is provided includes:
201:The Section Point of enqueue to be added is created, it is empty pointer variable that Section Point, which includes value,;
First node, a rear pointer variable are comprised at least in queue, the value of rear pointer variable is used to point to queue Tail node, tail node is that a pointer variable is comprised at least in first node, each first node that queue is included, and pointer becomes The value of amount, which is used to point to, is currently located the next node that node is connected, and the value for the pointer variable that tail node is included is sky.
The present embodiment does not make specific restriction to the building mode of queue, includes but is not limited to:Queue is enterprising in shared drive Row is built, and shared memory space is divided into the blocks of formed objects as memory block previously according to the node size in queue, each Individual memory block is used to preserve a node in queue.In addition, in order to be managed to memory block, can be set before each memory block It is equipped with one piece of region and stores a flag, is idle for identifying the memory block, is still used.Because queue is Built on shared drive, corresponding, it is based on shared drive, i.e., queue to be entered parallel in fact that queue, which is conducted interviews, Row access is that shared drive is conducted interviews parallel.In addition, the parallel executive agent conducted interviews to queue can be multiple lines Journey or multiple processes, therefore, it can be the queue accesses of striding course or cross-thread that queue, which is conducted interviews, parallel, so as to Improve the efficiency to queue accesses.
Wherein, queue can be managed by list structure, i.e., the position of next node is deposited by a upper node Storage, each node is in addition to the information comprising itself, and also one node head is used to be only after pointing to next node, node head The content of node.For the information of memory node head, the sky behind a reserved area, reserved area is marked in the head of shared drive Between the big memory block such as be just divided.Three information have coexisted in reserved area:Queue whether initialisation identifications position init, head The position of node is the value head of group head pointer variable, and the position of tail node is the value tail of rear pointer variable.Each first The pointer variable of node can be stored in the node head of each node, and the present embodiment is not especially limited to this.
The Section Point of an enqueue to be added is created, Section Point includes node content and a pointer variable, certainly, Other contents can also be included in the Section Point of establishment, the present embodiment is not especially limited to this.It should be noted that in order to It is follow-up easily to carry out queue accesses, can be to the pointer in Section Point after the Section Point for creating an enqueue to be added Variable does the operation initialized., then can be by the Section Point because the Section Point will be added in queue as new node The value of pointer variable be set to sky, the present embodiment is not specifically limited to this.
202:Obtain the value of rear pointer variable;
The value of rear pointer variable can be by reading the value of tail in reserved area, so as to obtain rear pointer variable Value.Certainly, other methods can also be used by obtaining the value of rear pointer variable, and the present embodiment is not especially limited to this.
203:Whether the value for judging the pointer variable included in the first node pointed by the value got is empty, if obtaining To value pointed by first node in the value of pointer variable that includes be non-NULL, then step 202 is re-executed, if getting The value of the pointer variable included in the pointed first node of value is sky, then performs step 204;
What is pointed to due to the value of rear pointer variable is last node in queue, when single thread conducts interviews to queue When, join the team every time after finishing, the pointer variable included in the queue pointed by the value of rear pointer variable in last node Value be always empty.When multiple thread parallels conduct interviews to queue, if there is a thread to change rear pointer variable The value of the pointer variable included in the pointed queue of value in last node, when other threads are read again, may result in reading The value of the pointer variable included in queue pointed by the value of the rear pointer variable of taking-up in last node is not sky, i.e., The value of the pointer variable included in the first node pointed by value got is non-NULL.It now can determine that rear pointer variable Value is updated, and is returned to step 202 and is obtained the value after rear pointer variable update, until judging after rear pointer variable update Value pointed by first node in the value of pointer variable that includes be sky, then perform step 204.
204:Section Point is added into queue, and the pointer variable that the first node pointed by the value got is included Value points to Section Point;
Section Point is added after queue, the present embodiment is not to will include in the first node pointed by the value got The mode that the value of pointer variable points to Section Point makees specific restriction, includes but is not limited to:Section Point is obtained in internal memory Storage address, the storage address is assigned to the pointer variable included in the first node pointed by rear pointer variable, so that The value of the pointer variable included in the first node pointed by rear pointer variable is set to point to Section Point.
It should be noted that the follow-up access operation for carrying out queue for convenience, sets a dummy node outside queue For Added Management queue, will the dummy node regard node outside queue as.After queue initialization, queue is space-time, team The node head and node content that the value of head pointer variable and rear pointer variable is all pointed in this dummy node, dummy node be all It is empty.
For example, using queue as sky, being used for outside the queue comprising one exemplified by the dummy node of Added Management queue, by the puppet Node is designated as dummy nodes, and the new node of enqueue to be added is Section Point.Step A in as shown in Figure 3, tail of the queue is referred to The value of the pointer variable included in dummy nodes pointed by the value of pin variable points to new node, that is, points to Section Point.
Section Point is added due to new in queue, thus the tail node of queue is the Section Point of the new addition, in reality After the enqueue operations of existing Section Point, the method that the present embodiment is provided also includes the step of the follow-up value for updating rear pointer variable Suddenly.
205:The value of rear pointer variable is updated to point to the value of Section Point.
The update mode of the value of the present embodiment not to the value of rear pointer variable to be updated to point to Section Point makees specific Limit, include but is not limited to:Storage address of the Section Point in internal memory is obtained, the storage address is assigned into rear pointer becomes Amount, so that the value of rear pointer variable points to Section Point.
For example, the step B in as shown in Figure 3, rear pointer variable Tail value is pointed to the new node of enqueue to be added, The new node of enqueue wherein to be added is Section Point.
The method that the present embodiment is provided, by creating the Section Point of enqueue to be added, and judges that the value got is signified To first node in the value of pointer variable that includes be non-NULL, after determining that the value of rear pointer variable is updated, reacquire Value after rear pointer variable update, until judging what is included in the first node pointed by the value after rear pointer variable update The value of pointer variable is sky, and Section Point is added into queue, and the pointer that the first node pointed by the value got is included The value of variable points to Section Point.The value when rear pointer variable is realized after queue is updated by concurrent access, still It so can continue to perform the enqueue operations of node.So as in the case of without being locked to queue, visit queue in parallel Ask, and then improve the efficiency of access queue.
Embodiment three
The embodiments of the invention provide a kind of access method of queue, with reference to the content of above-described embodiment one, to this implementation The method that example is provided is illustrated.Referring to Fig. 4, the method flow that the present embodiment is provided includes:
401:Obtain the value of team's head pointer variable;
First node, a rear pointer variable are comprised at least in queue, the value of rear pointer variable is used to point to queue Tail node, tail node is that a pointer variable is comprised at least in first node, each first node that queue is included, and pointer becomes The value of amount, which is used to point to, is currently located the next node that node is connected, and the value for the pointer variable that tail node is included is sky.This Outside, a dummy node is also included outside queue, dummy node includes pointer variable, and queue also includes team's head pointer variable, team's head The value of pointer variable is used to point to dummy node.The value of team's head pointer variable can by reading the value of head in reserved area so that Group value of head pointer variable can be obtained.Certainly, other methods, the present embodiment pair can also be used by obtaining the value of team's head pointer variable This is not especially limited.
402:Whether the value for judging the pointer variable included in the dummy node pointed by the value got is empty, if dummy node In the value of pointer variable that includes be non-NULL, then step 403 is performed, if being wrapped in the dummy node pointed by the value of team's head pointer variable The value of the pointer variable contained is sky, then performs step 407;
Due to being provided with a dummy node, i.e. dummy nodes outside queue, the dummy node is only used for convenient to queue progress Node after operation, dummy node is only in queue real node.Therefore, when there is no subsequent node behind dummy node, this When, it is nonsensical to do the node that dequeue operation deleted in queue, so as to need to judge the puppet pointed by the value that gets Whether the value of the pointer variable included in node is empty.Wrapped in the dummy node pointed by value that the present embodiment is not got to judgement Whether the value of the pointer variable contained is that empty judgment mode makees specific restriction, is included but is not limited to:Team's head according to getting refers to The value of pin variable determines the dummy node pointed by team's head pointer variable.If the value of the pointer variable included in dummy node is non-NULL, Then mean to include node in queue, then perform step 403, if being included in the dummy node pointed by the value of team's head pointer variable Pointer variable value for sky, then mean queue for sky, perform step 407.
403:Obtain the value of team's head pointer variable respectively on two different time points;
The acquisition modes of the value of the present embodiment not to obtaining team's head pointer variable respectively on two different time points are made Specific to limit, i.e., on two different time points of the value for obtaining team's head pointer variable, the present embodiment is not especially limited.Bag Include but be not limited to:When needing to carry out dequeue operation, reserved area head value is read, so as to obtain group value of head pointer variable. When every the judgement operation being ready to carry out after preset time period in step 404, then reserved area head value is read, so that again Obtain the value of team's head pointer variable.The present embodiment is not defined to the size of preset time period.
404:Whether the value for team's head pointer variable that judgement is got twice is identical, if the team's head pointer got twice becomes The value of amount is different, then re-executes step 403, if the value of the team's head pointer variable got twice is identical, perform step 405;
What is pointed to due to the value of team's head pointer variable is dummy node in queue, when single thread conducts interviews to queue, Go out every time after team finishes, the dummy node pointed by the value of team's head pointer variable is real dummy node.When multiple thread parallels pair When queue conducts interviews, if there is a thread to change group value of head pointer variable, when other threads are read again, reading may result in Node pointed by the value of team's head pointer variable of taking-up is not real dummy node, i.e., the team's head pointer got twice becomes The value of amount is differed.It now can determine that group value of head pointer variable is updated, obtain the value after team's head pointer variable update, until The value for team's head pointer variable that judgement is got twice is identical, then performs step 405.
405:The dummy node being updated is discharged, and by pointed by the value of the pointer variable included in the dummy node being updated Node is used as new dummy node;
The delivery mode for the dummy node that the present embodiment is not updated to release makees specific restriction, includes but is not limited to:It will deposit Store up memory space of the dummy node being updated in internal memory to withdraw, so as to discharge the dummy node being updated.
For example, as shown in figure 5, the dummy node dummy nodes in release Fig. 5 are the dummy node being updated, by dummy nodes In node 1 pointed by the value of pointer variable that includes as new dummy node.
Because the node in queue is by as new dummy node, and new dummy node is not belonging to queue, it is thus achieved that section The dequeue operation of point.After the dequeue operation of node is realized, because original dummy node is updated to new dummy node, thus this The step of method that embodiment is provided also includes the value of follow-up renewal team head pointer variable.
406:The value of team's head pointer variable is updated to point to the value of new dummy node, this visit queue terminates;
The update mode of the value of the present embodiment not to the value of team's head pointer variable to be updated to point to new dummy node is made to have Body is limited, and is included but is not limited to:Storage address of the new dummy node in internal memory is obtained, by the storage address assignment team head pointer Variable, so that the value that the value of team's head pointer variable is updated to point to the value of new dummy node, i.e. team's head pointer variable is pointed to newly Dummy node.
407:Return to the prompting of deletion of node failure.
Because the value of the pointer variable included in the dummy node pointed by the value of team's head pointer variable is sky, that is, mean puppet It is sky not have node, i.e. queue after node, and dequeue operation can return to the prompting of deletion of node failure without carrying out.This The echo plex mode of the prompting of embodiment not to returning to deletion of node failure makees specific restriction, includes but is not limited to:Returned to system Error identification, system is reported an error according to error identification.
The method that the present embodiment is provided, by obtaining the value of team's head pointer variable, and pointed by the value for judging to get Dummy node in the value of pointer variable that includes be non-NULL, judge that the value of team's head pointer variable got twice is different, it is determined that When dummy node is updated, the value of team's head pointer variable is obtained respectively on two different time points again, until judging twice The value of the team's head pointer variable got is identical, discharges the dummy node being updated, and the finger that will be included in the dummy node being updated Node pointed by the value of pin variable is realized when dummy node because queue is updated by concurrent access as new dummy node Afterwards, remain able to continue executing with the dequeue operation of node.So that in the case of without be locked to queue, can be to queue simultaneously Row is accessed, and then improves the efficiency of access queue.
Example IV
The embodiments of the invention provide a kind of access method of queue, this method is with above-described embodiment three with dequeue operation Exemplified by, the access method to queue is illustrated.The difference of the present embodiment and above-described embodiment three is, above-mentioned reality Apply example three be by by the node updates of dequeue be new dummy node, and discharge the mode of original dummy node realize out team grasp Make.And in the present embodiment, dummy node is immobilized, dequeue operation is realized by the node deleted in queue, particular content will With reference to the content of above-described embodiment one, the method that the present embodiment is provided is illustrated.Referring to Fig. 6, the present embodiment is provided Method flow include:
601:Obtain the value of team's head pointer variable;
The acquisition modes of the value of the present embodiment not to obtaining team's head pointer variable make specific restriction, are referred to during specific implementation The content of step 401 in embodiment three, here is omitted.
602:Whether the value for judging the pointer variable included in the dummy node pointed by the value got is empty, if dummy node In the value of pointer variable that includes be non-NULL, then step 603 is performed, if being wrapped in the dummy node pointed by the value of team's head pointer variable The value of the pointer variable contained is sky, then performs step 607;
The acquisition modes of the value of the present embodiment not to obtaining team's head pointer variable make specific restriction, also judgement are not got Value pointed by dummy node in the value of pointer variable that includes whether be empty judgment mode make it is specific limit, during specific implementation The step 402 in embodiment three is may be referred to, here is omitted.
603:Obtain the value of the pointer variable included in dummy node respectively on two different time points;
The present embodiment obtains the acquisition of the value of the pointer variable included in dummy node respectively on two different time points Mode makees specific restriction, includes but is not limited to:When needing to carry out dequeue operation, reserved area head value is read, so as to obtain The value of team's head pointer variable, then obtain the value of the pointer variable included in group value of head pointer variable, i.e., included in dummy node The value of pointer variable.When the judgement operation being ready to carry out in step 604, reserved area head value is again read off, so that again The value of the pointer variable included in the value for obtaining team's head pointer variable.
604:Whether the value of the pointer variable included in the dummy node that judgement is got twice is identical, if get twice The value of the pointer variable included in dummy node is different, then re-executes step 603, if included in the dummy node got twice The value of pointer variable is identical, then performs step 605;
What is pointed to due to the value of pointer variable included in dummy node is head node in queue, when serially visiting queue When asking, go out every time after team finishes, what the value of the pointer variable included in dummy node was pointed to is real head node in queue.When simultaneously When row conducts interviews to queue, if wherein once accessing the value for changing the pointer variable included in dummy node, access again simultaneously The value of the pointer variable included in dummy node is read, the value that may result in the pointer variable included in the dummy node read out is signified To node be not before head node, i.e., the value of the pointer variable included in the dummy node got twice differs, this When determine that the value of the pointer variable included in dummy node is updated, obtain the value after the pointer variable that includes updates in dummy node, Until the value of the pointer variable included in the dummy node that judgement is got twice is identical, then perform step 605.
605:Delete the node pointed by the value of the pointer variable included in dummy node;
The present embodiment is not made to have to the deletion mode for deleting the node pointed by the value of the pointer variable included in dummy node Body is limited, and is included but is not limited to:By the node release pointed by the value of the pointer variable included in dummy node, so as to delete pseudo- section Node pointed by the value of the pointer variable included in point.
For example, as shown in fig. 7, the node 1 pointed by the value of the pointer variable included in dummy node is discharged, so as to delete Node 1 pointed by the value of the pointer variable included in dummy node.
606:The value of the pointer variable included in dummy node is pointed to the next node of deleted node, this visit Queue terminates;
The next node of the present embodiment node not deleted to the value sensing by the pointer variable included in dummy node Mode make specific restriction, include but is not limited to:The value for obtaining the pointer variable included in dummy node points to deleted node Storage address of the next node in internal memory, the storage address is assigned to the pointer variable included in dummy node so that The value of the pointer variable included in dummy node is set to point to the next node of deleted node.
For example, as shown in fig. 7, the value of the pointer variable included in dummy node dummy nodes points to deleted node Next node, i.e. node 2.
607:Return to the prompting of deletion of node failure.
The echo plex mode of the prompting of the present embodiment not to returning to deletion of node failure makees specific restriction, can join during specific implementation The step 407 in embodiment three is examined, here is omitted.
The method that the present embodiment is provided, by obtaining the value of team's head pointer variable, and pointed by the value for judging to get Dummy node in the value of pointer variable that includes be non-NULL, judge the value of pointer variable included in the dummy node got twice Difference, when determining that the next node of dummy node is updated, is obtained in dummy node respectively on two different time points again Comprising pointer variable value, until judging that the value of pointer variable included in the dummy node that gets twice is identical, delete pseudo- Node pointed by the value of the pointer variable included in node, realizes the next node when dummy node because queue is visited parallel After asking and updating, remain able to continue executing with the dequeue operation of node.So as in the situation without being locked to queue Under, queue in parallel can be accessed, and then improve the efficiency of access queue.
Embodiment five
The embodiments of the invention provide a kind of access mechanism of queue, the device is used to perform above-described embodiment one to implementation The method that example four is provided.Referring to Fig. 8, the device includes:
Creation module 801, the Section Point for creating enqueue to be added, Section Point includes value and become for empty pointer Amount;
First acquisition module 802, the value for obtaining rear pointer variable;
The pointer variable included in first judge module 803, the first node pointed by value got for judgement Whether value is empty;
Module 804 is added, is non-for the value when the pointer variable included in the first node pointed by the value got Space-time, it is determined that the value of rear pointer variable is updated, obtains the value after rear pointer variable update, until judging rear pointer The value of the pointer variable included in the first node pointed by value after variable update is sky, and Section Point is added into queue, and The value for the pointer variable that first node pointed by the value got is included points to Section Point.
As a kind of preferred embodiment, the device also includes:
First update module, the value for the value of rear pointer variable to be updated to point to Section Point.
As a kind of preferred embodiment, the device also includes:
Second acquisition module, the value for obtaining team's head pointer variable;
Whether the value of the pointer variable included in the second judge module, the dummy node pointed by value got for judgement For sky;
3rd acquisition module, it is for when the value of the pointer variable included in dummy node is non-NULL, then different at two The value of team's head pointer variable is obtained on time point respectively;
Whether the 3rd judge module, the value of team's head pointer variable for judging to get twice is identical;
First removing module, for when the value of the team's head pointer variable got twice is different, it is determined that dummy node quilt Update, obtain the value of team's head pointer variable respectively on two different time points again, until judging the team got twice The value of head pointer variable is identical, discharges the dummy node that is updated, and by the value of the pointer variable included in the dummy node being updated Pointed node is used as new dummy node.
As a kind of preferred embodiment, the device also includes:
Second update module, the value for the value of team's head pointer variable to be updated to point to new dummy node.
As a kind of preferred embodiment, the device also includes:
4th acquisition module, the value for obtaining team's head pointer variable;
Whether the value of the pointer variable included in the 4th judge module, the dummy node pointed by value got for judgement For sky;
5th acquisition module, for being non-NULL when the value of the pointer variable included in the dummy node pointed by the value got When, then obtain the value of the pointer variable included in dummy node respectively on two different time points;
Whether the value of the pointer variable included in the 5th judge module, the dummy node got twice for judgement is identical;
Second removing module, for when the value of the pointer variable included in the dummy node got twice is different, then really The next node for determining dummy node is updated, and obtains the pointer included in dummy node respectively on two different time points again The value of variable, until the value of the pointer variable included in the dummy node that judgement is got twice is identical, deletes and is included in dummy node Pointer variable value pointed by node.
As a kind of preferred embodiment, the device also includes:
3rd update module, for the value of the pointer variable included in dummy node to be pointed to the next of deleted node Node.
As a kind of preferred embodiment, the device also includes:
Module is returned to, the value for the pointer variable included in the dummy node pointed by the value when team's head pointer variable is sky When, then return to the prompting of deletion of node failure.
The device that the present embodiment is provided, by creating the Section Point of enqueue to be added, and judges that the value got is signified To first node in the value of pointer variable that includes be non-NULL, after determining that the value of rear pointer variable is updated, reacquire Value after rear pointer variable update, until judging what is included in the first node pointed by the value after rear pointer variable update The value of pointer variable is sky, and Section Point is added into queue, and the pointer that the first node pointed by the value got is included The value of variable points to Section Point.The value when rear pointer variable is realized after queue is updated by concurrent access, still It so can continue to perform the enqueue operations of node.In addition, the value by obtaining team's head pointer variable, and the value got in judgement The value of the pointer variable included in pointed dummy node is non-NULL, and the value for team's head pointer variable that judgement is got twice is not Together, when determining that dummy node is updated, the value of team's head pointer variable is obtained respectively on two different time points again, until sentencing The value of the disconnected team's head pointer variable got twice is identical, discharges the dummy node being updated, and will be wrapped in the dummy node being updated Node pointed by the value of the pointer variable contained is as new dummy node, or deletes the value of the pointer variable included in dummy node Pointed node, realizes the next node when dummy node or dummy node after queue is updated by concurrent access, Remain able to continue executing with the dequeue operation of node.So that in the case of without be locked to queue, can be to queue in parallel Access, and then improve the efficiency of access queue.
Embodiment seven
A kind of terminal is present embodiments provided, the terminal can be used for the access method for performing queue in above-described embodiment. Referring to Fig. 9, the terminal 900 includes:
Terminal 900 can include RF (Radio Frequency, radio frequency) circuit 110, include one or more meters The memory 120 of calculation machine readable storage medium storing program for executing, input block 130, display unit 140, sensor 150, voicefrequency circuit 160, WiFi (Wireless Fidelity, Wireless Fidelity) module 170, include one or the processing of more than one processing core The part such as device 180 and power supply 190.It will be understood by those skilled in the art that the terminal structure shown in Fig. 9 is not constituted pair The restriction of terminal, can include than illustrating more or less parts, either combine some parts or different part cloth Put.Wherein:
RF circuits 110 can be used for receive and send messages or communication process in, the reception and transmission of signal, especially, by base station After downlink information is received, transfer to one or more than one processor 180 is handled;In addition, being sent to up data are related to Base station.Generally, RF circuits 110 include but is not limited to antenna, at least one amplifier, tuner, one or more oscillators, use Family identity module (SIM) card, transceiver, coupler, LNA (Low Noise Amplifier, low-noise amplifier), duplex Device etc..In addition, RF circuits 110 can also be communicated by radio communication with network and other equipment.The radio communication can make With any communication standard or agreement, and including but not limited to GSM (Global System of Mobile communication, entirely Ball mobile communcations system), GPRS (General Packet Radio Service, general packet radio service), CDMA (Code Division Multiple Access, CDMA), WCDMA (Wideband Code Division Multiple Access, WCDMA), LTE (Long Term Evolution, Long Term Evolution), Email, SMS (Short Messaging Service, Short Message Service) etc..
Memory 120 can be used for storage software program and module, and processor 180 is stored in memory 120 by operation Software program and module, so as to perform various function application and data processing.Memory 120 can mainly include storage journey Sequence area and storage data field, wherein, the application program (ratio that storing program area can be needed for storage program area, at least one function Such as sound-playing function, image player function) etc.;Storage data field can be stored uses created number according to terminal 900 According to (such as voice data, phone directory etc.) etc..In addition, memory 120 can include high-speed random access memory, it can also wrap Include nonvolatile memory, for example, at least one disk memory, flush memory device or other volatile solid-state parts. Correspondingly, memory 120 can also include Memory Controller, to provide processor 180 and input block 130 to memory 120 access.
Input block 130 can be used for the numeral or character information for receiving input, and generation to be set with user and function The relevant keyboard of control, mouse, action bars, optics or the input of trace ball signal.Specifically, input block 130 may include to touch Sensitive surfaces 131 and other input equipments 132.Touch sensitive surface 131, also referred to as touch display screen or Trackpad, collect and use (such as user is using any suitable objects such as finger, stylus or annex in touch-sensitive table for touch operation of the family on or near it Operation on face 131 or near touch sensitive surface 131), and corresponding attachment means are driven according to formula set in advance.It is optional , touch sensitive surface 131 may include both touch detecting apparatus and touch controller.Wherein, touch detecting apparatus detection is used The touch orientation at family, and the signal that touch operation is brought is detected, transmit a signal to touch controller;Touch controller is from touch Touch information is received in detection means, and is converted into contact coordinate, then gives processor 180, and can reception processing device 180 The order sent simultaneously is performed.Furthermore, it is possible to using polytypes such as resistance-type, condenser type, infrared ray and surface acoustic waves Realize touch sensitive surface 131.Except touch sensitive surface 131, input block 130 can also include other input equipments 132.Specifically, Other input equipments 132 can include but is not limited to physical keyboard, function key (such as volume control button, switch key etc.), One or more in trace ball, mouse, action bars etc..
Display unit 140 can be used for the information that is inputted by user of display or the information for being supplied to user and terminal 900 Various graphical user interface, these graphical user interface can be made up of figure, text, icon, video and its any combination. Display unit 140 may include display panel 141, optionally, can use LCD (Liquid Crystal Display, liquid crystal Show device), the form such as OLED (Organic Light-Emitting Diode, Organic Light Emitting Diode) configure display panel 141.Further, touch sensitive surface 131 can cover display panel 141, when touch sensitive surface 131 detects touching on or near it Touch after operation, send processor 180 to determine the type of touch event, with type of the preprocessor 180 according to touch event Corresponding visual output is provided on display panel 141.Although in fig .9, touch sensitive surface 131 and display panel 141 are conducts Two independent parts are inputted and input function to realize, but in some embodiments it is possible to by touch sensitive surface 131 with showing Panel 141 is integrated and realizes input and output function.
Terminal 900 may also include at least one sensor 150, such as optical sensor, motion sensor and other sensings Device.Specifically, optical sensor may include 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 141, and proximity transducer can close display when terminal 900 is moved in one's ear Panel 141 and/or backlight.As one kind of motion sensor, gravity accelerometer can detect in all directions (generally Three axles) acceleration size, size and the direction of gravity are can detect that when static, available for identification mobile phone posture application (ratio Such as horizontal/vertical screen switching, dependent game, magnetometer pose calibrating), Vibration identification correlation function (such as pedometer, tap);Extremely The other sensors such as the gyroscope, barometer, hygrometer, thermometer, the infrared ray sensor that can also configure in terminal 900, herein Repeat no more.
Voicefrequency circuit 160, loudspeaker 161, microphone 162 can provide the COBBAIF between user and terminal 900.Audio Electric signal after the voice data received conversion can be transferred to loudspeaker 161, sound is converted to by loudspeaker 161 by circuit 160 Sound signal output;On the other hand, the voice signal of collection is converted to electric signal by microphone 162, after voicefrequency circuit 160 is received Voice data is converted to, then after voice data output processor 180 is handled, through RF circuits 110 to be sent to such as another end End, or voice data is exported to memory 120 so as to further processing.Voicefrequency circuit 160 is also possible that earphone jack, To provide the communication of peripheral hardware earphone and terminal 900.
WiFi belongs to short range wireless transmission technology, and terminal 900 can help user's transceiver electronicses by WiFi module 170 Mail, browse webpage and access streaming video etc., it has provided the user wireless broadband internet and accessed.Although Fig. 9 is shown WiFi module 170, but it is understood that, it is simultaneously not belonging to must be configured into for terminal 900, can exist as needed completely Do not change in the essential scope of invention and omit.
Processor 180 is the control centre of terminal 900, utilizes various interfaces and each portion of connection whole mobile phone Point, by operation or perform and be stored in software program and/or module in memory 120, and call and be stored in memory 120 Interior data, perform the various functions and processing data of terminal 900, so as to carry out integral monitoring to mobile phone.Optionally, processor 180 may include one or more processing cores;It is preferred that, processor 180 can integrated application processor and modem processor, Wherein, application processor mainly handles operating system, user interface and application program etc., and modem processor mainly handles nothing Line communicates.It is understood that above-mentioned modem processor can not also be integrated into processor 180.
Terminal 900 also includes the power supply 190 (such as battery) powered to all parts, it is preferred that power supply can pass through electricity Management system and processor 180 are logically contiguous, so as to realize management charging, electric discharge and power consumption by power-supply management system The functions such as management.Power supply 190 can also include one or more direct current or AC power, recharging system, power supply event The random component such as barrier detection circuit, power supply changeover device or inverter, power supply status indicator.
Although not shown, terminal 900 can also include camera, bluetooth module etc., will not be repeated here.Specifically in this reality Apply in example, the display unit of terminal is touch-screen display, terminal also includes memory, and one or more than one Program, one of them or more than one program storage is configured to by one or more than one processing in memory Device is performed.One or more than one program bag, which contains, is used to perform the instruction operated below:
The Section Point of enqueue to be added is created, it is empty pointer variable that Section Point, which includes value,;
The value of rear pointer variable is obtained, and judges the pointer variable that is included in the first node pointed by the value that gets Value whether be empty;
If the value of the pointer variable included in the first node pointed by the value got is non-NULL, it is determined that rear pointer The value of variable is updated, and obtains the value after rear pointer variable update, until judging that the value after rear pointer variable update is signified To first node in the value of pointer variable that includes be sky, Section Point is added into queue, and by pointed by the value got The value of pointer variable that includes of first node point to Section Point.
Assuming that above-mentioned is the first possible embodiment, then provided based on the first possible embodiment Second of possible embodiment in, in the memory of terminal, also comprising for performing the instruction operated below:
The value of rear pointer variable is updated to point to the value of Section Point.
Based on the first or any embodiment of second of possible embodiment and provide the third In possible embodiment, in the memory of terminal, also comprising for performing the instruction operated below:
The value of team head pointer variable is obtained, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in dummy node is non-NULL, team's head is obtained respectively on two different time points The value of pointer variable, and judge whether the value of team's head pointer variable got twice is identical;
If the value of the team's head pointer variable got twice is different, it is determined that dummy node is updated, again in two differences Time point on obtain the value of team's head pointer variable respectively, until judge that the value of team's head pointer variable got twice is identical, Discharge the dummy node that is updated, and using the node pointed by the value of the pointer variable included in the dummy node being updated as new Dummy node.
In the 4th kind of possible embodiment provided based on the third possible embodiment, terminal is deposited In reservoir, also comprising for performing the instruction operated below:
The value of team's head pointer variable is updated to point to the value of new dummy node.
The 5th kind provided based on the first or any embodiment of second of possible embodiment In possible embodiment, in the memory of terminal, also comprising for performing the instruction operated below:
The value of team head pointer variable is obtained, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in the dummy node pointed by the value got is non-NULL, when two different Between obtain the value of the pointer variable included in dummy node respectively on point, and judge the pointer that is included in the dummy node got twice Whether the value of variable is identical;
If the value of the pointer variable included in the dummy node got twice is different, it is determined that the next node of dummy node It is updated, obtains the value of the pointer variable included in dummy node respectively on two different time points again, until judges two The value of the pointer variable included in the secondary dummy node got is identical, pointed by the value for deleting the pointer variable included in dummy node Node.
In the 6th kind of possible embodiment provided based on the 5th kind of possible embodiment, terminal is deposited In reservoir, also comprising for performing the instruction operated below:
The value of the pointer variable included in dummy node is pointed to the next node of deleted node.
The 7th kind provided based on the third or any embodiment of the 5th kind of possible embodiment In possible embodiment, in the memory of terminal, also comprising for performing the instruction operated below:
If the value of the pointer variable included in the dummy node pointed by the value of team's head pointer variable is sky, returns and delete section The prompting of point failure.
The terminal that the present invention is provided, by creating the Section Point of enqueue to be added, and judges pointed by the value that gets First node in the value of pointer variable that includes be non-NULL, after determining that the value of rear pointer variable is updated, reacquire team Value after tail pointer variable update, until judging the finger included in the first node pointed by the value after rear pointer variable update The value of pin variable is sky, and Section Point is added into queue, and the pointer that the first node pointed by the value got is included becomes The value of amount points to Section Point.The value when rear pointer variable is realized after queue is updated by concurrent access, still It can continue to perform the enqueue operations of node.In addition, the value by obtaining team's head pointer variable, and the value institute got in judgement The value of the pointer variable included in the dummy node of sensing is non-NULL, judges the value difference of team's head pointer variable got twice, When determining that dummy node is updated, the value of team's head pointer variable is obtained respectively on two different time points again, until judging The value of the team's head pointer variable got twice is identical, discharges the dummy node being updated, and will be included in the dummy node being updated Pointer variable value pointed by node as new dummy node, or delete the value institute of the pointer variable included in dummy node The node of sensing, realizes the next node when dummy node or dummy node after queue is updated by concurrent access, still It so can continue to perform the dequeue operation of node.So as in the case of without being locked to queue, visit queue in parallel Ask, and then improve the efficiency of access queue.
Embodiment eight
The embodiment of the present invention additionally provides a kind of computer-readable recording medium, and the computer-readable recording medium can be The computer-readable recording medium included in memory in above-described embodiment;Can also be individualism, without supplying eventually Computer-readable recording medium in end.The computer-readable recording medium storage has one or more than one program, and this one Individual or more than one program is used for performing the authority issuer for realizing multidimensional data by one or more than one processor Method, this method includes:
The Section Point of enqueue to be added is created, it is empty pointer variable that Section Point, which includes value,;
The value of rear pointer variable is obtained, and judges the pointer variable that is included in the first node pointed by the value that gets Value whether be empty;
If the value of the pointer variable included in the first node pointed by the value got is non-NULL, it is determined that rear pointer The value of variable is updated, and obtains the value after rear pointer variable update, until judging that the value after rear pointer variable update is signified To first node in the value of pointer variable that includes be sky, Section Point is added into queue, and by pointed by the value got The value of pointer variable that includes of first node point to Section Point.
Assuming that above-mentioned is the first possible embodiment, then provided based on the first possible embodiment Second of possible embodiment in, it is described that the Section Point is added into the queue, and by pointed by the value got The value of pointer variable that includes of first node point to the Section Point after, in addition to:
The value of rear pointer variable is updated to point to the value of the Section Point.
The third the possible embodiment provided based on the first or second of possible embodiment In, a dummy node is also included outside the queue, the dummy node includes pointer variable, and the queue also includes team's head and referred to Pin variable, the value of team's head pointer variable is used to point to the dummy node, and methods described also includes:
The value of team head pointer variable is obtained, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in dummy node is non-NULL, team's head is obtained respectively on two different time points The value of pointer variable, and judge whether the value of team's head pointer variable got twice is identical;
If the value of the team's head pointer variable got twice is different, it is determined that dummy node is updated, again in two differences Time point on obtain the value of team's head pointer variable respectively, until judge that the value of team's head pointer variable got twice is identical, Discharge the dummy node that is updated, and using the node pointed by the value of the pointer variable included in the dummy node being updated as new Dummy node.
It is described by institute in the 4th kind of possible embodiment provided based on the third possible embodiment State after node updates pointed by the value of the pointer variable included in dummy node are new dummy node, in addition to:
The value of team's head pointer variable is updated to point to the value of the new dummy node.
The 5th kind of possible embodiment provided based on the first or second of possible embodiment In, a dummy node is also included outside the queue, the queue also includes team's head pointer variable, team's head pointer variable It is worth for pointing to the dummy node, methods described also includes:
The value of team head pointer variable is obtained, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in the dummy node pointed by the value got is non-NULL, when two different Between obtain the value of the pointer variable included in dummy node respectively on point, and judge the pointer that is included in the dummy node got twice Whether the value of variable is identical;
If the value of the pointer variable included in the dummy node got twice is different, it is determined that the next node of dummy node It is updated, obtains the value of the pointer variable included in dummy node respectively on two different time points again, until judges two The value of the pointer variable included in the secondary dummy node got is identical, pointed by the value for deleting the pointer variable included in dummy node Node.
It is described to delete in the 6th kind of possible embodiment provided based on the 5th kind of possible embodiment After node pointed by the value of the pointer variable included in the dummy node, in addition to:
The value of the pointer variable included in dummy node is pointed to the next node of deleted node.
The 5th kind of possible embodiment provided based on the third or the 5th kind of possible embodiment In, after whether the value of the pointer variable for judging to include in the dummy node that gets is sky, in addition to:
If the value of the pointer variable included in the dummy node pointed by the value of team's head pointer variable is sky, returns and delete section The prompting of point failure.
Computer-readable recording medium provided in an embodiment of the present invention, by creating the Section Point of enqueue to be added, and The value for judging the pointer variable included in the first node pointed by the value got is non-NULL, determines the value of rear pointer variable After being updated, the value after rear pointer variable update is reacquired, until judging pointed by the value after rear pointer variable update First node in the value of pointer variable that includes be sky, Section Point is added into queue, and by pointed by the value got The value for the pointer variable that first node is included points to Section Point.The value when rear pointer variable is realized because queue is visited parallel After asking and updating, remain able to continue executing with the enqueue operations of node.In addition, the value by obtaining team's head pointer variable, And the value of the pointer variable included in the dummy node pointed by the value for judging to get is non-NULL, the team got twice is judged The value of head pointer variable is different, when determining that dummy node is updated, and obtains team's head respectively on two different time points again and refers to The value of pin variable, until judge that the value of team's head pointer variable got twice is identical, discharges the dummy node being updated, and will be by Node pointed by the value of the pointer variable included in the dummy node of renewal is as new dummy node, or deletes bag in dummy node Node pointed by the value of the pointer variable contained, realizes the next node when dummy node or dummy node because queue is visited parallel After asking and updating, remain able to continue executing with the dequeue operation of node.So as in the situation without being locked to queue Under, queue in parallel can be accessed, and then improve the efficiency of access queue.
Embodiment nine
The embodiments of the invention provide a kind of graphical user interface, the graphical user interface is with terminal, the end End includes touch-screen display, memory and for execution one or one of more than one program or more than one Processor;The graphical user interface includes:
The Section Point of enqueue to be added is created, it is empty pointer variable that Section Point, which includes value,;
The value of rear pointer variable is obtained, and judges the pointer variable that is included in the first node pointed by the value that gets Value whether be empty;
If the value of the pointer variable included in the first node pointed by the value got is non-NULL, it is determined that rear pointer The value of variable is updated, and obtains the value after rear pointer variable update, until judging that the value after rear pointer variable update is signified To first node in the value of pointer variable that includes be sky, Section Point is added into queue, and by pointed by the value got The value of pointer variable that includes of first node point to Section Point.
Graphical user interface provided in an embodiment of the present invention, by creating the Section Point of enqueue to be added, and judges to obtain The value of the pointer variable included in the first node pointed by value got is non-NULL, determines that the value of rear pointer variable is updated Afterwards, the value after rear pointer variable update is reacquired, until judging first pointed by the value after rear pointer variable update The value of the pointer variable included in node is sky, and Section Point added into queue, and by the first segment pointed by the value got The value for the pointer variable that point is included points to Section Point.The value when rear pointer variable is realized because queue is sent out by concurrent access After raw renewal, remain able to continue executing with the enqueue operations of node.In addition, the value by obtaining team's head pointer variable, and sentencing The value of the pointer variable included in dummy node pointed by the disconnected value got is non-NULL, judges the team's head pointer got twice The value of variable is different, when determining that dummy node is updated, obtains team's head pointer variable respectively on two different time points again Value, until judge that the value of team's head pointer variable got twice is identical, discharge the dummy node being updated, and will be updated Node pointed by the value of the pointer variable included in dummy node is as new dummy node, or deletes the finger included in dummy node Node pointed by the value of pin variable, realizes the next node when dummy node or dummy node because queue is sent out by concurrent access After raw renewal, remain able to continue executing with the dequeue operation of node.So that in the case of without be locked to queue, can be right Queue in parallel is accessed, and then improves the efficiency of access queue.
It should be noted that:The access mechanism for the queue that above-described embodiment is provided is in access queue, only with above-mentioned each work( The division progress of energy module is for example, in practical application, as needed can distribute above-mentioned functions by different functions Module is completed, i.e., the internal structure of device is divided into different functional modules, described above all or part of to complete Function.In addition, the access mechanism of queue and the access method embodiment of queue that above-described embodiment is provided belong to same design, its The process of implementing refers to embodiment of the method, repeats no more here.
The embodiments of the present invention are for illustration only, and the quality of embodiment is not represented.
One of ordinary skill in the art will appreciate that realizing that all or part of step of above-described embodiment can be by hardware To complete, the hardware of correlation can also be instructed to complete by program, described program can be stored in a kind of computer-readable In storage medium, storage medium mentioned above can be read-only storage, disk or CD etc..
The foregoing is only presently preferred embodiments of the present invention, be not intended to limit the invention, it is all the present invention spirit and Within principle, any modification, equivalent substitution and improvements made etc. should be included in the scope of the protection.

Claims (10)

1. a kind of queue access method, it is characterised in that first node, a rear pointer variable are comprised at least in the queue With team's head pointer variable, the value of the rear pointer variable is used for the tail node for pointing to the queue, and the tail node is first Node, the value of team's head pointer variable is used to point to dummy node, and the dummy node is outside the queue, and the queue is included Each first node in comprise at least pointer variable, the value of the pointer variable is currently located node for sensing and connected The next node connect, the value for the pointer variable that tail node is included is sky, and methods described includes:
The Section Point of the queue to be added is created, it is empty pointer variable that the Section Point, which includes value,;
Obtain the value of the rear pointer variable, and judge the pointer variable that is included in the first node pointed by the value got Value whether be empty;
If the value of the pointer variable included in the first node pointed by the value got is non-NULL, it is determined that the rear pointer The value of variable is updated, and obtains the value after the rear pointer variable update, until judging after the rear pointer variable update Value pointed by first node in the value of pointer variable that includes be sky, the Section Point is added into the queue, and will The value for the pointer variable that the first node pointed by value got is included points to the Section Point;
Obtain the value of team's head pointer variable, and the pointer variable for judging to include in the dummy node pointed by the value got Whether value is empty;
If the value of the pointer variable included in the dummy node is non-NULL, obtain described respectively on two different time points The value of team's head pointer variable, and judge whether the value of team's head pointer variable got twice is identical;If getting twice Team's head pointer variable value it is different, it is determined that the dummy node is updated, again on two different time points point The value of team's head pointer variable is not obtained, until the value for team's head pointer variable that judgement is got twice is identical, release The dummy node being updated, and using the node pointed by the value of the pointer variable included in the dummy node being updated as new Dummy node, the new dummy node is not belonging to the queue;Or,
If the value of the pointer variable included in the dummy node is non-NULL, obtain described respectively on two different time points The value of the pointer variable included in dummy node, and judge that the value of the pointer variable included in the dummy node that gets twice is It is no identical;If the value of the pointer variable included in the dummy node got twice is different, it is determined that under the dummy node One node is updated, and obtains the pointer variable that is included in the dummy node respectively on two different time points again Value, until the value of the pointer variable included in the dummy node that judgement is got twice is identical, deletes in the dummy node and wraps Node pointed by the value of the pointer variable contained.
2. according to the method described in claim 1, it is characterised in that described that the Section Point is added into the queue, and general The value for the pointer variable that the first node pointed by value got is included is pointed to after the Section Point, in addition to:
The value of the rear pointer variable is updated to point to the value of the Section Point.
3. according to the method described in claim 1, it is characterised in that the value by the pointer variable included in the dummy node Pointed node updates be new dummy node after, in addition to:
The value of team's head pointer variable is updated to point to the value of the new dummy node.
4. according to the method described in claim 1, it is characterised in that the pointer variable included in the deletion dummy node After the pointed node of value, in addition to:
The value of the pointer variable included in the dummy node is pointed to the next node of deleted node.
5. according to the method described in claim 1, it is characterised in that the pointer included in the dummy node for judging to get becomes After whether the value of amount is sky, in addition to:
If the value of the pointer variable included in the dummy node pointed by the value of team's head pointer variable is sky, returns and delete section The prompting of point failure.
6. a kind of access mechanism of queue a, it is characterised in that first node, rear pointer are comprised at least in the queue and is become Amount and team's head pointer variable, the value of the rear pointer variable are used for the tail node for pointing to the queue, and the tail node is the One node, the value of team's head pointer variable is used to point to dummy node, and the dummy node is outside the queue, the queue bag A pointer variable is comprised at least in each first node contained, the value of the pointer variable is currently located node institute for sensing The next node of connection, the value for the pointer variable that tail node is included is sky, and described device includes:
Creation module, the Section Point for creating the queue to be added, the Section Point includes value and become for empty pointer Amount;
First acquisition module, the value for obtaining the rear pointer variable;
First judge module, for the value of pointer variable that judges to include in the first node pointed by the value that gets whether be It is empty;
Add module, for when the pointer variable included in the first node pointed by the value got value be non-NULL when, then Determine that the value of the rear pointer variable is updated, obtain the value after the rear pointer variable update, until judging the team The value of the pointer variable included in the first node pointed by value after tail pointer variable update is sky, and the Section Point is added Enter the queue, and the value for the pointer variable that the first node pointed by the value got is included points to the Section Point;
Described device also includes:
Second acquisition module, the value for obtaining team's head pointer variable;
Second judge module, for the value of pointer variable that judges to include in the dummy node pointed by the value that gets whether be It is empty;
3rd acquisition module, it is for when the value of the pointer variable included in the dummy node is non-NULL, then different at two The value of team's head pointer variable is obtained on time point respectively;3rd judge module, for the team for judging to get twice Whether the value of head pointer variable is identical;First removing module, for the value of team's head pointer variable that ought get twice not Simultaneously, it is determined that the dummy node is updated, team's head pointer variable is obtained respectively on two different time points again Value, until judging that the value of team's head pointer variable got twice is identical, discharge the dummy node being updated, and will be described Node pointed by the value of the pointer variable included in the dummy node being updated is as new dummy node, and the new dummy node is not Belong to the queue;Or,
Described device also includes:
4th acquisition module, the value for obtaining team's head pointer variable;
4th judge module, for the value of pointer variable that judges to include in the dummy node pointed by the value that gets whether be It is empty;
5th acquisition module, for when the pointer variable included in the dummy node pointed by the value got value be non-NULL when, Then obtain the value of the pointer variable included in the dummy node respectively on two different time points;
Whether the value of the pointer variable included in the 5th judge module, the dummy node got twice for judgement is identical;
Second removing module, for when the value of the pointer variable included in the dummy node got twice is different, then really The next node of the fixed dummy node is updated, and is obtained in the dummy node and is wrapped respectively on two different time points again The value of the pointer variable contained, until the value of the pointer variable included in the dummy node that judgement is got twice is identical, is deleted Node pointed by the value of the pointer variable included in the dummy node.
7. device according to claim 6, it is characterised in that described device also includes:
First update module, the value for the value of the rear pointer variable to be updated to point to the Section Point.
8. device according to claim 6, it is characterised in that described device also includes:
Second update module, the value for the value of team's head pointer variable to be updated to point to the new dummy node.
9. device according to claim 6, it is characterised in that described device also includes:
3rd update module, the value of the pointer variable for will be included in the dummy node points to the next of deleted node Node.
10. device according to claim 6, it is characterised in that described device also includes:
Module is returned to, the value for the pointer variable included in the dummy node pointed by the value when team's head pointer variable is sky When, then return to the prompting of deletion of node failure.
CN201410033780.XA 2014-01-23 2014-01-23 The access method and device of queue Active CN103793267B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410033780.XA CN103793267B (en) 2014-01-23 2014-01-23 The access method and device of queue

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410033780.XA CN103793267B (en) 2014-01-23 2014-01-23 The access method and device of queue

Publications (2)

Publication Number Publication Date
CN103793267A CN103793267A (en) 2014-05-14
CN103793267B true CN103793267B (en) 2017-07-21

Family

ID=50668979

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410033780.XA Active CN103793267B (en) 2014-01-23 2014-01-23 The access method and device of queue

Country Status (1)

Country Link
CN (1) CN103793267B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111625376B (en) * 2017-04-01 2023-08-04 北京忆芯科技有限公司 Method and message system for queue communication through proxy
CN110046049A (en) * 2018-01-15 2019-07-23 迈普通信技术股份有限公司 Queue management method, device and data communications equipment
CN108830724B (en) * 2018-04-12 2023-04-14 平安科技(深圳)有限公司 Resource data packet processing method and terminal equipment
CN111488496B (en) * 2020-04-30 2023-07-21 湖北师范大学 Sliding window-based Tango tree construction method and system
CN111814007B (en) * 2020-07-31 2023-03-31 新华三信息安全技术有限公司 Method, device and equipment for processing data of doubly-linked list and machine-readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6032207A (en) * 1996-12-23 2000-02-29 Bull Hn Information Systems Inc. Search mechanism for a queue system
CN101183304A (en) * 2006-11-13 2008-05-21 国际商业机器公司 Concurrent, non-blocking, lock-free queue and method, apparatus, and computer program product for implementing same
CN103262036A (en) * 2010-12-17 2013-08-21 英特尔公司 Non-blocking wait-free data-parallel scheduler

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6032207A (en) * 1996-12-23 2000-02-29 Bull Hn Information Systems Inc. Search mechanism for a queue system
CN101183304A (en) * 2006-11-13 2008-05-21 国际商业机器公司 Concurrent, non-blocking, lock-free queue and method, apparatus, and computer program product for implementing same
CN103262036A (en) * 2010-12-17 2013-08-21 英特尔公司 Non-blocking wait-free data-parallel scheduler

Also Published As

Publication number Publication date
CN103793267A (en) 2014-05-14

Similar Documents

Publication Publication Date Title
CN103942113B (en) The detection method of system reboot reason, device and terminal unit
CN103389863B (en) A kind of display control method and device
CN105278937B (en) A kind of method and device showing pop-up box message
CN106708554B (en) Program operating method and device
CN104519404B (en) The player method and device of graphic interchange format file
CN104142868B (en) Establish the method and device of connection
CN103365419B (en) A kind of method and apparatus triggering alarm clock control command
CN103793267B (en) The access method and device of queue
CN103455603A (en) Method and device for caching webpage content and loading webpage and terminal device
CN104363988B (en) A kind of management method and device of multi-core processor
CN106371900A (en) Data processing method and device for realizing asynchronous call
CN106775833A (en) device driver loading method, terminal and system
CN106775267A (en) A kind of method and apparatus of the function menu for showing game plug-in unit
CN106951143A (en) The method and device of hiden application icon
CN107145386A (en) Data migration method, terminal device and computer-readable recording medium
CN107423050A (en) A kind of method and apparatus for penetrating operation
CN104901992A (en) Resource transfer method and device
CN105577712B (en) A kind of file uploading method, device and system
CN105022621A (en) Method and device for collecting session message and terminal
CN104216935B (en) The method and terminal of a kind of ff
CN106534998A (en) Video communication interface display method, device and system
CN105872041B (en) The processing method and processing device of operation object
CN109451295A (en) A kind of method and system obtaining virtual information
CN103561119B (en) Obtain method, device and the equipment of Media Access Control address
CN104683553B (en) The management method and device of refuse messages

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