Task execution method and device

By allocating tasks to be executed and target resources according to the task type, the problems of low reading and writing efficiency and complex implementation of shared resources in the prior art are solved, and efficient and secure task execution is achieved.

CN113760524BActive Publication Date: 2025-05-16BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011287800.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-17
Publication Date
2025-05-16
Estimated Expiration
2040-11-17

AI Technical Summary

Technical Problem

In the prior art, the read and write schemes for shared resources are less efficient and the implementation process is complicated.

Method used

By obtaining the requested task set, the task set to be executed is determined according to the task type of the requested task group, and the allocation method of the target resources is determined according to the task type of the task set to be executed, and the target resources are allocated to the task set to be executed and the requested task is executed.

Benefits of technology

It improves the efficiency of task execution, ensures the safe use of target resources, and the implementation process is relatively simple.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760524B_ABST
    Figure CN113760524B_ABST
Patent Text Reader

Abstract

The present invention discloses a task execution method and device, and relates to the field of computer technology. A specific implementation of the method includes: obtaining a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task; according to the task type of the at least one request task group, determining a to-be-executed task set from the request task set; wherein the to-be-executed task set includes at least one to-be-executed task group; according to the task type corresponding to the to-be-executed task set, determining the allocation method of the target resource; according to the allocation method, allocating the target resource to the to-be-executed task set, and executing the request task in the to-be-executed task set. This implementation method can not only ensure the safe use of the target resources, but also has a simple implementation process and high efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a task execution method and device. Background Art

[0002] The operating system of an electronic device can usually support multi-threaded operation. Shared resources can be accessed by multiple threads. In order to prevent multiple threads from accessing shared resources at the same time, locks can be used to protect shared resources.

[0003] In the process of implementing the present invention, the inventors found that the existing solutions for reading and writing shared resources have at least the following problems: relatively low efficiency, relatively complicated implementation process, etc. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a task execution method and device with high execution efficiency.

[0005] In a first aspect, an embodiment of the present invention provides a task execution method, including:

[0006] A task execution method, characterized by comprising:

[0007] Obtain a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task;

[0008] Determine a to-be-executed task set from the request task set according to the task type of the at least one request task group; wherein the to-be-executed task set includes at least one to-be-executed task group;

[0009] Determining the allocation method of the target resources according to the task type corresponding to the set of tasks to be executed;

[0010] According to the allocation mode, the target resource is allocated to the set of tasks to be executed, and the requested task in the set of tasks to be executed is executed.

[0011] Optionally, further comprising:

[0012] For each of the request task groups: according to the task type of the request task group, determine the calling interface corresponding to the request task group; and add the identifier of the request task group and the identifier of the calling interface to the request task set through the calling interface.

[0013] Optionally,

[0014] The step of determining a to-be-executed task set from the request task set according to the task type of the at least one request task group includes:

[0015] According to a preset fetching order, fetch the current task group from the requested task set;

[0016] Determine the task type of the current task group according to the interface identifier corresponding to the current task group;

[0017] If the task type of the current task group is a read operation, adding the current task group to the set of tasks to be executed;

[0018] According to the fetching order, the next task group is fetched from the remaining request task set until the task type of the next task group is not a read operation.

[0019] Optionally,

[0020] The step of determining a to-be-executed task set from the request task set according to the task type of the at least one request task group includes:

[0021] According to a preset fetching order, fetch the current task group from the requested task set;

[0022] Determine the task type of the current task group according to the interface identifier corresponding to the current task group;

[0023] If the task type of the current task group is a write operation, the current task group is added to the set of tasks to be executed.

[0024] Optionally,

[0025] The determining, according to the task type corresponding to the set of tasks to be executed, the allocation method of the target resources includes:

[0026] If the task type corresponding to the to-be-executed task set is a read operation, determining that the allocation mode of the target resource is a sharing mode;

[0027] The step of allocating the target resource to the set of tasks to be executed according to the allocation mode, and executing the requested task in the set of tasks to be executed includes:

[0028] The target resource is allocated to the tasks to be executed in the set of tasks to be executed in a shared manner, and the tasks to be executed are executed in a concurrent manner.

[0029] Optionally,

[0030] The determining, according to the task type corresponding to the set of tasks to be executed, the allocation method of the target resources includes:

[0031] If the number of the to-be-executed task groups in the to-be-executed task set is 1, and the task type corresponding to the to-be-executed task set is a write operation, determining that the allocation mode of the target resource is an exclusive mode;

[0032] The step of allocating the target resource to the set of tasks to be executed according to the allocation mode, and executing the requested task in the set of tasks to be executed includes:

