Parallel task data exchange method, device, electronic device and storage medium

The deadlock and real-time problems in data exchange between tasks are solved through the index value exchange mechanism, and the non-blocking data sharing is realized, which improves the real-time and resource utilization efficiency of the system.

CN114020491BActive Publication Date: 2025-08-22HANGZHOU HOLLYSYS AUTOMATION
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111299020.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-04
Publication Date
2025-08-22
Estimated Expiration
2041-11-04

AI Technical Summary

Technical Problem

In the computer's task parallel execution system, deadlocks and poor real-time problems are prone to occur when data exchange between tasks. The existing technology causes task waiting queues through locking mechanisms, affecting the system's real-time and responsiveness.

Method used

The index value exchange mechanism is adopted, and the data is written into the first memory space through the write task, and the index value exchange process is performed with the second memory space after the writing is completed, and the update identifier is activated; the read task determines whether the update identifier is activated. If activated, the index value exchange process is performed with the third memory space, and the data is read out and the identification is set to an inactive state.

Benefits of technology

It realizes non-blocking data exchange, improves the real-timeness of tasks, avoids deadlock problems, reduces system resource consumption, and improves the real-timeness of data sharing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114020491B_ABST
    Figure CN114020491B_ABST
Patent Text Reader

Abstract

The present application discloses a parallel task data exchange method, device, electronic device and computer-readable storage medium, the method comprising: if it is detected that data needs to be written, first data is written into a first memory space by using a write task; the first memory space has a write index value; if the first data is written, the first memory space and the second memory space are locked with an index value exchange process, and an update flag is activated; the second memory space has a transit index value; if it is detected that data needs to be read, it is determined whether the update flag is activated; if the update flag is activated, the second memory space and the third memory space are locked with an index value exchange process; the third memory space has a read index value; the second data is read from the third memory space by using a read task, and the update flag is set to an inactive state; the read and write operations of the task will not cause blocking, and the real-time performance is good.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of multi-tasking technology, and in particular to a parallel task data exchange method, a parallel task data exchange device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In a computer's task parallel execution system, a task itself is an independent unit. During the specific execution of business logic, tasks sometimes need to exchange some data to ensure the effective implementation of business functions. At this time, parallel tasks have read and write operation permissions for the memory space where the data is located. In order to ensure that the tasks obtain the correct data when performing read and write operations on this memory space, certain permissions or methods are required to ensure that only one task can operate on this memory at the same time.

[0003] The execution sequence of the three parallel tasks is as follows Figure 1 As shown in the figure, along the timeline, processor resources are used alternately to execute task logic instructions. This raises a problem: while task 1 is running, it needs to store the collected data in shared memory. However, if the task is interrupted (or preempted), the data write operation may also be interrupted. At this time, task 2 begins execution, but the data has not yet been fully written to the shared memory. If task 2 directly accesses the shared memory at this time, it will read some incorrect data, making the calculation result even more uncertain.

[0004] To address this issue, related technologies leverage operating system mechanisms such as semaphores and mutexes. When task 1 completes storing its data in the shared memory space, it locks the read and write permissions for this space. When other tasks acquire processor resources to execute, they first read the lock status. If the permissions allow read and write access, they proceed with read and write access. Otherwise, they join a waiting queue to wait for task 1 to release the lock, and then run sequentially or according to a priority mechanism to obtain read and write access to the shared memory space. However, the locking approach used in related technologies is prone to deadlock, and tasks need to join a waiting queue, resulting in poor real-time execution.

[0005] Therefore, the problems of deadlock and poor real-time performance in related technologies are technical problems that need to be solved by those skilled in the art. Summary of the Invention

[0006] In view of this, the purpose of this application is to provide a parallel task data exchange method, a parallel task data exchange device, an electronic device and a computer-readable storage medium, which will not cause blocking and has good real-time performance.

[0007] To solve the above technical problems, the present application provides a parallel task data exchange method, comprising:

[0008] If it is detected that data needs to be written, the first data is written into the first memory space using a write task; the first memory space has a write index value;

[0009] If the first data is written, the locked index values ​​of the first memory space and the second memory space are exchanged, and the update flag is activated; the second memory space has a transfer index value;

[0010] If it is detected that data needs to be read, determining whether the update flag is activated;

[0011] If the update flag is activated, the second memory space and the third memory space are locked and the index value exchange process is performed; the third memory space has a read index value;

