Method for managing shared data
By assigning priority constants to parallel tasks in a multi-core processor and using a buffer to manage the priority order of shared variables, the LWW problem is solved, data consistency and task response time are ensured, and the security and functional behavior of the system are improved.
Patent Information
- Application Number
- CN202480009586.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-02-02
- Filing Date
- 2024-01-30
- Publication Date
- 2025-09-05
AI Technical Summary
In a multi-core processor, access to shared variables by multiple software tasks executed in parallel may lead to the Last Writer Win (LWW) problem, resulting in loss and inconsistency of variable values.
By assigning priority constants to each task, managing the priority order of shared variables, using buffer and semaphore mechanisms to ensure data consistency, and adopting priority management methods to determine the update order of variables, the LWW problem is avoided.
It effectively solves the LWW problem, ensures the data consistency of shared variables and the correct execution of tasks in multi-core processors, and improves the response time and security of software tasks.
Smart Images

Figure CN120604216A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of software tasks executed in parallel. Background Art
[0002] Multi-core processors allow multiple software tasks to be executed in parallel. Parallel execution of software tasks is useful, for example, in the field of embedded systems.
[0003] In order to ensure correct functional behavior (eg control of the internal combustion engine) and safety (eg injection cut-off for the internal combustion engine should be very fast to guarantee driver safety), the response time of software tasks is an important factor.
[0004] A software task (or function) typically comprises one or more algorithms, called executables, that are executed when the task itself is initiated by an event in a time domain signal (eg, an event related to the position of a motor).
[0005] The same variable may be used by multiple executables that execute at different times, sometimes in parallel, and the value of the variable may evolve over time based on its value determined at the end of each executable. In some cases, a variable may even be immediately available to other executables as soon as it is modified. If the variable is read / written by concurrent tasks (e.g., concurrent tasks executing in separate cores, each task having one or more executables), the generation of data based on the variable may then result in concurrent access to the variable.
[0006] When there is overlap between read and write accesses to a variable, a last writer win (LWW) problem may occur, which may cause the value of a variable calculated by one task to be lost due to the actions of another concurrent task. Summary of the Invention
[0007] The present disclosure is intended to improve this situation.
[0008] A method for managing data shared through a memory implemented by a computer is proposed, wherein a shared variable VAR is stored in the memory, the variable VAR is accessible by at least two tasks TASK_i (i=1...n, n≥2) executed in parallel with each other, each task TASK_i includes at least one executable item RUN_ij (j=1...k, k≥1), when the task TASK_i includes at least two executable items RUN_ij, these executable items are executed in sequence, a priority variable PRIO_DATA associated with the variable VAR is stored in the memory and initially takes the value PRIO_INI, and the priority constant PRIO_i is stored in the memory A memory is provided for each of the tasks TASK_i, a priority constant PRIO_i characterizing a priority order of the task TASK_i, PRIO_INI is reserved for the lowest priority and is different from each of the priority constants PRIO_i, each of the executable items RUN_ij has an associated priority constant PRIO_RUN_ij characterizing a priority order of the executable items RUN_ij generating the variable VAR, for each of the tasks TASK_i, the priority constant PRIO_i of the task TASK_i is the maximum value of the priority constants PRIO_RUN_ij of the executable items RUN_ij of the task, and the method comprises the following steps:
[0009] -At time t1:
[0010] * initiates the i-th task TASK_i by using the value of the shared variable VAR in memory at time t1, and
[0011] *If PRIO_i>PRIO_DATA at time t1, PRIO_DATA is updated to the value PRIO_i,
[0012] - after the execution of the same i-th task TASK_i at time t2>t1, the i-th task TASK_i generates the value VAR_UPDATE_i of the variable VAR,
[0013] *If PRIO_DATA=PRIO_i at time t2, VAR is updated to the value VAR_UPDATE_i and PRIO_DATA is updated to the value PRIO_INI.
[0014] Methods for managing shared data may have one or more of the following characteristics:
[0015] *The value of each PRIO_i increases strictly in the order of priority of the task TASK_i that generates the variable VAR, PRIO_INI is less than each of the priority constants PRIO_i, preferably PRIO_INI=0.
[0016] * Each task TASK_i is executed on its own core CORE_i;
[0017] *The method further includes: a first buffer BUFF_1 arranged between the memory and the first core CORE_1 on which the first task TASK_1 is executed; and / or a second buffer BUFF_2 arranged between the memory and the second core CORE_2 on which the second task TASK_2 is executed, the first buffer BUFF_1 and the second buffer BUFF_2 including copies of values of a variable VAR used by the tasks TASK_1 and TASK_2 as input and output of the tasks TASK_1 and TASK_2, the first buffer BUFF_1 and the second buffer BUFF_2 being capable of interacting with the memory to modify the variable VAR output from the task TASK_i;
[0018] * the first buffer BUFF_1 and the second buffer BUFF_2 contain copies of the value of the variable VAR as input and output of the executable items RUN_1j, RUN_2j of each of the tasks TASK_1, TASK_2;
[0019] * Create the priority constant PRIO_i offline;
[0020] *Memory is read-write memory, especially RAM memory (Random Access Memory).
[0021] According to another aspect, a computer program is proposed, comprising instructions for carrying out all or part of the method as defined herein when the program is executed by a processor. According to another aspect, a non-transitory computer-readable storage medium is proposed, having such a program stored thereon.
[0022] According to another aspect, a computing device is proposed, comprising: a memory for storing at least some of the instructions of the computer program according to the preceding claim; and a processor accessing the memory to read the above instructions and then executing the above method.
[0023] According to another aspect, a non-transitory computer-readable storage medium is proposed, on which a computer program is stored, for implementing the above method when the computer program is executed by a processor.
[0024] According to another aspect, a vehicle is provided, which has an embedded system including the above-mentioned computing device. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Other features, details, and advantages will become apparent upon reading the following detailed description and analyzing the accompanying drawings, in which:
[0026] Figure 1
[0027] [ Figure 1 ] shows an example of a shared variable in which the LWW problem exists.
[0028] Figure 2
[0029] [ Figure 2 ] shows another example of a shared variable in which the LWW problem exists.
[0030] Figure 3
[0031] [ Figure 3 ] shows another example of a shared variable in which the LWW problem exists.
[0032] Figure 4
[0033] [ Figure 4 ] shows an example of prioritization between multiple tasks, each having one or more executable items.
[0034] Figure 5
[0035] [ Figure 5 ] shows a flowchart for managing priorities among multiple tasks using shared variables.
[0036] Figure 6
[0037] [ Figure 6 ] shows a first example of using shared variables to manage priority between two concurrent tasks.
[0038] Figure 7
[0039] [ Figure 7 ] shows a second example of using shared variables to manage priority between two concurrent tasks.
[0040] Figure 8
[0041] [ Figure 8 ] shows a third example of using shared variables to manage priorities between two concurrent tasks.
[0042] Figure 9
[0043] [ Figure 9] shows a fourth example of using shared variables to manage priorities between two concurrent tasks.
[0044] Figure 10
[0045] [ Figure 10 ] shows a fifth example of using shared variables to manage priority between two concurrent tasks.
[0046] Figure 11
[0047] [ Figure 11 ] shows a sixth example of using shared variables to manage priority between two concurrent tasks.
[0048] Figure 12
[0049] [ Figure 12 ] shows an example of using shared variables to manage priorities between two non-concurrent tasks. DETAILED DESCRIPTION
[0050] Now refer to Figure 1 and Figure 2 , Figure 1 and Figure 2 The diagram illustrates a situation in which a Last Writer Win (LWW) problem may then occur.
[0051] Core CORE 1 contains task TASK A, which contains the executable RUNNABLE A. Core CORE 2, which is parallel to core CORE 1, contains task TASK B, which contains the executable RUNNABLE B. Each executable RUNNABLE A and RUNNABLE B accesses variable VAR at the beginning of execution and updates the value of variable VAR with the value they calculated at the end of execution. Executables RUNNABLE A and RUNNABLE B access and update variable VAR at different times.
[0052] Therefore, for Figure 1 , the variable VAR is first accessed by the executable item RUNNABLE A and then by the executable item RUNNABLE B. The executable item RUNNABLE B ends before the executable item RUNNABLE A, and the value of the variable VAR is therefore updated sequentially by the executable item RUNNABLE B and then by the executable item RUNNABLE A. Therefore, when tasks TASK A and TASK B have completed, the variable has the value updated by task TASK A.
[0053] In the opposite case, Figure 2 , executable item RUNNABLE A ends before executable item RUNNABLE B, and the value of variable VAR is therefore updated sequentially by executable item RUNNABLE A and then executable item RUNNABLE B. Therefore, when task TASK A and task TASK B have completed, variable VAR has the value updated by task TASK B.
[0054] It can be seen that the priority of tasks TASK A and TASK B is not defined by their inherent priority, but rather by their temporality. Therefore, a last writer wins (LWW) problem may occur with respect to the value of variable VAR, because it is the last executable item to update the value of variable VAR that will determine the value of variable VAR when tasks TASK A and TASK B have completed.
[0055] Reference Figure 3 ,Now Figure 1 The situation is illustrated with buffer memories (or buffers) BUF1, BUF2 interacting between a memory containing a variable VAR and tasks TASK A and TASK B, respectively.
[0056] Buffers BUF1 and BUF2 are used to ensure data consistency among concurrent tasks (generally from different cores). Buffering mechanisms are typically used to ensure the stability of variables that are read multiple times in a task and written to in other concurrent tasks, as well as the consistency of a group of variables that are read in a task and written to in other concurrent tasks.
[0057] Buffers BUF1 and BUF2 are created for each of the concurrent tasks TASK A and TASK B. Routines FILL and FLUSH are generated to manage access to data in global memory, and in particular to the variable VAR, and to fill and flush (read and write) the buffers. The use of semaphores prevents these FILL and FLUSH routines from accessing global memory simultaneously. Routine FILL: Using the semaphore, it copies data from global memory to the local buffer (instruction for filling the buffer). Routine FLUSH: Using the semaphore, it copies data from the local buffer to global memory (instruction for clearing the buffer).
[0058] Note that the use of a buffer exacerbates the LWW problem for the variable VAR because it increases the timing between read and write accesses to that variable performed by concurrent tasks. Reads and writes are not performed while the executable is being executed, but rather they are performed at some point after the end of the executable when the buffer memory is flushed. Therefore, Figure 3 In the case of RUNNABLE A, the variable VAR updated by the executable is not as in Figure 1 As in the case of RUNNABLE A, it is updated not at the end of the execution of RUNNABLE A but when the buffer BUF 1 is flushed.
[0059] In response to these situations, a method for managing priorities is proposed. The present invention manages specific priorities for shared, optionally buffered, variables that may be overwritten by concurrent tasks. To avoid LWW situations, a priority order is managed for each shared variable associated with a concurrent task.
[0060] The method essentially consists of two steps. The first step is performed during algorithm design and consists of assigning / determining a priority order for tasks (and executable items). This first step can be performed offline or in real time. The second step is performed dynamically during the execution of the executable items and consists of assigning a value to the variable VAR in real time based on the priority of the executable items / tasks.
[0061] Now refer to Figure 4 , the first step corresponding to the assignment of priority order will be described.
[0062] In the general case of n tasks TASK_i (i=1...n, n≥2) each having j executable items RUN_ij (j=1...k, k≥1) executed in parallel, a shared variable VAR is stored in a memory and is accessible to the parallelly executed tasks TASK_i. According to an embodiment, each of the tasks TASK_i is executed on its own core CORE_i. The memory on which the variable VAR is stored is, for example, a read-write memory, in particular a RAM memory (Random Access Memory).
[0063] Each task TASK_i includes at least one executable item RUN_ij. When a task TASK_i includes two or more executable items RUN_ij, these executable items are executed in sequence. A priority constant PRIO_i is stored in a memory for each of the tasks TASK_i. The priority constant PRIO_i characterizes the priority order of the task TASK_i that generates the variable VAR. The constant PRIO_INI is reserved for the lowest priority and is different from each of the priority constants PRIO_i. Each of the executable items RUN_ij has an associated priority constant PRIO_RUN_ij. The priority constant PRIO_RUN_ij characterizes the priority order of the executable items RUN_ij that generate the variable VAR. For each of the tasks TASK_i, the priority constant PRIO_i of the task TASK_i is the maximum value among the priority constants PRIO_RUN_ij of the executable items RUN_ij of the task.
[0064] Therefore, if you refer to Figure 4 In the specific case of , task TASK A is executed in parallel with task TASK B. Task TASK A includes two executable items RUNNABLE 1 and RUNNABLE 2 that are executed sequentially. Task TASK B includes one executable item RUNNABLE 3.
[0065] Each executable item RUNNABLE 1, RUNNABLE 2, and RUNNABLE 3 has an associated priority constant PRIO_RUN_A1, PRIO_RUN_A2, or PRIO_RUN_B3. To determine the global priority of task TASK A relative to task TASK B, the priority constant PRIO_A for task TASK A is the maximum of the priority constants PRIO_RUN_A1 and PRIO_RUN_A2 for the task's executable items RUNNABLE 1 and RUNNABLE 2. For task TASK B, the priority constant PRIO_B is simply the priority constant PRIO_RUN_B3 for the task's executable item RUNNABLE 3, since that task does not include any executable items other than RUNNABLE 3. Neither the PRIO A nor the PRIO B constants have the value of the initial constant PRIO_INI, which is reserved for the lowest priority.
[0066] According to an embodiment, the priority constant is positive and strictly increasing. According to an embodiment, PRIO_INI=0.
[0067] Therefore, for the subsequent management of the priority of task TASK A relative to task TASK B, the constants PRIO A and PRIO B will be compared. If PRIO A>PRIO B, task TASK A will be prioritized over task TASK B for the generation of variable VAR. And if PRIO B>PRIO A, task TASK B will be prioritized over task TASK A for the generation of variable VAR.
[0068] Now refer to Figure 5 , a second step corresponding to assigning a value to the variable VAR in real time according to the priority order of the task TASK A and the task TASK B will be described.
[0069] In step S1, at time t1, the i-th task TASK_i with priority PRIO_i is initiated by using the value of the variable VAR shared in the memory at time t1 (the variable VAR is read by the task TASK_i), and if at time t1 PRIO_i>PRIO_DATA (i.e., the priority of the task TASK_i is higher than the priority of the task in progress at time t1, see Figure 5 ), PRIO_DATA is updated to the value PRIO_i (ie, the new priority is the priority of task TASK_i).
[0070] The time t1 of reading the variable VAR can be the initial time of execution of the task or a previous time, such as, for example, the time of filling a buffer (routine FILL), if a buffer is used.
[0071] In step S2, after the execution of the same i-th task TASK_i at time t2>t1, the i-th task TASK_i generates the value VAR_UPDATE_i of the variable VAR, if PRIO_DATA=PRIO_i at time t2 (see Figure 5 ), VAR is updated to the value VAR_UPDATE_i and PRIO_DATA is updated to the value PRIO_INI (the variable VAR calculated by task TASK_i is written in the memory).
[0072] The time t2 of writing the variable VAR can be the end time of the execution of the task or a later time, such as, for example, the time of clearing the buffer (routine FLUSH), if a buffer is used.
[0073] For a case where core CORE A includes a task TASK A having two executable items RUNNABLE 1 and RUNNABLE 2 and core CORE B in parallel with core CORE A includes a task TASK B having one executable item RUNNABLE 3 Figure 4 The situation will be referred to Figures 6 to 12 The various applicable cases of the second step are shown. Considering the consistency with the numerical designations used in the definition of the algorithm, Figures 6 to 12 In the example, core CORE A will be identified as CORE_1, task TASK A will be identified as TASK_1, and the executable items of task TASK_1 will be RUN_11 and RUN_12. Similarly, core CORE B will be identified as CORE_2, task TASK B will be identified as task TASK_2, and the executable item of task TASK_2 will be RUN_21.
[0074] Figures 6 to 12 The diagram shows that there are buffers BUFF_1, BUFF_2 (similar to Figure 3 Buffers BUF1 and BUF2 are provided. However, it is possible that only one buffer or no buffer exists. When a buffer exists, the times at which the variable VAR is read and written correspond to the filling (routine FILL) and emptying (routine FLUSH) of the buffer. If no buffer exists, the times at which the variable VAR is read and written may correspond to the start and end of a task.
[0075] exist Figure 6 In this case, the priority level PRIO_2 of task TASK_2 is defined as higher than the priority level PRIO_1 of task TASK_1. Initially, in the RAM memory, the variable PRIO_DATA is 0 (because, in this particular case, PRIO_INI has been selected to be 0). Task TASK_1 starts before task TASK_2. When task TASK_1 starts at time t1, the priority level of task TASK_1 is compared with the value of the variable PRIO_DATA at that time. Since PRIO_DATA = 0, PRIO_1 > PRIO_DATA, and therefore PRIO_DATA is updated with the value PRIO_1. Step S1 described above is completed.
[0076] At the same time, the variable VAR, which is x at this moment, is copied to the buffer BUFF_1. The first executable item RUN_11 of task TASK_1 is initiated using the value x of the variable VAR copied to the buffer BUFF_1 at this moment. When the first executable item RUN_11 ends, it produces an updated value x1 of the variable VAR. The updated value x1 is copied to the buffer BUFF_1 instead of being copied to the memory because the buffer BUFF_1 was not cleared by the instruction. When the second executable item RUN_12 of task TASK_1 is initiated, it takes the value x1 of the variable VAR available in BUFF_1 at that moment. When the second executable item RUN_12 ends, it produces an updated value x2 of the variable VAR. The updated value x2 is copied to the buffer BUFF_1. No other executable items exist in this buffer.
[0077] In order to determine whether the value x2 of the variable VAR can be copied to the memory for use by other tasks, the priority management according to step S2 occurs when the buffer BUFF_1 is emptied. At the time t2 (which is the time of the emptying of the buffer BUFF_1), the priority level PRIO_1 of the task TASK_1 is compared with PRIO_DATA. If PRIO_DATA=PRIO_1, this means that no other concurrent task with a higher priority has been launched between the time t1 and the time t2. In this case, the value x2 of the variable VAR can be copied to the memory. However Figure 6 This is not the case in , where at time t3 between t1 and t2 the task TASK_2 of higher priority PRIO_2 has been initiated. Therefore, at time t2, PRIO_DATA is no longer PRIO_1, and therefore the value x2 of the variable VAR is not copied to the memory but is retained in the buffer BUFF_2.
[0078] exist Figure 6 In this case, at time t2, PRIO_DATA has the value of PRIO_INI (i.e., 0) because at time t2, task TASK_2 has already ended (at t4, which is between t1 and t2). If task TASK_2 had not ended, PRIO_DATA would have the value PRIO_2, and the result would be the same whether the variable x2 was copied or not, because at time t2, PRIO_DATA is still not PRIO_1.
[0079] Priority management from the perspective of task TASK_2 is also managed through steps S1 and S2. Thus, in step S1, at time t3, variable VAR has the value x and PRIO_DATA has the value PRIO_1. PRIO_DATA is compared with PRIO_2. Since PRIO_2 > PRIO_1, task TASK_2 takes a higher priority than task TASK_1 for the management of variable VAR, and PRIO_DATA is updated with the value PRIO_2.
[0080] The value x of the variable VAR is copied to the buffer BUFF_2. The executable item RUN_21 of the task TASK_2 is initiated using the value x of the variable VAR copied to the buffer BUFF_2. When the executable item RUN_21 ends, it generates an updated value y of the variable VAR, which is copied to the buffer BUFF_2.
[0081] In order to determine whether the value y of the variable VAR can be copied to the memory for use by other tasks, the priority management according to step S2 then takes place. At time t4 (which is the time of emptying the buffer BUFF_2), the priority PRIO_2 of the task TASK_2 is compared with PRIO_DATA. If PRIO_DATA=PRIO_2, this means that no other concurrent tasks with a higher priority have been initiated between time t3 and time t4. In this case, the value y of the variable VAR can be copied to the memory. However Figure 6 This is not the case in , where task TASK_2 is the highest priority task, PRIO_2. Therefore, at time t4, PRIO_DATA is still PRIO_2, and the value y of variable VAR is copied to memory, and PRIO_DATA is reinitialized to PRIO_INI. This value persists even until the end of task TASK_1's execution, clearly demonstrating that when tasks TASK_1 and TASK_2 run concurrently, TASK_2 takes precedence over TASK_1 with respect to the value of variable VAR.
[0082] Figure 7 Expressed with Figure 6 The situation is similar to the situation except that the priority PRIO_1 of task TASK_1 is higher than the priority PRIO_2 of task TASK_2.
[0083] Therefore, in task TASK_1, at time t1, the value x of variable VAR is copied into buffer BUFF_1. As for PRIO_DATA, at time t1, PRIO_DATA = 0, so PRIO_DATA < PRIO_1, and thus PRIO_DATA is updated with the value PRIO_1. At the end time t2 of the execution of task TASK_1, PRIO_DATA still equals PRIO_1 because no other concurrent task with a higher priority has been initiated between time t1 and time t2. Therefore, PRIO_DATA is updated to PRIO_INI (i.e., 0), and the value x2 obtained at the end of the second executable item RUN_12 is copied into the memory to become the new value of variable VAR.
[0084] Regarding the management of priorities in task TASK_2, at time t3, the value x of variable VAR is copied into buffer BUFF_2. As for PRIO_DATA, at time t3, PRIO_DATA = PRIO_1, so PRIO_DATA > PRIO_2, and thus PRIO_DATA is not updated with the value PRIO_2. At the time t4 when buffer BUFF_2 of task TASK_2 is emptied, PRIO_DATA still equals PRIO_1, and the value y obtained at the end of the second executable item RUN_21 is not copied into the memory to become the new value of variable VAR.
[0085] The value of VAR at the end of the execution of task TASK_1 will be the value x2 of task TASK_1, which indeed shows the fact that when task TASK_2 is executed concurrently with task TASK_1 in time, task TASK_1 is prior to task TASK_2 with respect to the value of variable VAR.
[0086] In Figure 8 the case of Figure 6 as in Figure 6 the case of
[0087] Regarding the management of priorities in task TASK_1, at time t1 after t3, the value x of variable VAR is copied into buffer BUFF_1. The value of variable VAR has not been modified by task TASK_2 at this time because the latter has not ended at time t1.
[0088] Regarding PRIO_DATA, at time t1, PRIO_DATA = PRIO_2. Since PRIO_1 < PRIO_DATA, PRIO_DATA is not updated with the value PRIO_1 because task TASK_1 is not prior to task TASK_2. At the moment t2 when the buffer BUFF_1 of task TASK_1 is emptied, PRIO_DATA = 0 (because task TASK_2 has ended and the variable PRIO_DATA has been reinitialized), and the value x2 obtained at the end of the second executable item RUN_12 is not copied to the memory to become the new value of the variable VAR.
[0089] Regarding the management of the priority in task TASK_2, at time t3, the value x of the variable VAR is copied to the buffer BUFF_2. Regarding PRIO_DATA, at time t3, PRIO_DATA = PRIO_INI (= 0), so PRIO_DATA < PRIO_2, and thus PRIO_DATA is updated with the value PRIO_2. At the moment t4 when the buffer BUFF_2 of task TASK_2 is emptied, PRIO_DATA still equals PRIO_2, and the value y obtained at the end of the second executable item RUN_21 is copied to the memory to become the new value of the variable VAR, and PRIO_DATA is reinitialized to PRIO_INI.
[0090] This value even remains until the end of the execution of task TASK_1, which truly shows the fact that when task TASK_1 and task TASK_2 are carried out concurrently in time, task TASK_2 is prior to task TASK_1 regarding the value of the variable VAR.
[0091] Figure 9 The situation in Figure 8 is similar to the situation in
[0092] Regarding the management of priorities in task TASK_1, at time t1 after t3, the value x of variable VAR is copied into buffer BUFF_1. Regarding PRIO_DATA, at time t1, PRIO_DATA = PRIO_2. Since PRIO_1 > PRIO_DATA, PRIO_DATA is updated with the value PRIO_1 because task TASK_1 is prioritized over task TASK_2. At time t2 when buffer BUFF_1 of task TASK_1 is emptied, PRIO_DATA still has the value PRIO_1. The value x2 obtained at the end of the second executable item RUN_12 is thus copied into the memory to become the new value of variable VAR, and PRIO_DATA is reinitialized to PRIO_INI.
[0093] Regarding the management of priorities in task TASK_2, at time t3, the value x of variable VAR is copied into buffer BUFF_2. Regarding PRIO_DATA, at time t3, PRIO_DATA = PRIO_INI (=0), so PRIO_DATA < PRIO_2, and thus PRIO_DATA is updated with the value PRIO_2 at t3. At time t4 when buffer BUFF_2 of task TASK_2 is emptied, PRIO_DATA has already been updated to PRIO_1 at t1 because task TASK_1 is prioritized over task TASK_2. Since at t4, PRIO_DATA is not PRIO_2, the value y of variable VAR obtained at the end of the second executable item RUN_21 is not copied into the memory to become the new value of variable VAR when buffer BUFF_2 is emptied.
[0094] The value of VAR at the end of the execution of tasks TASK_1 and TASK_2 is the value at the end of the execution of task TASK_1, which indeed shows the fact that when tasks TASK_1 and TASK_2 are executed concurrently in time, task TASK_1 is prioritized over task TASK_2 for the value of variable VAR.
[0095] In Figure 10 the case where, as in Figure 6 the case where, the priority PRIO_2 of task TASK_2 is higher than the priority PRIO_1 of task TASK_1, and task TASK_2 starts after task TASK_1 in time. In contrast, contrary to Figure 6 the case where, at the buffer, task TASK_2 ends after task TASK_! in time. By applying steps S1 and S2, the management of priorities is thus as follows:
[0096] Regarding the management of priorities in Task TASK_1, at time t1, the value x of the variable VAR is copied into buffer BUFF_1. Regarding PRIO_DATA, at time t1, PRIO_DATA = PRIO_INI (= 0). Since PRIO_1 > PRIO_DATA, PRIO_DATA is updated with the value PRIO_1. At time t2 when buffer BUFF_1 of Task TASK_1 is emptied, PRIO_DATA = PRIO_2 (because Task TASK_2 is initiated after Task TASK_1 and is prior to Task TASK_1), and the value x2 obtained at the end of the second executable item RUN_12 is not copied into the memory to become the new value of variable VAR.
[0097] Regarding the management of priorities in Task TASK_2, at time t3 which is after t1 and before t2, at the time when buffer BUFF_2 of Task TASK_2 is filled, the value x of the variable VAR is copied into buffer BUFF_2. Regarding PRIO_DATA, at time t3, PRIO_DATA = PRIO_1, so PRIO_DATA < PRIO_2, and thus PRIO_DATA is updated with the value PRIO_2 because Task TASK_2 is initiated after Task TASK_1. At time t4 when buffer BUFF_2 of Task TASK_2 is emptied, PRIO_DATA still equals PRIO_2, and the value y obtained at the end of the second executable item RUN_21 is copied into the memory to become the new value of variable VAR, and PRIO_DATA is re-initialized to PRIO_INI (which is 0 in this case).
[0098] Therefore, the value of variable VAR at the end of the execution of Task TASK_1 and Task TASK_2 is the value of variable VAR at the end of the execution of Task TASK_2, which indeed shows the fact that when Task TASK_1 and Task TASK_2 are carried out concurrently in time, Task TASK_2 is prior to Task TASK_1 regarding the value of variable VAR.
[0099] Figure 11 The situation of Figure 10 is similar to that of , except that the priority PRIO_1 of Task TASK_1 is higher than the priority PRIO_2 of Task TASK_2. By applying steps S1 and S2, the management of priorities is thus as follows:
[0100] As for the priority management in task TASK_1, at time t1, the value x of variable VAR is copied to buffer BUFF_1. As for PRIO_DATA, at time t1, PRIO_DATA = PRIO_INI = 0. Since PRIO_1 > PRIO_DATA, PRIO_DATA is updated with the value PRIO_1. At time t2, when buffer BUFF_1 is cleared (after the execution of task TASK_1), PRIO_DATA still has the value of PRIO_1 because even though task TASK_2 was launched at t3 between t1 and t2, its priority is lower, and PRIO_DATA is not updated. The value x2 obtained at the end of the second executable item RUN_12 is copied to memory at t4 to become the new value of variable VAR, and PRIO_DATA is reinitialized to PRIO_INI.
[0101] Regarding priority management in task TASK_2, at time t3, the value x of variable VAR is copied to buffer BUFF_2. Regarding PRIO_DATA, at time t3, PRIO_DATA = PRIO_1, so PRIO_DATA > PRIO_2, because task TASK_1 has priority over task TASK_2, and therefore PRIO_DATA is not updated with the value PRIO_2 at t3. At time t4, when buffer BUFF_2 is cleared (after execution of task TASK_2), PRIO_DATA has been updated to PRIO_INI = 0 at t2. Since PRIO_DATA is not PRIO_2 at t4, the value y of variable VAR obtained at the end of the second executable item RUN_21 of task TASK_2 is not copied to memory to become the new value of variable VAR.
[0102] The value of VAR at the end of execution of tasks TASK_1 and TASK_2 is the value at the end of execution of task TASK_1, which certainly indicates that when tasks TASK_1 and TASK_2 are performed concurrently in time, task TASK_1 has priority over task TASK_2 in terms of the value of variable VAR.
[0103] For illustrative purposes, Figure 12The following illustrates a situation in which there is no temporal concurrency between tasks TASK_1 and TASK_2, and in which task TASK_1 is executed before TASK_2 in time. Regardless of the priorities of TASK_1 and TASK_2 relative to each other, the value of variable VAR at the end of execution of tasks TASK_1 and TASK_2 is the value of variable VAR at the end of execution of task TASK_2, because task TASK_2 was initiated temporally after the execution of task TASK_1. When each non-concurrent task TASK_1 or task TASK_2 begins, the value of PRIO_DATA in memory is equal to PRIO_INI, and each task is prioritized in the dispatch of variable VAR.
Claims
1. A method implemented by a computer for managing data shared through a memory, wherein a shared variable VAR is stored in the memory, the variable VAR is accessible by at least two tasks TASK_i (i=1...n, n≥2) executed in parallel with each other, each task TASK_i includes at least one executable item RUN_ij (j=1...k, k≥1), when the task TASK_i includes at least two executable items RUN_ij, these executable items are executed in sequence, a priority variable PRIO_DATA associated with the variable VAR is stored in the memory and initially takes the value PRIO_INI, and a priority constant PRIO_i is stored in the memory. A memory is provided for each of the tasks TASK_i, a priority constant PRIO_i characterizing a priority order of the task TASK_i, PRIO_INI is reserved for the lowest priority and is different from each of the priority constants PRIO_i, each of the executable items RUN_ij has an associated priority constant PRIO_RUN_ij characterizing a priority order of the executable items RUN_ij generating the variable VAR, for each of the tasks TASK_i, the priority constant PRIO_i of the task TASK_i is the maximum value of the priority constants PRIO_RUN_ij of the executable items RUN_ij of the task, and the method comprises the following steps: -At time t1: * initiates the i-th task TASK_i by using the value of the shared variable VAR in memory at time t1, and *If PRIO_i>PRIO_DATA at time t1, PRIO_DATA is updated to the value PRIO_i, - after the execution of the same i-th task TASK_i at time t2>t1, the i-th task TASK_i generates the value VAR_UPDATE_i of the variable VAR, *If PRIO_DATA=PRIO_i at time t2, VAR is updated to the value VAR_UPDATE_i and PRIO_DATA is updated to the value PRIO_INI.
2. A method for managing shared data as claimed in claim 1, wherein the value of each PRIO_i increases strictly in the order of priority of the task TASK_i that generates the variable VAR, PRIO_INI is less than each of the priority constants PRIO_i, preferably PRIO_INI=0. 3 . The method for managing shared data according to claim 1 , wherein each of the tasks TASK_i is executed on a core CORE_i specific thereto.
4. The method for managing shared data according to any one of the preceding claims, further comprising: A first buffer BUFF_1, which is arranged between the memory and the first core CORE_1 on which the first task TASK_1 is executed; and / or a second buffer BUFF_2, which is arranged between the memory and the second core CORE_2 on which the second task TASK_2 is executed, the first buffer BUFF_1 and the second buffer BUFF_2 include copies of the values of the variables VAR used by tasks TASK_1 and TASK_2 as inputs and outputs of tasks TASK_1 and TASK_2, the first buffer BUFF_1 and the second buffer BUFF_2 are capable of interacting with the memory to modify the variable VAR output from task TASK_i. 5 . The method for managing shared data of claim 4 , wherein the first buffer BUFF_1 and the second buffer BUFF_2 include copies of the value of the variable VAR as input and output of the executable items RUN_1 j and RUN_2 j of each of the tasks TASK_1 and TASK_2 . 6 . The method for managing shared data as claimed in claim 1 , wherein the creation of the priority constants PRIO_i is performed offline.
7. A computer program comprising instructions for carrying out at least part of the method as claimed in any one of the preceding claims when the software is executed by a processor.
8. A computing device comprising: - a memory for storing at least some of the instructions of the computer program as claimed in the preceding claims, - A processor which accesses the memory to read the above instructions and then executes the method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having stored thereon a computer program for implementing the method according to any one of claims 1 to 6 when the computer program is executed by a processor. 10 . A vehicle having an embedded system comprising the computing device according to claim 8 .