[0033] The target resource is exclusively allocated to the tasks to be executed in the set of tasks to be executed, and the tasks to be executed are executed.

[0034] Optionally,

[0035] The allocating the target resource to the tasks to be executed in the set of tasks to be executed in an exclusive manner, and executing the tasks to be executed, comprises:

[0036] If the number of tasks to be executed in the task group to be executed is 1, allocating the target resource to the tasks to be executed in the task group to be executed in an exclusive manner, and executing the tasks to be executed;

[0037] If there are multiple tasks to be executed in the task group to be executed, the target resource is allocated to the multiple tasks to be executed in the task group to be executed in an exclusive manner; and the multiple tasks to be executed are executed in a serial manner according to a preset execution order.

[0038] In a second aspect, an embodiment of the present invention provides a task execution device, including:

[0039] An acquisition module, used to acquire a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task;

[0040] A determination module, configured to determine a set of tasks to be executed from the set of requested tasks according to a task type of the at least one requested task group; wherein the set of tasks to be executed includes at least one set of tasks to be executed;

[0041] An allocation module, used to determine the allocation method of the target resource according to the task type corresponding to the set of tasks to be executed;

[0042] The execution module allocates the target resource to the set of tasks to be executed according to the allocation method, and executes the requested task in the set of tasks to be executed.

[0043] In a third aspect, an embodiment of the present invention provides an electronic device, including:

[0044] one or more processors;

[0045] a storage device for storing one or more programs,

[0046] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above embodiments.

[0047] In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method described in any of the above embodiments.

[0048] An embodiment of the above invention has the following advantages or beneficial effects: according to the task type of the request task group, the allocation method of the task group to be executed and the target resource is determined, the target resource is allocated to the task set to be executed, and the request task in the task group to be executed is executed. Not only can the use of the target resource be guaranteed to be safe, but the implementation process is also simple and efficient.

[0049] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0051] Figure 1 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0052] Figure 2 It is a schematic diagram of a resource security problem caused by multiple threads jointly requesting resources, provided by an embodiment of the present invention;

[0053] Figure 3 is a schematic diagram of a process of a task execution method provided by an embodiment of the present invention;

[0054] Figure 4 is a schematic diagram of a process of another task execution method provided by an embodiment of the present invention;

[0055] Figure 5 is a schematic diagram of a process of another task execution method provided by an embodiment of the present invention;

[0056] Figure 6 is a schematic diagram of a scenario of a multi-task execution method provided by an embodiment of the present invention;

[0057] Figure 7 is a structural schematic diagram of a task execution device provided by an embodiment of the present invention;

[0058] Figure 8It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0059] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0060] Figure 1 An exemplary system architecture 100 is shown to which the task execution method or task execution apparatus according to the embodiment of the present invention can be applied.

[0061] like Figure 1 As shown, system architecture 100 may include servers 101, 102, and network 103. Network 103 is used to provide a medium for a communication link between server 101 and server 102. Network 103 may include various connection types, such as wired, wireless communication links, or optical fiber cables.

[0062] There are multiple pending tasks to be executed on the server 101. The target resources required for executing the multiple pending tasks are stored on the server 102, that is, the multiple pending tasks on the server 101 simultaneously request the same target resource on the server 102. The target resource may include data records in a database, a variable in a memory, or a piece of code, etc.

[0063] The server 101 divides the tasks into multiple task groups according to the task types of the tasks to be executed and the association between the tasks, and determines a set of tasks to be executed according to the types of the task groups, wherein the set of tasks to be executed includes at least one set of tasks to be executed. According to the task types corresponding to the set of tasks to be executed, the allocation method of the target resources is determined; according to the allocation method, the target resources are allocated to the set of tasks to be executed, and the requested tasks in the set of tasks to be executed are executed.

[0064] It should be noted that the task execution method provided in the embodiment of the present invention is generally executed by the server 101 , and accordingly, the task execution device and the image set annotation device are generally arranged in the server 101 .

[0065] It should be understood that Figure 1 The number of networks and servers in the example is only illustrative. Any number of networks and servers may be provided as required. Multiple tasks running in the server 101 may request target resources from multiple servers at the same time.

[0066] When multiple tasks request the same target resource at the same time, the security of the target resource may be affected. Figure 2 FIG. 1 is a schematic diagram of a resource security problem caused by multiple threads requesting resources together, provided by an embodiment of the present invention. Figure 2 As shown in the figure, each task is executed from bottom to top, that is, the task closer to the execution sequence arrow is executed first. Connection 1 first modifies a data record in the database through a write operation, and then reads the data record through a read operation. However, between the write operation and the read operation of connection 1, the data is modified by the write operation of connection 2, so that the data read by the read operation of connection 1 is inconsistent with the data written by connection 1.