[0012] The second data is read from the third memory space using a read task, and the update flag is set to an inactive state.

[0013] Optionally, if the update flag is not activated, the following steps are included:

[0014] The second data is read from the third memory space using the read task.

[0015] Optionally, writing the first data into the first memory space by using a write task includes:

[0016] Determining whether the first data is historical data to be written;

[0017] If it is the historical data to be written, the first data is written into the first memory space based on the historical writing position of the first memory space.

[0018] Optionally, the reading the second data from the third memory space using a read task includes:

[0019] determining whether the second data is historical data to be read;

[0020] If it is the historical data to be read, the second data is read out based on the historical read position of the third memory space.

[0021] Optionally, it also includes:

[0022] According to the service type, a first trigger frequency corresponding to data reading and a second trigger frequency corresponding to data writing are set, as well as a magnitude relationship between the first trigger frequency and the second trigger frequency.

[0023] Optionally, the index value exchange process for locking the first memory space and the second memory space includes:

[0024] Activate a lock flag; while the lock flag is activated, reading and writing the first memory space and the second memory space are prohibited;

[0025] exchanging index values ​​between the first memory space and the second memory space;

[0026] The lock flag is set to an inactive state.

[0027] Optionally, the first memory space, the second memory space, and the third memory space have the same size.

[0028] The present application also provides a parallel task data exchange device, comprising:

[0029] A writing module, configured to write first data into a first memory space using a writing task if it is detected that data needs to be written; the first memory space has a writing index value;

[0030] A first exchange module is configured to exchange locked index values ​​of the first memory space and the second memory space and activate an update flag if the first data is written; the second memory space has a transit index value;

[0031] a flag detection module, configured to determine whether the update flag is activated if it is detected that data needs to be read;

[0032] a second exchange module, configured to perform locked index value exchange processing on the second memory space and the third memory space if the update flag is activated; the third memory space has a read index value;

[0033] The readout module is used to read out the second data from the third memory space by using the readout task, and set the update flag to an inactive state.

[0034] The present application also provides an electronic device, including a memory and a processor, wherein:

[0035] The memory is used to store computer programs;

[0036] The processor is used to execute the computer program to implement the above-mentioned parallel task data exchange method.

[0037] The present application also provides a computer-readable storage medium for storing a computer program, wherein the computer program implements the above-mentioned parallel task data exchange method when executed by a processor.

[0038] The parallel task data exchange method provided by the present application, if it is detected that data needs to be written, the first data is written to the first memory space by using a write task; the first memory space has a write index value; if the first data is written, the first memory space and the second memory space are locked with an index value exchange process, and the update flag is activated; the second memory space has a transit index value; if it is detected that data needs to be read, it is determined whether the update flag is activated; if the update flag is activated, the second memory space and the third memory space are locked with an index value exchange process; the third memory space has a read index value; the second data is read from the third memory space by using a read task, and the update flag is set to an inactive state.

[0039] It can be seen that after the first data is written into the first memory space, the method exchanges the locked index values ​​of the first memory space and the second memory space, and activates the update flag. Before the exchange, the first memory space has a write index value, and the second memory space has a transit index value. After the exchange, the original first memory space has a transit index value and is converted to a new second memory space. Correspondingly, the original second memory space has a write index value and is converted to a new first memory space. When you want to read data, first determine whether the update flag is activated. If it is activated, the locked index value exchange is performed on the second memory space and the third memory space. After the exchange, the original second memory space has a read index value and is converted to a new third memory space, and the original third memory space has a transit index value and is converted to a new second memory space. After the conversion is completed, the read task reads the second data from the third memory space and sets the update flag to an inactive state. According to the above process, the written input can be transferred from the first memory space to the second memory space, and further transferred to the third memory space, and then read out. The index value exchange process described above is a locking process to ensure that it can be completed normally, while the data reading and writing process does not require locking. Because the index value exchange process is extremely short, the lock duration is also extremely short. Therefore, the reading and writing operations of the task will not be blocked, and the real-time performance is improved. High-priority tasks do not need to wait for unlocking, and deadlock issues will not occur. At the same time, this data sharing method does not require the use of message mailboxes or pipeline communication technologies to exchange data between tasks, thereby reducing the consumption of system resources and improving the real-time performance of data sharing.

[0040] In addition, the present application also provides a parallel task data exchange device, an electronic device, and a computer-readable storage medium, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.

