A resource processing method and device
By creating backup resources for resources and using their tags for update processing, direct locking of resources is avoided, the problem of performance degradation caused by resource locking is solved, and the performance and parallelism of computer programs are improved.
Patent Information
- Application Number
- CN202011553100.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-24
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-12-24
AI Technical Summary
Locking resources can reduce the performance of computer programs, especially in situations of competition between resource producers and consumers, leading to serialized resource usage and reduced performance.
By creating a preconfigured backup resource for the resource, and when the first thread requests to read the resource, it determines whether the resource needs to be updated based on the mark of the backup resource. If it needs to be updated, the backup resource is used to update and read, avoiding the need to update the resource. Direct locking; when the second thread requests a write operation, the backup resource is locked for the write operation, unlocked after completion, and the mark value is set to indicate that an update is required.
Without affecting resource consistency, it reduces the locking operations on resources, improves the parallelism of resource use and the performance of computer programs, especially improves the efficiency of read and write operations in high concurrency situations.
Smart Images

Figure CN112650594B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a resource processing method and device. Background Art
[0002] Currently, resource contention between resource producers and resource consumers can be avoided by locking resources. The resource producer can be a thread that performs a write operation on a resource, and the resource consumer can be a thread that performs a read operation on a resource. Specifically, both resource producers and resource consumers need to lock the resource before performing a corresponding operation on the resource.
[0003] However, locking resources can degrade the performance of computer programs. Summary of the invention
[0004] The technical problem to be solved by the present application is that locking resources will reduce the performance of computer programs, and a resource processing method and device are provided.
[0005] In a first aspect, an embodiment of the present application provides a resource processing method, the method comprising:
[0006] When a first thread requests to read a first resource, determining whether the first resource needs to be updated according to a backup resource corresponding to the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated;
[0007] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0008] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0009] Optionally, the determining whether the first resource needs to be updated according to the backup resource corresponding to the first resource includes:
[0010] Obtaining a value of a first tag of the backup resource;
[0011] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0012] Optionally, the method further includes:
[0013] When the second thread requests to perform a write operation on the first resource, locking the backup resource;
[0014] Performing a write operation on the backup resource;
[0015] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0016] Optionally, the updating the first resource by using the backup resource includes:
[0017] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0018] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0019] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0020] Optionally, the updating the first resource by using the backup resource includes:
[0021] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0022] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0023] In a second aspect, an embodiment of the present application provides a resource processing method, the method comprising:
[0024] When the second thread requests to perform a write operation on the first resource, a backup resource of the first resource is locked, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated;
[0025] Performing a write operation on the backup resource;
[0026] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0027] Optionally, the method further includes:
[0028] When the first thread requests to read the first resource, determining whether the first resource needs to be updated according to the first mark;
[0029] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0030] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0031] Optionally, determining whether the first resource needs to be updated according to the first mark includes:
[0032] Obtaining a value of the first tag;
[0033] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0034] Optionally, the updating the first resource by using the backup resource includes:
[0035] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0036] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0037] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0038] Optionally, the updating the first resource by using the backup resource includes:
[0039] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0040] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0041] In a third aspect, an embodiment of the present application provides a resource processing device, the device comprising:
[0042] a determining unit, configured to determine whether the first resource needs to be updated according to a backup resource corresponding to the first resource when the first thread requests to read the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated;
[0043] A first reading unit, configured to directly read the first resource if it is determined that the first resource does not need to be updated;
[0044] an updating unit, configured to update the first resource using the backup resource if it is determined that the first resource needs to be updated;
[0045] The second reading unit is used to read the updated first resource.
[0046] Optionally, the determining unit is used to:
[0047] Obtaining a value of a first tag of the backup resource;
[0048] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0049] Optionally, the device further comprises:
[0050] A locking unit, configured to lock the backup resource when the second thread requests to perform a write operation on the first resource;
[0051] An operation unit, configured to perform a write operation on the backup resource;
[0052] An unlocking unit, configured to unlock the backup resource after the write operation is completed;
[0053] A setting unit is configured to set the value of the first mark to a second value indicating that an update is required.
[0054] Optionally, the updating unit is used to:
[0055] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0056] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0057] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0058] Optionally, the updating unit is used to:
[0059] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0060] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0061] In a fourth aspect, an embodiment of the present application provides a resource processing device, the device comprising:
[0062] A locking unit, configured to lock a backup resource of a first resource when a second thread requests to perform a write operation on the first resource, wherein: the backup resource is created in advance, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated;
[0063] An operation unit, configured to perform a write operation on the backup resource;
[0064] An unlocking unit, configured to unlock the backup resource after the write operation is completed;
[0065] A setting unit is configured to set the value of the first mark to a second value indicating that an update is required.
[0066] Optionally, the device further comprises:
[0067] a determining unit, configured to determine whether the first resource needs to be updated according to the first mark when the first thread requests to read the first resource;
[0068] A first reading unit, configured to directly read the first resource if it is determined that the first resource does not need to be updated;
[0069] an updating unit, configured to update the first resource using the backup resource if it is determined that the first resource needs to be updated;
[0070] The second reading unit is used to read the updated first resource.
[0071] Optionally, the determining unit is used to:
[0072] Obtaining a value of the first tag;
[0073] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0074] Optionally, the determining unit is used to:
[0075] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0076] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0077] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0078] Optionally, the updating unit is used to:
[0079] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0080] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0081] In a fifth aspect, an embodiment of the present application provides a resource processing device, comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations:
[0082] When a first thread requests to read a first resource, determining whether the first resource needs to be updated according to a backup resource corresponding to the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated;
[0083] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0084] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0085] Optionally, the determining whether the first resource needs to be updated according to the backup resource corresponding to the first resource includes:
[0086] Obtaining a value of a first tag of the backup resource;
[0087] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0088] Optionally, the operation further includes:
[0089] When the second thread requests to perform a write operation on the first resource, locking the backup resource;
[0090] Performing a write operation on the backup resource;
[0091] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0092] Optionally, the updating the first resource by using the backup resource includes:
[0093] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0094] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0095] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0096] Optionally, the updating the first resource by using the backup resource includes:
[0097] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0098] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0099] In a sixth aspect, an embodiment of the present application provides a resource processing device, comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations:
[0100] When the second thread requests to perform a write operation on the first resource, a backup resource of the first resource is locked, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated;
[0101] Performing a write operation on the backup resource;
[0102] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0103] Optionally, the operation further includes:
[0104] When the first thread requests to read the first resource, determining whether the first resource needs to be updated according to the first mark;
[0105] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0106] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0107] Optionally, determining whether the first resource needs to be updated according to the first mark includes:
[0108] Obtaining a value of the first tag;
[0109] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0110] Optionally, the updating the first resource by using the backup resource includes:
[0111] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0112] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0113] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0114] Optionally, the updating the first resource by using the backup resource includes:
[0115] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0116] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0117] In a seventh aspect, an embodiment of the present application provides a computer-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the device to execute any of the methods described in the first aspect above.
[0118] In an eighth aspect, an embodiment of the present application provides a computer-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the device to execute any method described in the second aspect above.
[0119] Compared with the prior art, the embodiments of the present application have the following advantages:
[0120] An embodiment of the present application provides a resource processing method, specifically: a first resource has a corresponding backup resource, which is created in advance, and the backup resource has a first tag, and the value of the first tag is used to indicate whether the first resource needs to be updated. When the first thread requests to read the first resource, it can be determined whether the first resource needs to be updated based on the value of the first tag. If it is determined that the first resource does not need to be updated, there is no need to lock the first resource, and the first resource can be read directly. If it is determined that the first resource needs to be updated, there is no need to lock the first resource, and the first resource can be directly updated and the updated first resource can be read. It can be seen that, using this solution, when the first thread requests to read the first resource, there is no need to lock the first resource as in the prior art, thereby improving the performance of the computer program.
[0121] The embodiment of the present application also provides a resource processing method, specifically: the first resource has a corresponding backup resource, the backup resource is created in advance, and the backup resource has a first tag, and the value of the first tag is used to indicate whether the first resource needs to be updated. When the second thread requests to perform a write operation on the first resource, the backup resource of the first resource is locked, and then the write operation is performed on the backup resource. After the write operation is completed, the backup resource is unlocked, and the value of the first tag is set to a second value indicating that an update is required. Since in the present application, the write operation on the first resource is transferred to the backup resource, therefore, when performing a write operation on the backup resource, there is no need to lock the first resource, and accordingly, other threads such as the first thread can perform a read operation on the first resource. In this way, the read operation on the first resource and the write operation on the backup resource can be performed simultaneously, thereby improving the performance of the computer program. BRIEF DESCRIPTION OF THE DRAWINGS
[0122] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0123] Figure 1 A schematic diagram of a process flow of a resource processing method provided in an embodiment of the present application;
[0124] Figure 2a A schematic diagram of the structure of a resource processing device provided in an embodiment of the present application;
[0125] Figure 2b A schematic diagram of the structure of a resource processing device provided in an embodiment of the present application;
[0126] Figure 3 A schematic diagram of the structure of the client provided in the embodiment of the present application;
[0127] Figure 4 A schematic diagram of the structure of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0128] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0129] The inventor of this application has found through research that, whether it is a resource producer or a resource consumer, before performing a corresponding operation on a resource, it is necessary to lock the resource. For the convenience of description, the lock added to the resource is called a "resource lock". Resource locks can include mutual exclusion locks and read-write locks, and read-write locks can include read locks and write locks. When performing a read operation on a resource, a read lock needs to be added to the resource, and when performing a write operation on a resource, a write lock needs to be added to the resource.
[0130] If the resource lock is a mutex lock, the resource can only be occupied by one thread at a time. For example, before thread A performs a read or write operation on resource a, it adds a mutex lock to resource a. Only after thread A performs an unlock operation on resource a (i.e., unlocks the mutex lock), other threads can perform corresponding operations on resource a. Therefore, if a resource is locked with a mutex lock, it will lead to the serialization of resource use, that is, a thread can only operate the resource after another thread unlocks the resource, which correspondingly reduces the performance of the computer program.
[0131] For read locks, multiple threads can add read locks to the resource at the same time, that is, multiple threads can perform read operations on the resource at the same time. However, adding read locks itself is inefficient, which will correspondingly reduce the performance of the computer program.
[0132] As for the write lock, it is similar to the mutex lock. If a resource is written by a thread, other threads must wait for the write lock to be unlocked if they need to perform read or write operations on the resource. Therefore, if a write lock is added to a resource, it will lead to the serialization of resource use, that is, a thread can only operate the resource after waiting for another thread to unlock the write lock, which correspondingly reduces the performance of the computer program.
[0133] From the above description, it can be seen that, currently, for a thread, no matter whether the thread performs a read operation or a write operation on a resource, the thread needs to lock the resource before operating the resource. Whether a mutex lock or a read-write lock is used to lock the resource, the performance of the computer program will be reduced.
[0134] In order to solve the above problems, an embodiment of the present application provides a resource processing method and device.
[0135] Various non-limiting implementations of the present application are described in detail below in conjunction with the accompanying drawings.
[0136] Exemplary Methods
[0137] See also Figure 1 , which is a flow chart of a resource processing method provided in an embodiment of the present application.
[0138] The resource processing method provided in the embodiment of the present application can be executed by a controller or processor having a data processing function, or by a device including the aforementioned controller or processor, which is not specifically limited in the embodiment of the present application. Among them, the device including the controller or processor includes but is not limited to a terminal device and a server.
[0139] In this embodiment, Figure 1 The resource processing method shown may include, for example, the following steps S101 - S103 .
[0140] S101: When a first thread requests to read a first resource, determining whether the first resource needs to be updated according to a backup resource corresponding to the first resource.
[0141] The first resource mentioned here may be a shared resource, that is, multiple threads have the permission to operate the first resource. In one example, the first resource may have multiple producers and one consumer. In other words, there may be multiple threads that can perform write operations on the first resource, and there is only one thread that can perform read operations on the first resource. For example, the first resource is configuration information to implement a certain function, and multiple threads can modify the configuration information, that is, multiple threads can perform write operations on the configuration information. However, there is only one thread that can read the configuration information, that is, there is only one thread that can read the configuration information. The first thread mentioned here may be the only thread that can read the first resource.
[0142] In one implementation of the embodiment of the present application, for the first resource, a backup resource can be created for the first resource. Considering that for the first resource, some threads want to perform a read operation on the first resource, and some threads want to perform a write operation on the first resource. If the first thread requests to perform a read operation on the first resource and the second thread requests to perform a write operation on the first resource at the same time, the read and write operations on the first resource cannot be performed at the same time. In order to avoid this problem, in one implementation, if the second thread requests to perform a write operation on the first resource, the write operation is performed on the backup resource. At this time, the first thread can still perform a read operation on the first resource. Compared with the aforementioned solution of adding a mutex lock to the resource, the first thread reading the first resource and the second thread performing a write operation on the backup resource of the first resource can be performed simultaneously in this way, thereby improving concurrency.
[0143] In some embodiments, considering that the threads capable of performing write operations on the backup resource may include other threads in addition to the second thread, such as a third thread, in order to prevent multiple threads from performing write operations on the backup resource at the same time, before performing a write operation on the backup resource based on the request of the second thread, the backup resource may be locked, and then the write operation is performed on the backup resource, and the backup resource is unlocked after the write operation is completed.
[0144] It is understandable that the backup resource is a backup of the first resource, and in principle the first resource and the backup resource should always remain the same. Therefore, after the backup resource is written based on the request of the second thread, the first resource should be updated so that the updated first resource is consistent with the backup resource after the aforementioned write operation. In order to achieve this effect, in an example, a first mark can be set for the backup resource, and the value of the first mark is used to indicate whether the first resource needs to be updated. In an example, when the value of the first mark is the first value, it indicates that the first resource does not need to be updated, and when the value of the first mark is the second value, it indicates that the first resource needs to be updated. Among them, the first value and the second value are different. The embodiment of the present application does not specifically limit the first value and the second value. In an example, the first mark is Boolean data, and the first value can be, for example, 0, and the second value can be 1. It is understandable that if the backup resource is different from the first resource, the first resource needs to be updated. For example, if the backup resource is written, the first resource needs to be updated. In this case, after the write operation is performed on the backup resource, the value of the first mark can also be set to the aforementioned second value to indicate that the first resource needs to be updated.
[0145] In one implementation of the embodiment of the present application, in S101, "determining whether the first resource needs to be updated" can be implemented by reading the first resource and the backup resource, and determining whether the first resource and the backup resource are consistent. If they are consistent, it is determined that the first resource does not need to be updated. If they are inconsistent, it is determined that the first resource needs to be updated. It is understandable that when reading the backup resource, in order to prevent other threads from performing write operations on the backup resource at the same time, the backup resource needs to be locked, which leads to the seriality of resource use and correspondingly reduces the performance of the computer program.
[0146] In another implementation of the embodiment of the present application, in S101, "determining whether the first resource needs to be updated" can be determined based on the value of the aforementioned first tag during specific implementation. In one example, if the value of the first tag is a first value, it can be determined that the first resource does not need to be updated, and if the value of the first tag is a second value, it can be determined that the first resource needs to be updated. It can be understood that by adopting this method, there is no need to lock the backup resources, thereby improving the parallelism of resource use and correspondingly improving the performance of the computer program.
[0147] S102: If it is determined that the first resource does not need to be updated, directly read the first resource.
[0148] It is understandable that in the aforementioned multi-producer single-consumer scenario, the threads that can read the first resource only include the first thread, and no other threads will perform write operations on the first resource because the original write operations for the first resource are transferred to the backup resource. In other words, except for the first thread, no other thread will operate the first resource. Therefore, in an embodiment of the present application, after determining that the first resource does not need to be updated, it is not necessary to lock the first resource, but to directly read the first resource. In this way, the computer resources consumed by locking the first resource can be reduced, and the parallelism of the use of the first resource can be improved, which correspondingly improves the performance of the computer program.
[0149] S103: If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0150] As described in S102 above, except for the first thread, no other thread will operate the first resource. Therefore, in the embodiment of the present application, after determining that the first resource needs to be updated, it is not necessary to lock the first resource, but directly update the first resource and read the updated first resource.
[0151] It is understandable that the reason why the first resource needs to be updated is that a write operation has been performed on the backup resource of the first resource, thereby making the backup resource inconsistent with the first resource. Therefore, in one example, the backup resource can be read, and the first resource can be updated using the read backup resource, so that the updated first resource is the same as the read backup resource. As mentioned above, the thread that can perform a write operation on the backup resource can include other threads in addition to the second thread. In order to avoid other threads performing a write operation on the backup resource while reading the backup resource, the backup resource can be locked before reading the backup resource, and correspondingly, the backup resource can be unlocked after reading the backup resource.
[0152] In one implementation, after the first resource is updated, the value of the first tag may be set to the first value to indicate that the first resource is consistent with the backup resource, that is, the first resource does not need to be updated. Accordingly, if the first thread requests to read the first resource again, it may be determined based on the first value that the first resource does not need to be updated, and thus the first resource may be directly read.
[0153] From the above description, it can be seen that, using this solution, when the first thread requests to read the first resource, there is no need to lock the first resource as in the prior art, thereby reducing the computer resources consumed by locking the first resource, improving the parallelism of resource use, and correspondingly improving the performance of the computer program. Moreover, the higher the frequency of the first thread's request to read the first resource, the more obvious the improvement of the computer program performance will be compared with the prior art.
[0154] To facilitate understanding of this solution, the overall process of the read operation and the write operation on the first resource is briefly introduced below.
[0155] First, the overall process of performing a write operation on a first resource is introduced. The process may include the following steps A1 to A2.
[0156] Step A1: When the second thread requests to perform a write operation on the first resource, the pre-created backup resource is locked, and the write operation is performed on the backup resource.
[0157] It should be noted that in the embodiment of the present application, a backup resource needs to be created in advance for the first resource.
[0158] In the embodiment of the present application, the write operation on the first resource is not directly performed on the first resource itself, but is performed on the backup resource of the first resource.
[0159] Therefore, when the second thread requests to perform a write operation on the first resource, the first resource is not locked, and only the backup resource is locked. The lock added to the backup resource here can be a mutual exclusion lock or a read-write lock, which is not specifically limited in the embodiment of the present application.
[0160] After the write operation is performed on the backup resource, the value of the backup resource is updated to the latest value.
[0161] Step A2: After the write operation is completed, the value of the first mark of the backup resource is set to a second value indicating that an update is required, and the backup resource is unlocked. The first mark of the backup resource is used to indicate whether the first resource needs to be updated.
[0162] It is understandable that the thread requesting to perform a write operation on the first resource may include other threads in addition to the second thread. The implementation of other threads performing a write operation on the backup resource may refer to the above steps and will not be described in detail here.
[0163] Next, the overall process of performing a read operation on the first resource is introduced, and the process may include the following steps:
[0164] Step B1: when the first thread requests to read the first resource, it is determined whether the first resource needs to be updated according to the value of the first tag of the backup resource corresponding to the first resource.
[0165] Step B2: If it is determined that the first resource does not need to be updated, directly read the first resource.
[0166] Step B3: If it is determined that the first resource needs to be updated, lock the backup resource, read the value of the backup resource, and after reading, set the value of the first mark to a first value indicating that no update is required, and unlock the backup resource; use the read value of the backup resource to update the first resource so that the value of the updated first resource is equal to the value of the backup resource; read the updated first resource.
[0167] It should be noted that in step B3, after the backup resource is locked, the first resource can be directly updated using the value of the backup resource, so that the value of the updated first resource is equal to the value of the backup resource; then the value of the first mark of the backup resource is set to the first value indicating that no update is required, and the backup resource is unlocked; finally, the updated first resource is read.
[0168] For the specific implementation of steps B1 to B3, please refer to the description of S101 to S103 above, which will not be repeated here.
[0169] It should be noted that, in some embodiments, the write operation to the backup resource of the first resource may be relatively frequent, for example, the second thread, the third thread, and even the fourth thread successively perform write operations on the backup resource, and in this process, the first thread does not request to read the first resource. Although in principle, the first resource should be consistent with the backup resource. However, as mentioned above, updating the first resource requires locking the backup resource, and frequent locking of the backup resource will also affect the performance of the computer program. Therefore, in the embodiment of the present application, it is not necessary to update the first resource every time after performing a write operation on the backup resource, but every time after performing a write operation on the backup resource, the value of the first tag is set to the second value, and when the first thread requests to read the first resource, the first resource is updated according to the second value. In this case, before the first thread requests to read the first resource, no matter how many times the write operation is performed on the backup resource, the first resource only needs to be updated once when the first thread requests to read the first resource, thereby effectively improving the performance of the computer program. It should be noted that the aforementioned "every time after performing a write operation on the backup resource, the value of the first tag is set to the second value" can include two situations. The first case is: before executing the write operation, the value of the first tag is a first value indicating that no update is required, and after executing the write operation, the value of the first tag is modified from the first value to a second value indicating that an update is required; the second case is: before executing the write operation, the value of the first tag is originally the second value, and after executing the write operation, the value of the first tag is still the second value.
[0170] Exemplary Devices
[0171] Based on the method provided in the above embodiment, the embodiment of the present application also provides a corresponding device, which is described below in conjunction with the accompanying drawings.
[0172] See also Figure 2a , which is a structural diagram of a resource processing device provided in an embodiment of the present application. Figure 2a The device 210 shown may specifically include, for example: a determining unit 211 , a first reading unit 212 , an updating unit 213 , and a second reading unit 214 .
[0173] A determination unit 211 is used to determine whether the first resource needs to be updated according to a backup resource corresponding to the first resource when the first thread requests to read the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated;
[0174] A first reading unit 212, configured to directly read the first resource if it is determined that the first resource does not need to be updated;
[0175] An updating unit 213, configured to update the first resource using the backup resource if it is determined that the first resource needs to be updated;
[0176] The second reading unit 214 is configured to read the updated first resource.
[0177] Optionally, the determining unit 211 is configured to:
[0178] Obtaining a value of a first tag of the backup resource;
[0179] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0180] Optionally, the device further comprises:
[0181] A locking unit, configured to lock the backup resource when the second thread requests to perform a write operation on the first resource;
[0182] An operation unit, configured to perform a write operation on the backup resource;
[0183] An unlocking unit, configured to unlock the backup resource after the write operation is completed;
[0184] A setting unit is configured to set the value of the first mark to a second value indicating that an update is required.
[0185] Optionally, the updating unit 213 is used to:
[0186] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0187] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0188] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0189] Optionally, the updating unit 213 is used to:
[0190] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0191] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0192] See also Figure 2b , which is a structural diagram of a resource processing device provided in an embodiment of the present application. Figure 2b The device 220 shown may specifically include, for example: a locking unit 221 , a reading unit 222 , an unlocking unit 223 , and a setting unit 224 .
[0193] The locking unit 221 is used to lock the backup resource of the first resource when the second thread requests to perform a write operation on the first resource, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated;
[0194] An operation unit 222, configured to perform a write operation on the backup resource;
[0195] An unlocking unit 223, configured to unlock the backup resource after the write operation is completed;
[0196] The setting unit 224 is configured to set the value of the first mark to a second value indicating that an update is required.
[0197] Optionally, the device further comprises:
[0198] a determining unit, configured to determine whether the first resource needs to be updated according to the first mark when the first thread requests to read the first resource;
[0199] A first reading unit, configured to directly read the first resource if it is determined that the first resource does not need to be updated;
[0200] an updating unit, configured to update the first resource using the backup resource if it is determined that the first resource needs to be updated;
[0201] The second reading unit is used to read the updated first resource.
[0202] Optionally, the determining unit is used to:
[0203] Obtaining a value of the first tag;
[0204] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0205] Optionally, the determining unit is used to:
[0206] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0207] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0208] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0209] Optionally, the updating unit is used to:
[0210] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0211] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0212] Since the devices 210 and 220 are devices corresponding to the methods provided in the above method embodiments, the specific implementation of each unit of the devices 210 and 220 is based on the same concept as the above method embodiments. Therefore, for the specific implementation of each unit of the devices 210 and 220, reference can be made to the description of the above method embodiments, which will not be repeated here.
[0213] The method provided in the embodiment of the present application can be executed by a client or a server. The client and server that execute the above method are described below respectively.
[0214] Figure 3 1 shows a block diagram of a client 300. For example, the client 300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0215] Reference Figure 3 The client 300 may include one or more of the following components: a processing component 302 , a memory 304 , a power component 306 , a multimedia component 308 , an audio component 310 , an input / output (I / O) interface 33 , a sensor component 314 , and a communication component 316 .
[0216] The processing component 302 generally controls the overall operation of the client 300, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 302 may include one or more modules to facilitate the interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate the interaction between the multimedia component 308 and the processing component 302.
[0217] The memory 304 is configured to store various types of data to support operations on the client 300. Examples of such data include instructions for any application or method operating on the client 300, contact data, phone book data, messages, pictures, videos, etc. The memory 304 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0218] The power supply component 306 provides power to the various components of the client 300. The power supply component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the client 300.
[0219] The multimedia component 308 includes a screen that provides an output interface between the client 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 308 includes a front camera and / or a rear camera. When the client 300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0220] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC), and when the client 300 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 304 or sent via the communication component 316. In some embodiments, the audio component 310 also includes a speaker for outputting audio signals.
[0221] The I / O interface provides an interface between the processing component 302 and the peripheral interface module, which may be a keyboard, a click wheel, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0222] The sensor assembly 314 includes one or more sensors for providing various aspects of status assessment for the client 300. For example, the sensor assembly 314 can detect the open / closed state of the device 300, the relative positioning of components, such as the display and keypad of the client 300, and the sensor assembly 314 can also detect the position change of the client 300 or a component of the client 300, the presence or absence of user contact with the client 300, the orientation or acceleration / deceleration of the client 300, and the temperature change of the client 300. The sensor assembly 314 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 314 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 314 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0223] The communication component 316 is configured to facilitate wired or wireless communication between the client 300 and other devices. The client 300 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 316 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0224] In an exemplary embodiment, the client 300 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the following methods:
[0225] When a first thread requests to read a first resource, determining whether the first resource needs to be updated according to a backup resource corresponding to the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated;
[0226] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0227] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0228] Optionally, the determining whether the first resource needs to be updated according to the backup resource corresponding to the first resource includes:
[0229] Obtaining a value of a first tag of the backup resource;
[0230] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0231] Optionally, the method further includes:
[0232] When the second thread requests to perform a write operation on the first resource, locking the backup resource;
[0233] Performing a write operation on the backup resource;
[0234] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0235] Optionally, the updating the first resource by using the backup resource includes:
[0236] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0237] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0238] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0239] Optionally, the updating the first resource by using the backup resource includes:
[0240] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0241] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0242] In another exemplary embodiment, the client 300 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the following methods:
[0243] When the second thread requests to perform a write operation on the first resource, a backup resource of the first resource is locked, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated;
[0244] Performing a write operation on the backup resource;
[0245] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0246] Optionally, the method further includes:
[0247] When the first thread requests to read the first resource, determining whether the first resource needs to be updated according to the first mark;
[0248] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0249] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0250] Optionally, determining whether the first resource needs to be updated according to the first mark includes:
[0251] Obtaining a value of the first tag;
[0252] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0253] Optionally, the updating the first resource by using the backup resource includes:
[0254] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0255] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0256] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0257] Optionally, the updating the first resource by using the backup resource includes:
[0258] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0259] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0260] Figure 4 4 is a schematic diagram of the structure of the server in the embodiment of the present application. The server 400 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 422 (for example, one or more processors) and memory 432, and one or more storage media 430 (for example, one or more mass storage devices) storing application programs 442 or data 444. Among them, the memory 432 and the storage medium 430 can be short-term storage or permanent storage. The program stored in the storage medium 430 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 422 can be configured to communicate with the storage medium 430 to execute a series of instruction operations in the storage medium 430 on the server 400.
[0261] Further:
[0262] In one example, the CPU 422 may execute the following method:
[0263] When a first thread requests to read a first resource, determining whether the first resource needs to be updated according to a backup resource corresponding to the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated;
[0264] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0265] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0266] Optionally, the determining whether the first resource needs to be updated according to the backup resource corresponding to the first resource includes:
[0267] Obtaining a value of a first tag of the backup resource;
[0268] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0269] Optionally, the method further includes:
[0270] When the second thread requests to perform a write operation on the first resource, locking the backup resource;
[0271] Performing a write operation on the backup resource;
[0272] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0273] Optionally, the updating the first resource by using the backup resource includes:
[0274] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0275] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0276] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0277] Optionally, the updating the first resource by using the backup resource includes:
[0278] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0279] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0280] In yet another example, the CPU 422 may execute the following method:
[0281] When the second thread requests to perform a write operation on the first resource, a backup resource of the first resource is locked, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated;
[0282] Performing a write operation on the backup resource;
[0283] After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
[0284] Optionally, the method further includes:
[0285] When the first thread requests to read the first resource, determining whether the first resource needs to be updated according to the first mark;
[0286] If it is determined that the first resource does not need to be updated, directly read the first resource;
[0287] If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
[0288] Optionally, determining whether the first resource needs to be updated according to the first mark includes:
[0289] Obtaining a value of the first tag;
[0290] When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
[0291] Optionally, the updating the first resource by using the backup resource includes:
[0292] Locking the backup resource, and unlocking the backup resource after reading the backup resource;
[0293] Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource;
[0294] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0295] Optionally, the updating the first resource by using the backup resource includes:
[0296] Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource;
[0297] The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
[0298] The server 400 may also include one or more power supplies 426, one or more wired or wireless network interfaces 450, one or more input and output interfaces 456, one or more keyboards 456, and / or one or more operating systems 441, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0299] The embodiment of the present application also provides a computer-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the device to execute the resource processing method provided by the above method embodiment.
[0300] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0301] It should be understood that the present application is not limited to the precise structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
[0302] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A resource processing method, characterized in that: The method comprises: When the first thread requests to read the first resource, obtaining a value of a first tag of a backup resource corresponding to the first resource; When the value of the first mark is a first value indicating that no update is required, it is determined that the first resource does not need to be updated; when the value of the first mark is a second value indicating that an update is required, it is determined that the first resource needs to be updated; wherein the first value is different from the second value, the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated; If it is determined that the first resource does not need to be updated, directly read the first resource; If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
2. The method according to claim 1, characterized in that The method further comprises: When the second thread requests to perform a write operation on the first resource, locking the backup resource; Performing a write operation on the backup resource; After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
3. The method according to any one of claims 1-2, characterized in that: The updating of the first resource by using the backup resource includes: Locking the backup resource, and unlocking the backup resource after reading the backup resource; Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
4. The method according to any one of claims 1 to 2, characterized in that: The updating of the first resource by using the backup resource includes: Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
5. A resource processing method, characterized in that: The method comprises: When the second thread requests to perform a write operation on the first resource, a backup resource of the first resource is locked, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated; Performing a write operation on the backup resource; After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
6. The method according to claim 5, characterized in that The method further comprises: When the first thread requests to read the first resource, determining whether the first resource needs to be updated according to the first mark; If it is determined that the first resource does not need to be updated, directly read the first resource; If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
7. The method according to claim 6, characterized in that The determining, according to the first mark, whether the first resource needs to be updated includes: Obtaining a value of the first tag; When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
8. The method according to claim 6, characterized in that The updating of the first resource by using the backup resource includes: Locking the backup resource, and unlocking the backup resource after reading the backup resource; Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
9. The method according to claim 6, characterized in that The updating of the first resource by using the backup resource includes: Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
10. A resource processing device, characterized in that: The device comprises: a determining unit, configured to determine whether the first resource needs to be updated according to a backup resource corresponding to the first resource when the first thread requests to read the first resource; wherein the backup resource is pre-created and is configured with a first flag, and the first flag is used to indicate whether the first resource needs to be updated; A first reading unit, configured to directly read the first resource if it is determined that the first resource does not need to be updated; an updating unit, configured to update the first resource using the backup resource if it is determined that the first resource needs to be updated; A second reading unit, configured to read the updated first resource; The determining unit is used for: Obtaining a value of a first tag of the backup resource; When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
11. The device according to claim 10, characterized in that The device also includes: A locking unit, configured to lock the backup resource when the second thread requests to perform a write operation on the first resource; An operation unit, configured to perform a write operation on the backup resource; An unlocking unit, configured to unlock the backup resource after the write operation is completed; A setting unit is configured to set the value of the first mark to a second value indicating that an update is required.
12. The device according to any one of claims 10-11, characterized in that: The updating unit is used for: Locking the backup resource, and unlocking the backup resource after reading the backup resource; Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
13. The device according to any one of claims 10-11, characterized in that: The updating unit is used for: Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
14. A resource processing device, characterized in that: The device comprises: A locking unit, configured to lock a backup resource of a first resource when a second thread requests to perform a write operation on the first resource, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated; an operation unit, configured to perform a write operation on the backup resource; An unlocking unit, configured to unlock the backup resource after the write operation is completed; A setting unit is configured to set the value of the first mark to a second value indicating that an update is required.
15. The device according to claim 14, characterized in that The device also includes: a determining unit, configured to determine whether the first resource needs to be updated according to the first mark when the first thread requests to read the first resource; A first reading unit, configured to directly read the first resource if it is determined that the first resource does not need to be updated; an updating unit, configured to update the first resource using the backup resource if it is determined that the first resource needs to be updated; The second reading unit is used to read the updated first resource.
16. The device according to claim 15, characterized in that The determining unit is used for: Obtaining a value of the first tag; When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
17. The device according to claim 15, characterized in that The determining unit is used for: Locking the backup resource, and unlocking the backup resource after reading the backup resource; Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
18. The device according to claim 15, characterized in that The updating unit is used for: Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
19. A resource processing device, characterized in that: The system comprises a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations: When the first thread requests to read the first resource, obtaining a value of a first tag of a backup resource corresponding to the first resource; When the value of the first mark is a first value indicating that no update is required, it is determined that the first resource does not need to be updated; when the value of the first mark is a second value indicating that an update is required, it is determined that the first resource needs to be updated; wherein the first value is different from the second value, the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated; If it is determined that the first resource does not need to be updated, directly read the first resource; If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
20. The device according to claim 19, characterized in that The operations also include: When the second thread requests to perform a write operation on the first resource, locking the backup resource; Performing a write operation on the backup resource; After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
21. The device according to any one of claims 19-20, characterized in that: The updating of the first resource by using the backup resource includes: Locking the backup resource, and unlocking the backup resource after reading the backup resource; Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
22. The device according to any one of claims 19-20, characterized in that The updating of the first resource by using the backup resource includes: Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
23. A resource processing device, characterized in that: The system comprises a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations: When the second thread requests to perform a write operation on the first resource, a backup resource of the first resource is locked, wherein: the backup resource is pre-created, and the backup resource is configured with a first mark, and the first mark is used to indicate whether the first resource needs to be updated; and a write operation is performed on the backup resource; After the write operation is completed, the backup resource is unlocked, and the value of the first mark is set to a second value indicating that an update is required.
24. The device according to claim 23, characterized in that The operations also include: When the first thread requests to read the first resource, determining whether the first resource needs to be updated according to the first mark; If it is determined that the first resource does not need to be updated, directly read the first resource; If it is determined that the first resource needs to be updated, the first resource is updated using the backup resource and the updated first resource is read.
25. The device according to claim 24, characterized in that The determining, according to the first mark, whether the first resource needs to be updated includes: Obtaining a value of the first tag; When the value of the first tag is a first value indicating that updating is not required, it is determined that the first resource does not need to be updated; when the value of the first tag is a second value indicating that updating is required, it is determined that the first resource needs to be updated, and the first value is different from the second value.
26. The device according to claim 24, characterized in that The updating of the first resource by using the backup resource includes: Locking the backup resource, and unlocking the backup resource after reading the backup resource; Using the read backup resource to update the first resource, so that the updated first resource is the same as the read backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
27. The device according to claim 24, characterized in that The updating of the first resource by using the backup resource includes: Locking the backup resource, updating the first resource using the backup resource so that the updated first resource is the same as the read backup resource, and unlocking the backup resource; The value of the first mark of the backup resource is set to a first value indicating that updating is not required.
28. A computer readable medium having instructions stored thereon, which, when executed by one or more processors, cause an apparatus to perform the method of any one of claims 1 to 4.
29. A computer readable medium having instructions stored thereon, which, when executed by one or more processors, cause an apparatus to perform the method of any one of claims 5 to 8.
Citation Information
Patent Citations
Synchronous method performing mutual exclusion access on shared resource, device and network equipment
CN101631328A
Local locking in bi-directional synchronous mirroring environment and computer system
CN104714756A