[0067] Based on this, an embodiment of the present invention provides a task execution method that can better solve the security problem of reading and writing shared target resources. Figure 3 As shown, the method includes:

[0068] Step 301: Obtain a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task.

[0069] The tasks in the embodiments of the present invention are a series of computer instructions that can accomplish a certain purpose. A task can be a process, a thread, or a thread group. A task corresponds to a series of computer operations, such as input operations, download operations, encoding and decoding, face recognition, image segmentation, etc.

[0070] There are multiple request tasks that need to be executed in the system. These request tasks all need to request the same target resource. The target resource may include: data records in the database, a variable in the memory, or a piece of code, etc.

[0071] The above-mentioned multiple request tasks to be executed can be divided into multiple request task groups according to task attributes such as task type and task association. There is no dependency between the request tasks in each request task group and the request tasks in other request task groups. A request task group includes at least one request task. A request task group may include a single read operation task, multiple read operation tasks, a single write operation task, or a group of tasks corresponding to the same atomic operation. The above-mentioned multiple request task groups constitute a request task set.

[0072] For example, a request task set may include:

[0073] Request task group 1: read operation task 1;

[0074] Request task group 2: read operation task 2, read operation task 3;

[0075] Request task group 3: write operation task 1, read operation task 4

[0076] Request task group 4: write operation task 2.

[0077] Among them, the request tasks in the request task group 3 are tasks corresponding to a group of atomic operations.

[0078] Step 302: Determine a to-be-executed task set from the requested task set according to the task type of at least one requested task group; wherein the to-be-executed task set includes at least one to-be-executed task group.

[0079] The task type of the request task group may be determined by the tasks in the request task group. The task type of the request task group may include: read operation, write operation, etc. If the request task group includes a read operation task, the task type of the request task group is a read operation. If the request task group includes a write operation task, the task type of the request task group is a write operation. If the tasks in the request task group are a group of atomic operation tasks, the task type of the request task group is a write operation.

[0080] From the example of requesting a task group in step 301, it can be seen that if the task type of the requesting task group is a read operation, the number of tasks included in the requesting task group is 1 or more. If the task type of the requesting task group is a write operation, and the requesting task group only includes write operation tasks, the number of tasks included in the requesting task group is 1. If the task type of the requesting task group is a read operation, and the requesting task group includes a group of atomic operation tasks, the number of tasks included in the requesting task group is 1 or more.

[0081] The set of tasks to be executed is a subset of the set of requested tasks. The set of tasks to be executed can be determined from the set of requested tasks according to the task type of the requested task group. For example, multiple request task groups with a task type of read operation can be selected from the request task group as the set of tasks to be executed, and the multiple request task groups to be executed constitute the set of tasks to be executed. It is also possible to select a request task group with a task type of write operation from the request task group as the set of tasks to be executed, and the set of tasks to be executed is the set of tasks to be executed.

[0082] Taking the example of the request task set in step 301, the task group to be executed may include: request task group 1 and request task group 2. Request task group 1 and request task group 2 constitute the task group to be executed.

[0083] Step 303: Determine the allocation method of the target resources according to the task type corresponding to the set of tasks to be executed.

[0084] The task type corresponding to the set of tasks to be executed is determined by the task type of the task group to be executed in the set of tasks to be executed. If the set of tasks to be executed includes one or more task groups to be executed, and the task type of each task group to be executed is a read operation, then the task type corresponding to the set of tasks to be executed is a read operation. If the set of tasks to be executed includes only one task group to be executed, and the task type of the task group to be executed is a write operation, then the task type corresponding to the set of tasks to be executed is a write operation.

[0085] Taking the request task set in step 301 as an example, if the task set to be executed includes: request task group 1 and request task group 2. Since the task types of request task group 1 and request task group 2 are both read operations, the task type corresponding to the task set to be executed is read operation.

[0086] If the task type corresponding to the set of tasks to be executed is a read operation, the target resource allocation mode is determined to be a shared mode. If the task type corresponding to the set of tasks to be executed is a write operation, the target resource allocation mode is determined to be an exclusive mode.

[0087] Step 304: Allocate the target resource to the set of tasks to be executed according to the allocation method, and execute the requested task in the set of tasks to be executed.