[0042] Figure 1 A current multi-task parallel timing diagram provided by an embodiment of the present application;

[0043] Figure 2 A flow chart of a parallel task data exchange method provided in an embodiment of the present application;

[0044] Figure 3 A timing diagram of multi-task data exchange provided in an embodiment of the present application;

[0045] Figure 4 A schematic diagram of the structure of a parallel task data exchange device provided in an embodiment of the present application;

[0046] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0047] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0048] like Figure 1 As shown in the figure, currently, multi-task data exchange is usually carried out by locking the memory space when a task accesses it, and other tasks wait for the unlocking before continuing to access it. This method has the following problems:

[0049] Problem 1: To obtain the data to be exchanged, the task needs to wait, and real-time performance is forced to be interrupted.

[0050] To obtain data in the shared memory space, different tasks have to wait for the tasks that already occupy the shared memory space to release access rights to the space. This reduces the real-time performance of the tasks. In special cases, in order to ensure the real-time execution of other business logic within the task, it is necessary to consider changing the task content division and design.

[0051] Question 2: Deadlock problem.

[0052] If a low-priority task locks access to shared memory space, and a high-priority task needs to wait for unlocking to obtain access, the high-priority task will have more opportunities to obtain CPU permissions than the low-priority task, which may cause a deadlock. Once a deadlock occurs, the overall system responsiveness and business processing capabilities will be greatly reduced.

[0053] To resolve deadlock, a general operating system needs to detect the duration of a single task lock. After a timeout, the operating system temporarily flips or raises the priority of the low-priority task. After the original low-priority task is completed, the lock is released and the task's original priority is restored. This causes the task priority to change, making the operating system's management tasks more complex. The increased software or management complexity may lead to other system problems.

[0054] Problem 3: The performance and real-time requirements of multiple data copies are not met.

[0055] The method of exchanging data between tasks through message mailboxes or pipe communication technology has two shortcomings when exchanging large amounts of data. First, if the completion relies on the mailbox provided by the operating system, the operating system's resources will be consumed more. For example, dynamic application of mailbox space requires a large amount of heap memory space; second, the large amount of data copying between the application layer and the operating system layer is time-consuming. To complete the data exchange, the application layer needs to copy the data into the information carrier space provided by the operating system mailbox or other mechanisms. After the operating system delivers the data to the destination task, the data needs to be copied from the operating system level to the application layer space. These two copies will consume a lot of system time, which is not conducive to the system's real-time requirements and has high requirements for memory copy performance.

[0056] In order to solve the above problems, we provide a new parallel task data exchange method. Please refer to Figure 2 , Figure 2 A flow chart of a parallel task data exchange method provided in an embodiment of the present application. The method includes:

[0057] S101: If it is detected that data needs to be written, first data is written into a first memory space using a write task.

[0058] Among them, the first memory space has a write index value. The write index value is used to indicate that the corresponding memory space is used to store the written data. A write task refers to a task that needs to write data to the storage space. The task type and content are not limited. For example, in actual applications, there is an algorithm implementation that requires a data acquisition task to put the collected input data into a memory space. The algorithm's calculation task needs to use this data as input parameters. The calculation task accesses the data shared by the acquisition task. After the calculation is completed, the calculation result needs to be delivered to the external output task to perform a specific output action. The above-mentioned data acquisition tasks and calculation tasks both need to write the input into the storage space, so they can all be used as write tasks.

[0059] The first data refers to data that needs to be written. When any writing task needs to write data, the index values ​​corresponding to the respective memory spaces are searched, and the memory space corresponding to the write index value is determined as the first memory space.

[0060] In one embodiment, the first data is brand new data. In this case, the first data is written starting from the address starting point of the first memory space. In another embodiment, the first data is historical data to be written, that is, the first task is interrupted while writing data, and another task reads the storage space and rewrites the first data after the reading is completed. In this case, the process of using the write task to write the first data to the first memory space may include the following steps:

[0061] Step 11: Determine whether the first data is historical data to be written.

[0062] Step 12: If the data is historical data to be written, the first data is written into the first memory space based on the historical writing position of the first memory space.

[0063] Historical data to be written refers to data that has not been written due to the interruption of the writing task when writing data last time. Specifically, a write interruption flag can be set, and the interruption flag can be activated when the writing task is interrupted. When writing the first data, if it is detected that the interruption flag is activated, the first data is determined to be historical data to be written. If it is detected that it is historical data to be written, the historical write position can be obtained, and the first data can be written to the first memory space based on the historical write position. The historical write position can be recorded when the writing of data is interrupted.

