Read lock method of operating, write lock operation method and system
Technical field
The application relates to Computer Systems Organization technical field, particularly a kind of read lock method of operating, write lock operation method and system.
Background technology
Thread (thread), being also referred to as Lightweight Process (Lightweight Process, LWP), is the control flow check of certain single order in process, and as the minimum unit that program performs.In the operating system introducing thread, usually using the base unit of process as Resources allocation, using thread as independent operating and the independent base unit dispatched.Thread can concurrence performance, and such as, multiple threads in a process can concurrence performance.Thread in different process also can concurrence performance.Especially, calculate in the computer system of core, such as have in the computer system of multiple core cpu, the thread of different core also can concurrence performance more.
During multiple thread concurrence performance, often need to access same data.From the data that this is accessed, this data sharing is to different threads.When these shared data of multiple thread accesses, need the integrality ensureing these shared data.Such as, shared data can not be revised by two threads simultaneously; A thread can not read the shared data that have modified half.Classical mode uses lock (Lock) mechanism.Such as, carry out for these data add " read lock " in the process of read operation at thread to data, at thread, data are carried out in the process of write operation as these data add " writing lock ".Before process carries out read operation to data, first to this data read lock, after read operation performs and finishes, then separate read lock.Similar, before process carries out write operation to data, first add these data and write lock, after write operation performs and finishes, then solution writes lock.Usual read_ref, as the reference count of read operation thread, represents the ID of write operation thread with writer_ID.
What perform same data for different threads is all read operation, can add repeatedly read lock.Such as, thread 1 will perform read operation to data, then, before execution read operation, to this data read lock, the data type specifically value of read_ref being added 1(such as read_ref is shaping, and initial value is 0), afterwards these data are read.In the process read, thread 2 also will perform read operation to same data, then the value of read_ref is added 1, and read these data.Then now the value of read_ref is 2.After the read operation of thread 1 is finished, the value of read_ref is subtracted 1, and separates read lock.Now, the value of read_ref is 1.Afterwards, the read operation of thread 2 to these data is finished, and the value of read_ref is subtracted 1, and separates read lock.Now, the value of read_ref is 0.Can repeat to add to the read lock of same data, therefore, between read lock, there is sharing.
What perform same data for different threads is all write operation, can only add and once write lock.Such as, thread 1 will perform write operation to data, then, before execution write operation, add these data and write lock, the data type specifically value of writer_ID being updated to the ID(such as writer_ID of thread 1 is shaping, and initial value is 0; The ID of arbitrary thread is not 0), afterwards write operation is carried out to these data.In the process write, thread 2 also will perform write operation to same data, but because of writer_ID at time be not 0, therefore thread 2 can not add and writes lock, can not carry out write operation to these data.After the write operation of thread 1 is finished, solution writes lock, and the value by writer_ID is updated to 0.Thread 2 previous add to write to lock unsuccessfully and after waiting for a period of time, learn writer_ID at time be 0, can add and write lock.Afterwards, the value of writer_ID is updated to the ID of thread 2, carries out write operation afterwards to these data.After the write operation of thread 2 is finished, solution writes lock, and the value by writer_ID is updated to 0.Visible, writing lock and cannot repeat to add same data, therefore, writes between lock and has alternative.
In addition, write lock and read lock is also mutual exclusion, namely at any one time, read lock added to same data and just can not add again and write lock, added write lock can not read lock again.Like this, a certain thread, before carrying out read operation to data, needs whether the writer_ID value checking these data is 0.If be 0, just read operation can be carried out; If be not 0, need to wait for that writer_ID value becomes 0.Similar, a certain thread, before carrying out write operation to data, needs whether the read_ref value checking these data is 0.If be 0, just write operation can be carried out; If be not 0, need to wait for that read_ref value becomes 0.In fact, for read lock, under more susceptible condition, be write operation and latching operation is write in adding of carrying out to avoid having another thread simultaneously between the operation checking writer_ID value and corresponding read operation further, namely the collision detection caused in this kind of situation was lost efficacy, whether add after 1 by the value of read_ref, be also 0 by this writer_ID value again checked now.If be not 0, just perform read operation.Similar, lock is write for adding, under more susceptible condition, be read operation and the read lock that carries out operates to avoid having another thread simultaneously between the operation checking read_ref value and corresponding write operation further, namely the collision detection caused in this kind of situation was lost efficacy, after the value of writer_ID is updated to the ID writing thread, whether be also 0 by this read_ref value again checked now.If be not 0, just perform write operation.
Above-mentioned thread is changed the value of read_ref value, writer_ID, belongs to atomic operation.Atomic operation is generally the instruction that CPU provides, and has inseparability.A thread, when an execution atomic operation, can not be interrupted by other thread, can not be switched to other threads.In other words, this atomic operation once, just run to this operation always and terminate.
Realizing in the application's process, inventor finds that in prior art, at least there are the following problems:
Calculate in the computer system of core, the thread of different core may perform reading and writing operation to same data more.Particularly often there will be in a period of time and a large amount of read operation is performed to same data, and there is no the situation of write operation.The general corresponding buffer memory (cache) of each core.Each core safeguards a read_ref value in the buffer memory of its correspondence.Further, the implementation conventionally, the read_ref value in the buffer memory that each core is corresponding will be consistent.Like this, for the computer system calculating core, the read_ref value in the buffer memory that core is corresponding, with other core communication to notify this change once after changing more.Read_ref value in self corresponding buffer memory of the notified rear renewal of other core.
Like this, this mode of the prior art, when causing multiple threads of different core to carry out read operation to same data, because the communication between core will spend certain hour, the atomic operation changing read_ref value in the corresponding buffer memory of each core needs to spend certain hour, and thus execution efficiency is lower.
Summary of the invention
The object of the embodiment of the present application is to provide a kind of read lock method of operating, writes lock operation method and system, to improve execution efficiency.
For solving the problems of the technologies described above, the embodiment of the present application provides a kind of read lock method of operating, write lock operation method and system is achieved in that
A kind of read lock method of operating, comprising:
The privately owned reference count that each core is corresponding is set;
Carry out in reading process at the thread of different core to same data, carry out read lock with the privately owned reference count that different core is corresponding, understand latching operation.
A kind of read lock operating system, comprises data cell, a buffer unit, the second buffer unit, and first calculates core and second calculates core, wherein,
Data cell, for storing data;
First buffer unit, for saving as the first privately owned reference count of the distribution of the first calculating core;
Second buffer unit, for saving as the second privately owned reference count of the distribution of the second calculating core;
First calculates core and second calculates core, for reading the same data in described data cell; And,
First thread calculating core carries out in reading process to described data, carries out read lock with the privately owned reference count that the first core is corresponding, understands latching operation;
Second thread calculating core carries out in reading process to described data, carries out read lock with the privately owned reference count that the second core is corresponding, understands latching operation.
One writes lock operation method, comprising:
Before write operation is performed to data, judge the read operation process whether existed in all calculating cores these data;
Before write operation is performed to data, judge whether described data are in another write operation process;
If above-mentioned two judged results are no, then these data are carried out in the process of write operation, with described global write be locked into row add write lock, operation that solution writes lock.
One writes latching operation system, comprises data cell, the first judging unit, the second judging unit, adds, solution writes lock unit, wherein,
Data cell, for storing data;
First judging unit, for before performing write operation to data, judges the read operation process whether existed in all calculating cores these data;
Second judging unit, for before performing write operation to data, judges whether described data are in another write operation process;
Add, solution write lock unit, for when the judged result of the first judging unit and the second judging unit is all no, described data are being carried out in the process of write operation, with described global write be locked into row add write lock, operation that solution writes lock.
The technical scheme provided from above the embodiment of the present application, when the embodiment of the present application makes the thread of different core carry out read operation to same data, independently corresponding to this core privately owned reference count operation.The privately owned reference count that these different cores are corresponding does not need between each core synchronous, and therefore execution efficiency gets a promotion.And the extendability of read lock is also improved, namely no matter the thread of how many cores concurrently adds, separates read lock, and adding the time of separating read lock nearly all can not increase, thus improves execution efficiency.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present application or technical scheme of the prior art, be briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, the accompanying drawing that the following describes is only some embodiments recorded in the application, for those of ordinary skill in the art, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to these accompanying drawings.
Fig. 1 is the process flow diagram of the application's read lock method of operating embodiment;
Fig. 2 is the module map of the application's read lock operating system embodiment;
Fig. 3 is the process flow diagram that the application writes a lock operation method embodiment;
Fig. 4 is the module map that the application writes a latching operation system embodiment.
Embodiment
The embodiment of the present application provides a kind of read lock method of operating, writes lock operation method and system.
Technical scheme in the application is understood better in order to make those skilled in the art person, below in conjunction with the accompanying drawing in the embodiment of the present application, technical scheme in the embodiment of the present application is clearly and completely described, obviously, described embodiment is only some embodiments of the present application, instead of whole embodiments.Based on the embodiment in the application, those of ordinary skill in the art are not making the every other embodiment obtained under creative work prerequisite, all should belong to the scope of the application's protection.
First an embodiment of the application's read lock method of operating is introduced.
Fig. 1 shows the process flow diagram of the application's read lock method of operating embodiment.As shown in Figure 1, the method for this embodiment comprises:
S100: the privately owned reference count that each core is corresponding is set.
Modern CPU have employed the delay that a large amount of technology is brought to offset internal storage access.During read/write memory data, CPU can perform hundreds and thousands of instructions.Multistage static RAM (Static Random Access Memory, SRAM) buffer memory (hereinafter referred to as buffer memory) is the Main Means reducing the impact that this delay brings.
Such as, for the computer system of double-core, core 1 and core 2 have corresponding buffer memory 1 and buffer memory 2 respectively.Described buffer memory can be the buffer memory calculating core.Such as, for CPU, CPU inside is usually with level cache, L2 cache, and the CPU even had is also with three grades of buffer memorys.The CPU comprising level cache, L2 cache, CPU are needed to the data of operation, a kind of situation is first read into L2 cache from internal memory, then be read into level cache from L2 cache, then be read into CPU from level cache and perform.In general, the closer to the storer of CPU, speed is faster, but cost is also higher; More away from the storer of CPU, speed is slower, but cost is also more cheap.Generally in the storer near CPU, store CPU and read and write data frequently, to improve the utilization factor of the high storer of cost.
In this step, preferably, privately owned reference count (private_read_ref) can be placed in buffer memory.Such as, privately owned reference count can be arranged in the level cache of CPU.Certainly, depending on the architectural framework of CPU and the capacity of storer not at the same level, also can privately owned reference count be arranged in L2 cache, other reading speed and CPU atomic operation speed can also be arranged on in the storer of magnitude.The embodiment of the present application is not particularly limited to this.In fact, buffer memory is often transparent to program, and that is whether program can not control a variable and will be put in buffer memory, and will be placed on which rank of buffer memory.When program will operate a variable, CPU can check this variable whether in level cache, if had, directly reads from first-level buffer; If no, can check whether in L2 cache: if had, variable is loaded into level cache from L2 cache, if L2 cache does not have, variable is loaded in L2 cache and level cache from internal memory yet.
In prior art, different threads, to the read operation of same data, relates to same reference count, namely operates same reference count.This reference count read_ref, is called overall read_ref according to computer realm general rule.Particularly the different threads of same calculating core, comprises the different threads in same process, or the different threads in different process, when carrying out read operation to same data, carries out from adding (++) or certainly subtracting (--) operation same overall read_ref.If in multi-core computer system, for the situation of multiple core, still only adopt a global reference count, then there will be the problem obtained as analyzed in background technology.
In this step, for different core, for each core arranges privately owned application count.Such as, for core 1, arranging the privately owned reference count of its correspondence, such as, is read_ref_core1; For core 2, also arranging the privately owned reference count of its correspondence, such as, is read_ref_core2.For the situation also comprising other core, can the rest may be inferred.
For the privately owned reference count that each core is corresponding, can not forever (or being referred to as to fix) distribute, but interim distribution.Such as, can to carry out data distributing before read lock first at the thread of each core; This privately owned reference count is regained after the read operation of thread to these data of this core is finished.Concrete, the array [read_ref] of a privately owned reference count can be set.To carry out first before read lock to data at the thread of each core, application distributes should in [read_ref] array one.It is enough large that the space of this array [read_ref] can be arranged.In array, each can be set to shaping (int).In array, the initial value of each can be initialized as 0.Certainly, for the read operation of a certain data, also can by each fixed allocation in [read_ref] array to each core.
Preferably, in practical operation, each in [read_ref] array can be assigned in a cache lines in buffer memory (cache line).Cache lines is the minimum unit that multi-core CPU safeguards buffer consistency, is also the effective unit that internal memory exchanges.In the middle of reality, a cache lines on most of platform is greater than 8 bytes, and most cache lines is 64 bytes.If [read_ref] array define is int type, be then 8 bytes.Visible, a cache lines can store 8 read_ref.If store the situation of a more than read_ref in a cache lines, then just have conflict during different element in groups of operands.In order to avoid conflict, each read_ref in [read_ref] array can be stored in a cache lines.Such as, each in [read_ref] array can be claimed as a structure, state that a structure size is 64 bytes simultaneously.Like this, each in [read_ref] array all monopolizes a cache lines, can avoid producing conflict during operation.
S110: carry out in reading process to same data at the thread of different core, carries out read lock with the privately owned reference count that different core is corresponding, understands latching operation.
Such as, same computer system comprises 2 and calculates core, is respectively core 1 and core 2.Again such as, core 1 and core 2 all will read same data.According to S100, core 1 can apply for 1 privately owned reference count, is labeled as read_ref_core1; Similar, core 2 also respectively can apply for 1 privately owned reference count, as being read_ref_core2.
Like this, carry out, in reading process, first carrying out read lock to these data at the thread of core 1.That is, the privately owned reference count read_ref_core1 of core 1 performs and adds 1 operation.Like this, read_ref_core1 becomes 1 from initial value 0.Afterwards, the thread of core 1 reads these data.After read operation is finished, carry out deciphering latching operation.That is, the privately owned reference count read_ref_core1 of core 1 performs and subtracts 1 operation.Like this, read_ref_core1 becomes 0 from 1.
Similar, carry out, in reading process, first carrying out read lock to these data at the thread of core 2.That is, the privately owned reference count read_ref_core2 of core 2 performs and adds 1 operation.Like this, read_ref_core2 becomes 1 from initial value 0.Afterwards, the thread of core 2 reads these data.After read operation is finished, carry out deciphering latching operation.That is, the privately owned reference count read_ref_core2 of core 2 performs and subtracts 1 operation.Like this, read_ref_core2 becomes 0 from 1.
The aforesaid way that the embodiment of the present application adopts, when making the thread of different core carry out read operation to same data, independently corresponding to this core privately owned reference count operation.The privately owned reference count that these different cores are corresponding does not need between each core synchronous, and therefore execution efficiency gets a promotion.And the extendability of read lock is also improved, namely no matter the thread of how many cores concurrently adds, separates read lock, and adding the time of separating read lock nearly all can not increase.
In addition, the privately owned reference count that different core is corresponding does not need between each core synchronous, eliminates the communication process between each core, thus eliminates the expense of the bandwidth, time etc. needed for intercore communication.
Described S110 specifically can comprise the steps:
The thread of the S111: the first core carries out in reading process to data, carries out read lock with the privately owned reference count that the first core is corresponding, understands latching operation.
The thread of the S112: the second core carries out in reading process to described data, carries out read lock with the privately owned reference count that the second core is corresponding, understands latching operation.
The above-mentioned read lock operation carried out with privately owned reference count, specifically comprises: the process of different core performs with the privately owned reference count that each core is corresponding and adds 1 operation.The deciphering latching operation carried out with privately owned reference count, specifically comprises: the process of different core performs with the privately owned reference count that each core is corresponding and subtracts 1 operation.Conciliate between read lock operation at read lock, the process of each core can read described data.
It should be noted that, multiple different threads of same core carry out the process of read operation to same data, can perform read lock, understand latching operation with same privately owned counter.Such as, carry out, in reading process, first carrying out read lock to these data at the thread 1 of core 1.The privately owned reference count read_ref_core1 of core 1 performs and adds 1 operation.Like this, read_ref_core1 becomes 1 from initial value 0.Afterwards, the thread 1 of core 1 reads these data.In the process that the thread 1 of core 1 reads these data, the thread 2 of core 1 also will perform read operation to same data, then the value of read_ref_core1 is added 1, and read these data.Then now the value of read_ref is 2.After the read operation of the thread 1 of core 1 is finished, the value of read_ref_core1 is subtracted 1, separate read lock.Now, the value of read_ref_core1 becomes 1.Afterwards, the read operation of thread 2 to these data of core 1 is finished, and the value of read_ref_core1 is subtracted 1, separates read lock.Now, the value of read_ref_core1 becomes 0.Like this, for same core, no matter its how many threads concurrently add, separate read lock, and adding the time of separating read lock nearly all can not increase.
Also it should be noted that, in order to avoid the inconsistent situation of data occurs, the read lock in the embodiment of the present application, still with write that to lock be mutual exclusion.Such as, have in the computer system of multiple core, a global write lock is set, as being global_writer_id.A certain thread will perform write operation to data, then, before execution write operation, add write lock to these data.Such as, the data type that the value of global_writer_id is updated to the ID(such as global_writer_id of thread 1 by the thread 1 of a certain core is shaping, and initial value is 0; The ID of arbitrary thread is not 0), afterwards write operation is carried out to these data.In the process write, the thread of a certain core (can be same core or different core with the last thread writing lock that adds), referred to herein as thread 2, will perform read operation to same data, and application is to should the privately owned reference count of core.This privately owned reference count is such as initialized as 0.But, because of global_writer_id at time be not 0, therefore thread 2 can not read lock, can not carry out read operation to these data.After the write operation of thread 1 is finished, solution writes lock, and the value by global_writer_id is updated to 0.Thread 2 is in the failure of previous read lock and after waiting for a period of time, learn global_writer_id at time be 0, can read lock.Thread 2 also may, after previous read lock failure, be attempted carrying out read lock at regular intervals; When the value of global_writer_id is 0, the success of retry read lock.Like this, the value of the privately owned reference count that thread 2 is applied for adds 1, carries out read operation afterwards to these data.Now the value of the privately owned reference count of thread 2 is 1.After the read operation of thread 2 is finished, separate read lock, the value by the privately owned reference count of its correspondence carries out subtracting 1 operation, becomes 0.
Based on this, before in S110, read lock operation is carried out in the privately owned reference count of thread to correspondence of different core, can also comprise:
S101: the thread of different core checks whether described data are in write operation process, triggers when check result is no and performs S110.
Whether be in write operation process, can by checking that the state of global write lock realizes.Such as, can check whether global write lock is 0, and perform S110 when check result is 0.
Otherwise, if the value checking global write lock is not 0, then mean current write operation to be existed to these data.Then based on the aforementioned mutual exclusion row writing lock and read lock, now to this data read lock, also just read operation can not can not be carried out to these data.In this situation, need to wait for that global write lock becomes after 0, then perform S110.
This S101 performs after S100, also can be performed before S100.
It should be noted that, for read lock, be write operation and latching operation is write in adding of carrying out to avoid having another thread simultaneously between the operation checking global_writer_id value and corresponding read operation further, namely the collision detection caused in this kind of situation was lost efficacy, whether add after 1 by the value of privately owned reference count corresponding for this core, be also 0 by this global_writer_id value again checked now.If be not 0, just perform read operation.
Below introduce an embodiment of the application's read lock operating system.Fig. 2 shows the module map of this system embodiment.
As shown in Figure 2, the read lock operating system in the application one embodiment comprises the first calculating core 11a, and second calculates core 11b, the first buffer unit 12a, the second buffer unit 12b, data cell 13, the buffer unit that each described calculating core correspondence one is unique.
Wherein:
Data cell 13, for storing data;
First buffer unit 12a, for saving as the first privately owned reference count of the distribution of the first calculating core;
Second buffer unit 12b, for saving as the second privately owned reference count of the distribution of the second calculating core;
First calculates core 11a and second calculates core 11b, for reading the same data in described data cell; And,
First thread calculating core 11a carries out in reading process to described data, carries out read lock with the privately owned reference count that the first core is corresponding, understands latching operation;
Second thread calculating core 11b carries out in reading process to described data, carries out read lock with the privately owned reference count that the second core is corresponding, understands latching operation.
Wherein:
Described first buffer unit 12a can be the buffer memory of the first calculating core;
Described second buffer unit 12b can be the buffer memory of the second calculating core.
Mention in embodiment of the method above, the privately owned reference count that each core is corresponding is set, can to carry out data privately owned reference count corresponding to this core distributing before read lock first at the thread of each core, or also can the private reference count of each core of fixed allocation.Such as, the array [read_ref] of a privately owned reference count can be set.To carry out first before read lock to data at the thread of each core, application distributes should in [read_ref] array one.It is enough large that the space of this array [read_ref] can be arranged.In array, each can be set to shaping (int).In array, the initial value of each can be initialized as 0.Certainly, for the read operation of a certain data, also can by each fixed allocation in [read_ref] array to each core.Preferably, in practical operation, each in [read_ref] array can be assigned in a cache lines in buffer memory (cacheline).Cache lines is the minimum unit that multi-core CPU safeguards buffer consistency, is also the effective unit that internal memory exchanges.In the middle of reality, a cache lines on most of platform is greater than 8 bytes, and most cache lines is 64 bytes.If [read_ref] array define is int type, be then 8 bytes.Visible, a cache lines can store 8 read_ref.If store the situation of a more than read_ref in a cache lines, then just have conflict during different element in groups of operands.In order to avoid conflict, each read_ref in [read_ref] array can be stored in a cache lines.Such as, each in [read_ref] array can be claimed as a structure, state that a structure size is 64 bytes simultaneously.Like this, each in [read_ref] array all monopolizes a cache lines, can avoid producing conflict during operation.
In conjunction with foregoing, in an embodiment of the application's read lock operating system, the buffer memory of different core can in corresponding different cache lines.Such as, corresponding first cache lines of described first buffer unit, corresponding second cache lines of described second buffer unit.
In described read lock operating system embodiment, inspection unit 14 can also be comprised, for checking whether described data are in write operation process, and trigger read lock that each calculating core carries out corresponding privately owned reference count in a case of no, understand latching operation.
The above-mentioned read lock operation carried out privately owned reference count, specifically comprises: the privately owned reference count execution that the process of each core is corresponding to this core adds 1 operation.To the deciphering latching operation that privately owned reference count is carried out, specifically comprise: the privately owned reference count execution that the process of each core is corresponding to this core subtracts 1 operation.Conciliate between read lock operation at read lock, the process of each core can read described data.
Below introduce the embodiment that the application writes lock operation method.Fig. 3 shows the process flow diagram of the method embodiment.As shown in Figure 3, the lock operation method embodiment of writing of the application comprises:
S300: before write operation is performed to data, judge the read operation process whether existed in all calculating cores these data.
Describedly judge whether all calculating cores exist the read procedure to these data, concrete, can by convenient each calculate core to should the privately owned reference count of data whether be 0 realization.If be 0, illustrate that these data are in read operation process; If be not 0, then illustrate that these data are not in read operation process.
S310: before write operation is performed to data, judge whether described data are in another write operation process.
S310, concrete can by judging whether the global write lock for these data is 0 realization.If be 0, illustrate that these data are not in another write operation process; If be not 0, illustrate that another write operation process exists.
S320: if the judged result of above-mentioned S310, S320 is no, then carry out in the process of write operation to these data, with described global write be locked into row add write lock, operation that solution writes lock.
Concrete, before carrying out write operation, these data are added and writes lock; After writing, lock is write to this data solution.
Global variable in S320 is such as global_writer_id.Adding and write lock, can be that the value of this global_writer_id is updated to the ID writing thread; Solution writes lock, can be the value of this global_writer_id is updated to 0.
Similar, lock is write for adding, be read operation and the read lock that carries out operates to avoid having another thread simultaneously between the operation checking each core privately owned reference count value and corresponding write operation further, namely the collision detection caused in this kind of situation was lost efficacy, after the value of global_writer_id is updated to the ID writing thread, also again will check now whether the privately owned reference count value of each core is 0.If be not 0, just perform write operation.
Above-mentioned lock operation method of writing can based on aforementioned read lock method of operating or read lock operating system.
Below introduce the embodiment that the application writes latching operation system.Fig. 4 shows the module map of this system embodiment.As shown in Figure 4, the latching operation system embodiment of writing of the application comprises:
Data cell 3, for storing data;
First judging unit 21a, for before performing write operation to data, judges the read operation process whether existed in all calculating cores these data;
Second judging unit 21b, for before performing write operation to data, judges whether described data are in another write operation process;
Add, solution write lock unit 22, for when the judged result of the first judging unit and the second judging unit is all no, described data are being carried out in the process of write operation, with described global write be locked into row add write lock, operation that solution writes lock.
Concrete, before carrying out write operation, these data are added and writes lock; After writing, lock is write to this data solution.
Global variable is such as global_writer_id.Adding and write lock, can be that the value of this global_writer_id is updated to the ID writing thread; Solution writes lock, can be the value of this global_writer_id is updated to 0.
Above-mentioned latching operation system of writing can based on aforementioned read lock method of operating or read lock operating system.
System, device, module or unit that above-described embodiment is illustrated, specifically can be realized by computer chip or entity, or be realized by the product with certain function.
For convenience of description, various unit is divided into describe respectively with function when describing above device.Certainly, the function of each unit can be realized in same or multiple software and/or hardware when implementing the application.
As seen through the above description of the embodiments, those skilled in the art can be well understood to the mode that the application can add required general hardware platform by software and realizes.Based on such understanding, the technical scheme of the application can embody with the form of software product the part that prior art contributes in essence in other words, this computer software product can be stored in storage medium, as ROM/RAM, magnetic disc, CD etc., comprising some instructions in order to make a computer equipment (can be personal computer, server, or the network equipment etc.) perform the method described in some part of each embodiment of the application or embodiment.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, between each embodiment identical similar part mutually see, what each embodiment stressed is the difference with other embodiments.Especially, for system embodiment, because it is substantially similar to embodiment of the method, so description is fairly simple, relevant part illustrates see the part of embodiment of the method.
The application can be used in numerous general or special purpose computing system environments or configuration.Such as: personal computer, server computer, handheld device or portable set, laptop device, multicomputer system, system, set top box, programmable consumer-elcetronics devices, network PC, small-size computer, mainframe computer, the distributed computing environment comprising above any system or equipment etc. based on microprocessor.
The application can describe in the general context of computer executable instructions, such as program module.Usually, program module comprises the routine, program, object, assembly, data structure etc. that perform particular task or realize particular abstract data type.Also can put into practice the application in a distributed computing environment, in these distributed computing environment, be executed the task by the remote processing devices be connected by communication network.In a distributed computing environment, program module can be arranged in the local and remote computer-readable storage medium comprising memory device.
Although depict the application by embodiment, those of ordinary skill in the art know, the application has many distortion and change and do not depart from the spirit of the application, and the claim appended by wishing comprises these distortion and change and do not depart from the spirit of the application.