[0088] In the embodiment of the present invention, according to the task type of the request task group, the allocation method of the task set to be executed and the target resource is determined, the target resource is allocated to the task set to be executed, and the request task in the task set to be executed is executed. Not only can the use of the target resource be guaranteed to be safe, but also there is no need to consider the context environment of the task and the life cycle of the task, etc., which can solve the problems of low efficiency in reading and writing shared resources and complex implementation process in the prior art.

[0089] In one embodiment of the present invention, the execution method further comprises:

[0090] For each request task group: determine the calling interface corresponding to the request task group according to the task type of the request task group; add the identifier of the request task group and the identifier of the calling interface to the request task set through the calling interface.

[0091] Different interfaces are set in the system to add request task groups of different task types to the request task set. The calling interface type may include a read interface or a write interface. If the task type of the request task group is a read operation, the read interface is determined as the calling interface of the request task group; the identifier of the request task group and the identifier of the read interface are added to the request task set. If the task type of the request task group is a write operation, the write interface is determined as the calling interface of the request task group; the identifier of the request task group and the identifier of the write interface are added to the request task set.

[0092] The embodiment of the present invention provides a task execution method, such as Figure 4 As shown, including:

[0093] Step 401: Obtain a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task.

[0094] Step 402: According to a preset fetching order, fetch the current task group from the request task set.

[0095] The order of taking out can be set according to specific needs. The current task group can be taken out from the request task set in the order of first-in-first-out or last-in-first-out, or the current task group can be taken out from the request task set according to the importance weight of each task group.

[0096] Step 403: Determine whether the task type of the current task group is a read operation according to the interface identifier corresponding to the current task group.

[0097] If yes, then execute the following step 404. If no, then determine whether the task type of the current task group is a write operation, and refer to the following Figure 5 Relevant steps of the illustrated embodiment.

[0098] Step 404: If the task type of the current task group is a read operation, the current task group is added to the set of tasks to be executed.

[0099] Step 405: According to the fetching order, fetch the next task group from the remaining request task set.

[0100] Step 406: Determine whether the task type of the next task group is a read operation according to the interface identifier corresponding to the current task group.

[0101] If yes, the next task group is determined as the current task group, and the above step 404 is executed to add the current task group to the set of tasks to be executed. If no, the following step 407 is executed.

[0102] Step 407: Determine that the target resource allocation mode is a sharing mode.

[0103] When the task type corresponding to the to-be-executed task set is a read operation, the target resource is allocated in a shared manner.

[0104] Step 408: Allocate the target resources to the tasks to be executed in the set of tasks to be executed in a shared manner, and execute the tasks to be executed in a concurrent manner.

[0105] For example, if the current request task set includes:

[0106] Request task group 1: read operation task 1;

[0107] Request task group 2: read operation task 2;

[0108] Request task group 3 (atomic operation): write operation task 1, read operation task 3;

[0109] Request task group 4: write operation task 3.

[0110] Since the operation types of request task group 1 and request task group 2 are both read operations, and the task type of request task group 3 is not a read operation, request task group 1 and request task group 2 are put into the set of tasks to be executed.

[0111] In the embodiment of the present invention, if there are multiple request task groups with the task type of read operation in front of the request task set, these request task groups of read operation are taken out in sequence and added to the set to be executed, and then the target type is allocated to the tasks in the task group to be executed in a shared manner, and the tasks in the task group to be executed are scheduled in a concurrent manner. Compared with the solution of serial read and write single connection, the allocation method of target resources can be arranged more reasonably, reducing the time required to run multiple tasks.

[0112] The embodiment of the present invention provides a task execution method, such as Figure 5 As shown, including:

[0113] Step 501: Obtain a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task.

[0114] Step 502: According to a preset fetching order, fetch the current task group from the request task set.

[0115] The order of taking out can be set according to specific needs. The current task group can be taken out from the request task set in the order of first-in-first-out or last-in-first-out, or the current task group can be taken out from the request task set according to the importance weight of each task group.

[0116] Step 503: Determine whether the task type of the current task group is a write operation according to the interface identifier corresponding to the current task group.

[0117] If yes, then execute the following step 504. If no, then determine whether the task type of the current task group is a read operation, please refer to the above Figure 4 Relevant steps of the illustrated embodiment.

[0118] Step 504: Add the current task group to the set of tasks to be executed.

[0119] Step 505: Determine that the allocation mode of the target resource is an exclusive mode.

[0120] If the type of the pending task set is a write operation, the number of pending task groups in the pending task set is 1. The pending task group may include only one write operation task. The pending task group may also include multiple tasks from the same atomic operation.