[0064] S102: If the first data is written completely, the locked index values ​​of the first memory space and the second memory space are exchanged, and an update flag is activated.

[0065] Among them, the second memory space has a transit index value. The transit index value is used to indicate that the memory space is used to transit data, and the memory space designated by it is the second memory space. After the first data is written, the index values ​​of the first memory space and the second memory space can be exchanged, and the exchange is a locked index value exchange process. By exchanging the index values ​​between the first memory space and the second memory space, the identities of the first memory space and the second memory space can be switched, and the first data written in the above steps can be transferred to the second memory space. By locking the above steps, it can be ensured that the index value exchange is completed to avoid abnormalities. Specifically, the process of locking the index value exchange process of the first memory space and the second memory space can specifically include:

[0066] Step 21: Activate the lock flag.

[0067] Step 22: Exchange the index values ​​between the first memory space and the second memory space.

[0068] Step 23: Set the lock flag to the inactive state.

[0069] Among them, reading and writing the first memory space and the second memory space are prohibited during the activation of the lock flag. By activating the lock flag, each task can be informed that the first memory space and the second memory space cannot be read, avoiding data errors caused by data reading and writing during the exchange process. After the index values ​​of the first memory space and the second memory space are exchanged, the original first memory space is converted to the new second memory space, and the original second memory space is converted to the new first memory space, which is equivalent to the written first data being transferred from the first memory space to the second memory space. This conversion process is faster than using message mailboxes or pipe communication technology to achieve data exchange between tasks.

[0070] After the index value is exchanged, the update flag is activated. The update flag is a flag indicating that new data has been read, and its specific form is not limited.

[0071] S103: If it is detected that data needs to be read, it is determined whether the update flag is activated.

[0072] S104: If the update flag is activated, the locked index values ​​of the second memory space and the third memory space are exchanged.

[0073] S105: Read the second data from the third memory space using a read task, and set the update flag to an inactive state.

[0074] If it is detected that data needs to be read, it is first determined whether there is new data that needs to be read, specifically whether the update flag is activated. If the update flag is not activated, it means that no new data has been written, and therefore no new data needs to be read. Therefore, the second data can be directly read from the third memory space using the read task. The third memory space has a read index value, and the data therein is used to be read by the read task. It should be noted that in order to ensure the reliability of data writing and reading, the space sizes of the first memory space, the second memory space, and the third memory space in this embodiment are the same.

[0075] Furthermore, if the update flag is not activated, similar to writing data, since the read task may be interrupted during the data reading process, in this case, when reading the data, it is possible to first determine whether the second data is historical data to be read. Historical data to be read refers to data that was not read due to the interruption of the read task during the previous data read. If it is historical data to be read, the second data is read based on the historical read position of the third memory space. The determination method for historical data to be read is similar to that for historical data to be written.

[0076] Furthermore, since the frequency of data writing and reading cannot be consistent, the first trigger frequency corresponding to data reading and the second trigger frequency of data writing can be set separately according to the business type, as well as the size relationship between the first trigger frequency and the second trigger frequency, to avoid the newly written data being overwritten and causing data loss in the fast writing scenario, or to avoid the written data being read out repeatedly due to the lack of time to write new input in the slow writing scenario.

[0077] If the update flag is activated, it indicates that new data is being read. Since data reading can only be performed through the third memory space, the locked index values ​​of the second and third memory spaces can be swapped, converting the original second memory space into the new third memory space and vice versa. After the swap is complete, the second data is read from the third memory space using the read task, and the update flag is reset to an inactive state.

[0078] Please refer to Figure 3 , Figure 3 This is a multi-task data exchange timing diagram provided for an embodiment of the present application. Three memory spaces of equal size are designed, and their indexes are named w (write index value), s (swap index value), and r (read index value). The index values ​​can be 0, 1, and 2, respectively. A flag variable is also set to indicate whether the storage space has been updated.