[0121] Step 506: Allocate the target resource to the tasks to be executed in the set of tasks to be executed in an exclusive manner, and execute the tasks to be executed.

[0122] In an embodiment of the present invention, if the type of the current request task group in the request task set is a write operation, only the current request task group is added to the to-be-executed set, and then the target resource is exclusively allocated to the current request task group, which can reduce the dirty data problem caused by multiple tasks performing write operations on the target resources at the same time.

[0123] In one embodiment of the present invention, determining the allocation method of the target resources according to the task type corresponding to the set of tasks to be executed includes:

[0124] If the number of the to-be-executed task groups in the to-be-executed task set is 1, and the task type corresponding to the to-be-executed task set is a write operation, it is determined that the allocation mode of the target resource is an exclusive mode;

[0125] According to the allocation method, the target resources are allocated to the set of tasks to be executed, and the requested tasks in the set of tasks to be executed are executed, including:

[0126] The target resource is exclusively allocated to the tasks to be executed in the set of tasks to be executed, and the tasks to be executed are executed.

[0127] If there is only one task group to be executed in the task set to be executed, and the task type corresponding to the task set to be executed is a write operation, the target resource is allocated in an exclusive manner. For example, if the current request task set includes:

[0128] Request task group 1: write operation task 1;

[0129] Request task group 2: write operation task 2;

[0130] Request task group 3 (atomic operation): write operation task 3, read operation task 1;

[0131] Request task group 4: read operation task 2.

[0132] Since the task type of request task group 1 is a write operation, only request task group 1 is placed in the set of tasks to be executed, and the target resource is exclusively allocated to write operation task 1 to prevent other task operations from operating the target resource while write operation task 1 is performing a write operation on the target resource.

[0133] In one embodiment of the present invention, allocating target resources to tasks to be executed in a set of tasks to be executed in an exclusive manner, and executing the tasks to be executed, includes:

[0134] If the number of tasks to be executed in the task group to be executed is 1, the target resource is exclusively allocated to the tasks to be executed in the task group to be executed, and the tasks to be executed are executed;

[0135] If there are multiple tasks to be executed in the task group to be executed, the target resource is allocated to the multiple tasks to be executed in the task group to be executed in an exclusive manner; and the multiple tasks to be executed are executed in a serial manner according to a preset execution order.

[0136] If there is only one task group to be executed in the task set to be executed, and the task group to be executed includes multiple tasks from the same atomic operation, the target resource is allocated in an exclusive manner. For example, if the current request task set includes:

[0137] Request task group 1: write operation task 1, read operation task 2;

[0138] Request task group 2: write operation task 3.

[0139] Among them, if the request task group 1 includes a group of read and write tasks from the same atomic operation, the request task group 1 will be placed in the set of tasks to be executed, and the target resources will be exclusively allocated to the write request task group 1 to prevent the read and write tasks of the atomic operation from being interrupted by other tasks during execution.

[0140] It should be noted that the method of the embodiment of the present invention is more suitable for the request of the task running on the mobile terminal for the database resource. At present, the tasks running on the mobile terminal usually access the database resource in a serial manner to ensure the security of using the database resource.

[0141] The method of the embodiment of the present invention determines a set of tasks to be performed according to the task type of the request task group, and the set of tasks to be performed may include at least one task to be performed. When the task type of the task group to be performed is a read operation, at least one task to be performed is performed in parallel. Therefore, compared with accessing database resources in a serial manner, the efficiency of task execution is improved.

[0142] In addition, the security granularity of the database used by the mobile terminal can only be read or written individually for each connection. Figure 2The two operations in connection 1 in can be regarded as a group of atomic operations. The two operations in connection 1 may be interrupted by other operations. Therefore, if a task involving a group of atomic operations is involved, dirty data may occur. The method of the embodiment of the present invention can place a group of atomic operation tasks in the same task group, thereby ensuring that multiple tasks belonging to the same atomic operation will not be interrupted by other tasks during execution, further ensuring the security of shared data.

[0143] In order to make the technical solution of the present invention easier to understand, a specific implementation method is explained below using the application scenario of processes in a mobile terminal jointly requesting database resources. Figure 6 FIG. 1 is a schematic diagram of a scenario of a multi-task execution method provided by an embodiment of the present invention. Figure 6 As shown in the figure, a SQLite database is deployed on the mobile terminal. A read-write queue is provided on the upper layer of SQLite for the application layer to use. The read-write queue is a task queue, and the tasks put into it by the application layer are closures one by one. The read-write queue only enables one connection to the local database. The read-write queue is used to store the request task group in the request task set. The read-write queue provides two interfaces to the application layer: a read interface and an exclusive write interface. These two interfaces can be operated synchronously or asynchronously.

[0144] When there are multiple threads in the application layer that need to perform database operations, for example, there are 3 threads that need to read and write the database. If the thread is a read-only operation, the read interface is called; if the thread is a write-only operation, the write interface is called; if the thread is a group of read and write operations that need to be performed atomically, the write interface is also called.

[0145] The read and write queues are executed in the order in which the tasks enter, with concurrent reading and serial writing. Figure 6 to explain.

[0146] S1: Thread 3 first uses the write interface to put a write operation task into the read-write queue, and then thread 1 and thread 2 use the read interface to put two read operation tasks into the read-write queue.

[0147] The above-mentioned one write operation and two read operations are three request task groups. The read-write queue is used to store the request task groups in the request task set. The request task set includes three request task groups in total.

[0148] S2: Put the write operation task group into the set of tasks to be executed, allocate database resources to the write operation tasks in an exclusive manner, and execute the write operation tasks.

[0149] Because there is no task executing when the first write operation is placed, the write operation will be executed immediately, while the two read operations of thread 1 and thread 2 will wait because there are exclusive tasks in progress.

[0150] S3: Put the two read operation task groups of thread 1 and thread 2 into the set of tasks to be executed in sequence, allocate database resources to the two read operation tasks in a shared manner, and execute the two read operation tasks in parallel.

[0151] After the write operation of thread 3 is completed, the two read operations of thread 1 and thread 2 will be executed concurrently.

[0152] S4: Thread 2 calls the write interface and puts a set of read and write operation tasks into the read and write queue.

[0153] The group of read and write operation tasks are tasks from the same atomic operation and form a request task group.

[0154] S5: putting the request task group in step S4 into the set of tasks to be executed, allocating database resources to the request task group in an exclusive manner, and executing the operation tasks in the request task in a serial manner.

[0155] Thread 2 uses the write interface to put in another set of read and write operations. This set of read and write operations will wait for the two read operations of thread 1 and thread 2 to complete before executing.

[0156] S6: Thread 1, Thread 2, and Thread 3 use the read interface to put three read operation tasks into the read-write queue one after another.

[0157] S7: sequentially placing the three read operation task groups of thread 1, thread 2 and thread 3 into the set of tasks to be executed, allocating database resources to the three read operation tasks in a shared manner, and executing the three read operation tasks in parallel.

[0158] Thread 1, Thread 2, and Thread 3 each put in three read operations using the read interface. These three read operations will wait for the completion of a set of read and write operations of Thread 2 before executing, and they are executed in a concurrent manner.

[0159] The method of the embodiment of the present invention not only utilizes the lock of SQLite itself, but also provides a read-write queue for the application layer to use. The atomic granularity is determined by the application layer, and ultimately achieves the purpose of efficient and safe concurrent reading and writing of the database.

[0160] In one embodiment of the present invention, the task queue is provided in iOS (mobile operating system) in the form of GCD (GrandCentral Dispatch). In other platforms, tasks can be stored in the form of an array, and the tasks in the scheduling array can be managed in the form of a read-write lock. The final effect achieved is concurrent reading and serial writing. If all current operations are read operations, then all read operations can be executed concurrently, and write operations need to wait. If there is a write operation currently being executed, and only one write operation is being executed, then all other operations will wait. The read-write queue will be executed in the order in which the tasks arrive. If the subsequent operation is still a write operation, then the write operation will continue to be executed serially in an exclusive manner, and if the subsequent operation is several read operations, then these read operations will be executed in a concurrent manner. In iOS, a new concurrent queue needs to be created, the read interface calls the dispatch_async method to add the task to the queue, and the write interface calls the dispatch_barrier_async method to add the task to the queue. Because it is relatively complicated to operate SQLite directly, it can be used in conjunction with a third-party framework, such as FMDB in iOS, which provides FMDB with a read and write queue, such as FMDBBarrierQueue, and uses FMDBBarrierQueue to hand over database read and write operations to FMDB.

[0161] The technical solution of the present invention directly provides a read-write queue for the application layer in the upper layer of SQLite, such as dispatch_async and dispatch_barrier_async in iOS, and adopts the form of single-connection concurrent reading and writing. The application layer puts the read-only operation into the read-write queue using the read interface, and puts the operation of both reading and writing into the read-write queue using the write interface. The read-write queue will create corresponding threads according to the number of tasks and task types in the current queue, reasonably arrange the serial and concurrency of tasks, and use the lock of SQLite itself to ensure the atomicity of each operation of the connection.