[0079] When any task (i.e., task 1) writes to the shared space, it only writes to the space with index w (i.e., index value 0). The write process may be interrupted. In this case, the write operation is stopped and the write operation is resumed after the read operation is complete. After writing all the data to be updated, the flag variable is set to T, and the index s (i.e., index value 1) and the index value of w are swapped. During the index swap, the mutual exclusion mechanism provided by the operating system is used to lock the swap process. After the swap is complete, the lock is unlocked. When another task reads the shared space, it first checks whether the flag variable is F. If not, it reads the space with index r (i.e., index value 2). If so, the index values ​​of r and s are swapped. Similarly, during the index swap, the mutual exclusion mechanism provided by the operating system is used to lock the swap process. After the swap is complete, the lock is unlocked and the space with index r is read again.

[0080] Applying the parallel task data exchange method provided in the embodiment of the present application, after the first data is written into the first memory space, the first memory space and the second memory space are subjected to a locked index value exchange process, and the update flag is activated. Before the exchange, the first memory space has a write index value, and the second memory space has a transit index value. After the exchange, the original first memory space has a transit index value and is converted to a new second memory space. Correspondingly, the original second memory space has a write index value and is converted to a new first memory space. When you want to read data, first determine whether the update flag is activated. If it is activated, the second memory space and the third memory space are subjected to a locked index value exchange process. After the exchange, the original second memory space has a read index value and is converted to a new third memory space, and the original third memory space has a transit index value and is converted to a new second memory space. After the conversion is completed, the read task reads the second data from the third memory space and sets the update flag to an inactive state. According to the above process, the written input can be transferred from the first memory space to the second memory space, and further transferred to the third memory space, and then read out. The index value exchange process described above is a locking process to ensure that it can be completed normally, while the data reading and writing process does not require locking. Because the index value exchange process is extremely short, the lock duration is also extremely short. Therefore, the reading and writing operations of the task will not be blocked, and the real-time performance is improved. High-priority tasks do not need to wait for unlocking, and deadlock issues will not occur. At the same time, this data sharing method does not require the use of message mailboxes or pipeline communication technologies to exchange data between tasks, thereby reducing the consumption of system resources and improving the real-time performance of data sharing.

[0081] The following is an introduction to a parallel task data exchange device provided in an embodiment of the present application. The parallel task data exchange device described below and the parallel task data exchange method described above can be referenced to each other.

[0082] Please refer to Figure 4 , Figure 4 A schematic structural diagram of a parallel task data exchange device provided in an embodiment of the present application includes:

[0083] The writing module 110 is configured to write the first data into the first memory space using a writing task if it is detected that data needs to be written; the first memory space has a writing index value;

[0084] The first exchange module 120 is configured to exchange locked index values ​​of the first memory space and the second memory space and activate an update flag if the first data is written; the second memory space has a transit index value;

[0085] The flag detection module 130 is used to determine whether the update flag is activated if it is detected that data needs to be read;

[0086] The second exchange module 140 is configured to perform a locked index value exchange process on the second memory space and the third memory space if the update flag is activated; the third memory space has a read index value;

[0087] The read module 150 is configured to read the second data from the third memory space using a read task and set the update flag to an inactive state.

[0088] Optionally include:

[0089] A direct reading module is configured to read the second data from the third memory space using the read task if the update flag is not activated.

[0090] Optionally, the readout module 150 includes:

[0091] a reading judgment unit, configured to judge whether the second data is historical data to be read;

[0092] A history reading unit is configured to read out the second data based on a history read position of the third memory space if the second data is the history data to be read out.

[0093] Optionally, the writing module 110 includes:

[0094] a write determination unit, configured to determine whether the first data is historical data to be written;

[0095] A history writing unit is configured to write the first data into the first memory space based on a history writing position of the first memory space if the data is the history data to be written.

[0096] Optionally, it also includes:

[0097] The setting module is used to set a first trigger frequency corresponding to data reading and a second trigger frequency corresponding to data writing, as well as a magnitude relationship between the first trigger frequency and the second trigger frequency according to a business type.

[0098] Optionally, the first switching module 120 includes:

[0099] A locking unit, configured to activate a lock flag; during activation of the lock flag, reading and writing of the first memory space and the second memory space are prohibited;

[0100] an exchange unit, configured to exchange index values ​​between the first memory space and the second memory space;

[0101] The unlocking unit is used to set the lock mark position to an inactive state.

[0102] Optionally, the first memory space, the second memory space, and the third memory space have the same size.

[0103] The electronic device provided in the embodiment of the present application is introduced below. The electronic device described below and the parallel task data exchange method described above can be referenced to each other.