[0162] like Figure 7 As shown, an embodiment of the present invention provides a task execution device, including:

[0163] The acquisition module 701 is used to acquire a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task;

[0164] The determination module 702 is used to determine a to-be-executed task set from the request task set according to the task type of at least one request task group; wherein the to-be-executed task set includes at least one to-be-executed task group;

[0165] The allocation module 703 is used to determine the allocation method of the target resources according to the task type corresponding to the set of tasks to be executed;

[0166] The execution module 704 is used to allocate the target resource to the set of tasks to be executed according to the allocation method, and execute the requested task in the set of tasks to be executed.

[0167] In one embodiment of the present invention, it further comprises:

[0168] The adding module 705 is used for: for each request task group, determining the calling interface corresponding to the request task group according to the task type of the request task group; and adding the identifier of the request task group and the identifier of the calling interface to the request task set through the calling interface.

[0169] In one embodiment of the present invention, the determination module 702 is specifically used to: retrieve the current task group from the request task set according to a preset retrieval order;

[0170] Determine the task type of the current task group according to the interface identifier corresponding to the current task group;

[0171] If the task type of the current task group is a read operation, add the current task group to the set of tasks to be executed;

[0172] According to the fetching order, the next task group is fetched from the remaining request task set until the task type of the next task group is not a read operation.

[0173] In one embodiment of the present invention, the determination module 702 is specifically used to: retrieve the current task group from the request task set according to a preset retrieval order;

[0174] Determine the task type of the current task group according to the interface identifier corresponding to the current task group;

[0175] If the task type of the current task group is a write operation, the current task group is added to the set of tasks to be executed.

[0176] In one embodiment of the present invention, the allocation module 703 is specifically used to: if the task type corresponding to the to-be-executed task set is a read operation, determine that the allocation mode of the target resource is a sharing mode;

[0177] The execution module 704 is specifically used to: allocate target resources to the tasks to be executed in the set of tasks to be executed in a shared manner, and execute the tasks to be executed in a concurrent manner.

[0178] In one embodiment of the present invention, the allocation module 703 is specifically used to: if the number of the to-be-executed task groups in the to-be-executed task set is 1, and the task type corresponding to the to-be-executed task set is a write operation, determine that the allocation mode of the target resource is an exclusive mode;

[0179] The execution module 704 is specifically used to: allocate the target resource to the tasks to be executed in the set of tasks to be executed in an exclusive manner, and execute the tasks to be executed.

[0180] In one embodiment of the present invention, the execution module 704 is specifically used to: if the number of the tasks to be executed in the task group to be executed is 1, allocate the target resource to the tasks to be executed in the task group to be executed in an exclusive manner, and execute the tasks to be executed;

[0181] If there are multiple tasks to be executed in the task group to be executed, the target resource is allocated to the multiple tasks to be executed in the task group to be executed in an exclusive manner; and the multiple tasks to be executed are executed in a serial manner according to a preset execution order.

[0182] An embodiment of the present invention provides an electronic device, including:

[0183] one or more processors;

[0184] a storage device for storing one or more programs,

[0185] When one or more programs are executed by one or more processors, the one or more processors implement the method of any of the above embodiments.

[0186] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0187] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0188] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0189] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.

[0190] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0191] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0192] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a sending module, an acquisition module, a determination module, and a first processing module. The names of these modules do not, in some cases, constitute limitations on the modules themselves. For example, the sending module may also be described as a "module for sending a picture acquisition request to the connected server."

[0193] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:

[0194] Obtain a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task;

[0195] Determine a to-be-executed task set from the request task set according to the task type of the at least one request task group; wherein the to-be-executed task set includes at least one to-be-executed task group;

[0196] Determining the allocation method of the target resources according to the task type corresponding to the set of tasks to be executed;

[0197] According to the allocation mode, the target resource is allocated to the set of tasks to be executed, and the requested task in the set of tasks to be executed is executed.

[0198] According to the technical solution of the embodiment of the present invention, by requesting the task type of the task group, determining the allocation method of the task group to be executed and the target resource, allocating the target resource to the set of tasks to be executed, and executing the requested task in the task group to be executed, not only can the use of the target resource be guaranteed to be safe, but also the implementation process is relatively simple and efficient.