[0104] Please refer to Figure 5 , Figure 5 The electronic device 100 may include a processor 101 and a memory 102, and may further include one or more of a multimedia component 103, an information input / output (I / O) interface 104, and a communication component 105.

[0105] The processor 101 is used to control the overall operation of the electronic device 100 to complete all or part of the steps in the above-mentioned parallel task data exchange method; the memory 102 is used to store various types of data to support the operation of the electronic device 100. For example, this data may include instructions for any application or method operating on the electronic device 100, as well as application-related data. The memory 102 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.

[0106] The multimedia component 103 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in the memory 102 or sent through the communication component 105. The audio component also includes at least one speaker for outputting audio signals. The I / O interface 104 provides an interface between the processor 101 and other interface modules. The above-mentioned other interface modules may be a keyboard, a mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 105 is used for wired or wireless communication between the electronic device 100 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G or 4G, or a combination of one or more of them, so the corresponding communication component 105 may include: a Wi-Fi component, a Bluetooth component, an NFC component.

[0107] The electronic device 100 can 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 execute the parallel task data exchange method provided in the above embodiment.

[0108] The computer-readable storage medium provided in an embodiment of the present application is introduced below. The computer-readable storage medium described below and the parallel task data exchange method described above can be referenced to each other.

[0109] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned parallel task data exchange method are implemented.

[0110] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., which can store program codes.

[0111] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.

[0112] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0113] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0114] Finally, it should be noted that, in this document, relationships such as first and second, etc., are used solely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms include, comprise, or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0115] This document uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.

Claims

1. A parallel task data exchange method, characterized in that: include: If it is detected that data needs to be written, the first data is written into the first memory space using a write task; The first memory space has a write index value; If the first data is written, the locked index values ​​of the first memory space and the second memory space are exchanged, and an update flag is activated; The second memory space has a transfer index value; If it is detected that data needs to be read, determining whether the update flag is activated; If the update flag is activated, performing locked index value exchange processing on the second memory space and the third memory space; The third memory space has a read index value; The second data is read from the third memory space using a read task, and the update flag is set to an inactive state.

2. The parallel task data exchange method according to claim 1, characterized in that: If the update flag is not activated, including: The second data is read from the third memory space using the read task.

3. The parallel task data exchange method according to claim 2, characterized in that: The reading the second data from the third memory space by using the read task includes: determining whether the second data is historical data to be read; If it is the historical data to be read, the second data is read out based on the historical read position of the third memory space.

4. The parallel task data exchange method according to claim 1, characterized in that: The step of writing the first data into the first memory space by using the write task includes: Determining whether the first data is historical data to be written; If it is the historical data to be written, the first data is written into the first memory space based on the historical writing position of the first memory space.

5. The parallel task data exchange method according to claim 1, characterized in that: Also includes: According to the service type, a first trigger frequency corresponding to data reading and a second trigger frequency corresponding to data writing are set, as well as a magnitude relationship between the first trigger frequency and the second trigger frequency.

6. The parallel task data exchange method according to claim 1, characterized in that: The index value exchange process of locking the first memory space and the second memory space includes: Activate a lock flag; while the lock flag is activated, reading and writing the first memory space and the second memory space are prohibited; exchanging index values ​​between the first memory space and the second memory space; The lock flag is set to an inactive state.

7. The parallel task data exchange method according to claim 1, characterized in that: The first memory space, the second memory space and the third memory space have the same size.

8. A parallel task data exchange device, characterized in that: include: A writing module, configured to write the first data into the first memory space using a writing task if it is detected that data needs to be written; The first memory space has a write index value; a first exchange module, configured to exchange locked index values ​​of the first memory space and the second memory space and activate an update flag if the first data is written; The second memory space has a transfer index value; a flag detection module, configured to determine whether the update flag is activated if it is detected that data needs to be read; a second exchange module, configured to perform locked index value exchange processing on the second memory space and the third memory space if the update flag is activated; The third memory space has a read index value; The readout module is used to read out the second data from the third memory space by using the readout task, and set the update flag to an inactive state.

9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store computer programs; The processor is configured to execute the computer program to implement the parallel task data exchange method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that Used to store a computer program, wherein when the computer program is executed by a processor, the parallel task data exchange method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Data processing method, storage system and exchange device

    CN110546620A

  • Data read-write priority balancing method, system and device and storage medium

    CN112416556A