[0199] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A task execution method, characterized in that: include: Obtain a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task; a task corresponds to a series of computer operations; and there is no dependency relationship between the request tasks in each request task group and the request tasks in other request task groups; Determine a to-be-executed task set from the request task set according to the task type of the at least one request task group; wherein the to-be-executed task set includes at least one to-be-executed task group; Determine the allocation method of the target resource according to the task type corresponding to the set of tasks to be executed; wherein the task type corresponding to the set of tasks to be executed is determined by the task type of the task group to be executed in the set of tasks to be executed; if the request task group includes a write operation task, or the task in the request task group is a group of atomic operation tasks, then the task type of the request task group is a write operation; if the type of the set of tasks to be executed is a write operation, then the number of the task groups to be executed in the set of tasks to be executed is 1; According to the allocation mode, the target resource is allocated to the set of tasks to be executed, and the requested task in the set of tasks to be executed is executed.

2. The method according to claim 1, characterized in that Further including: For each of the request task groups: determining a calling interface corresponding to the request task group according to a task type of the request task group; The identifier of the request task group and the identifier of the call interface are added to the request task set through the call interface.

3. The method according to claim 2, characterized in that The step of determining a to-be-executed task set from the request task set according to the task type of the at least one request task group includes: According to a preset fetching order, fetch the current task group from the requested task set; Determine the task type of the current task group according to the interface identifier corresponding to the current task group; If the task type of the current task group is a read operation, adding the current task group to the set of tasks to be executed; According to the fetching order, the next task group is fetched from the remaining request task set until the task type of the next task group is not a read operation.

4. The method according to claim 2, characterized in that: The step of determining a to-be-executed task set from the request task set according to the task type of the at least one request task group includes: According to a preset fetching order, fetch the current task group from the requested task set; Determine the task type of the current task group according to the interface identifier corresponding to the current task group; If the task type of the current task group is a write operation, the current task group is added to the set of tasks to be executed.

5. The method according to claim 1 or 3, characterized in that: The determining, according to the task type corresponding to the set of tasks to be executed, the allocation method of the target resources includes: If the task type corresponding to the to-be-executed task set is a read operation, determining that the allocation mode of the target resource is a sharing mode; The step of allocating the target resource to the set of tasks to be executed according to the allocation mode, and executing the requested task in the set of tasks to be executed includes: The target resource is allocated to the tasks to be executed in the set of tasks to be executed in a shared manner, and the tasks to be executed are executed in a concurrent manner.

6. The method according to claim 1 or 4, characterized in that: The determining, according to the task type corresponding to the set of tasks to be executed, the allocation method of the target resources includes: If the number of the to-be-executed task groups in the to-be-executed task set is 1, and the task type corresponding to the to-be-executed task set is a write operation, determining that the allocation mode of the target resource is an exclusive mode; The step of allocating the target resource to the set of tasks to be executed according to the allocation mode, and executing the requested task in the set of tasks to be executed includes: The target resource is exclusively allocated to the tasks to be executed in the set of tasks to be executed, and the tasks to be executed are executed.

7. The method according to claim 6, characterized in that The allocating the target resource to the tasks to be executed in the set of tasks to be executed in an exclusive manner, and executing the tasks to be executed, comprises: If the number of tasks to be executed in the task group to be executed is 1, allocating the target resource to the tasks to be executed in the task group to be executed in an exclusive manner, and executing the tasks to be executed; If there are multiple tasks to be executed in the task group to be executed, the target resource is allocated to the multiple tasks to be executed in the task group to be executed in an exclusive manner; and the multiple tasks to be executed are executed in a serial manner according to a preset execution order.

8. A task execution device, characterized in that: include: An acquisition module is used to acquire a request task set; wherein each request task set includes at least one request task group requesting a target resource, and the request task group includes at least one request task; a task corresponds to a series of computer operations; and there is no dependency relationship between the request tasks in each request task group and the request tasks in other request task groups; A determination module, configured to determine a set of tasks to be executed from the set of requested tasks according to a task type of the at least one requested task group; wherein the set of tasks to be executed includes at least one set of tasks to be executed; An allocation module, used for determining the allocation mode of the target resource according to the task type corresponding to the set of tasks to be executed; wherein the task type corresponding to the set of tasks to be executed is determined by the task type of the task group to be executed in the set of tasks to be executed; if the request task group includes a write operation task, or the task in the request task group is a group of atomic operation tasks, then the task type of the request task group is a write operation; if the type of the set of tasks to be executed is a write operation, then the number of the task groups to be executed in the set of tasks to be executed is 1; The execution module allocates the target resource to the set of tasks to be executed according to the allocation method, and executes the requested task in the set of tasks to be executed.

9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Transaction request processing method and device in blockchain, equipment and medium

    CN111475262A

  • Method and device for processing IO requests

    CN111694770A