Thread priority control method and related device

By setting the priority of the DDS receiving thread to the highest or the higher of the initial priority and the candidate priority, the blocking problem caused by the DDS receiving thread waiting for other threads is solved, and the message processing efficiency is improved.

CN120630801APending Publication Date: 2025-09-12BEIJING JINGWEI HIRAIN TECH CO INC
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202510726495.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-30
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

When the DDS receiving thread waits for other high-priority threads to process tasks, the DDS processing thread is blocked and cannot receive and process messages in time.

Method used

By determining the priority of the DDS processing thread in the suspended state in the application, the priority of the DDS receiving thread is set to the highest priority or the higher of the initial priority and the candidate priority to ensure that the priority of the DDS receiving thread is not lower than that of other DDS processing threads and avoid resource preemption.

Benefits of technology

This reduces the possibility of low-priority threads blocking high-priority DDS processing threads, ensures that DDS messages can be processed in a timely manner, and improves message transmission efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120630801A_ABST
    Figure CN120630801A_ABST
Patent Text Reader

Abstract

The invention discloses a thread priority control method and a related device, and relates to the technical field of information, the method is applied to DDS communication middleware deployed in an electronic control unit of a vehicle, and the method comprises the following steps: determining each target DDS processing thread currently in a suspended state in an application program; based on the priority of each target DDS processing thread in the application program, determining a candidate priority corresponding to the target DDS processing thread with the highest priority; the priority of the DDS receiving thread in the application program is set to be a target priority, and the target priority is the highest one of the initial priority distributed by the application program to the DDS receiving thread and the candidate priority. According to the invention, the situation that the application program cannot receive and process the DDS message in time can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information technology, and in particular to a thread priority control method and related devices. Background Art

[0002] Data Distribution Service (DDS) is a next-generation distributed real-time communication middleware protocol widely used in the field of autonomous vehicles. DDS communication middleware can be used to transmit and distribute messages between applications on various electronic control units in a vehicle, as well as between different applications on the same electronic control unit.

[0003] To transmit and distribute messages through the DDS communication middleware, the application needs to create a DDS receiving thread and at least one DDS processing thread. After receiving a DDS message through the DDS receiving thread, the application can process the DDS message through the DDS processing thread.

[0004] However, during the process of the DDS receiving thread receiving DDS messages, if there is another thread with a higher priority than the DDS receiving thread that needs to perform task processing, the DDS receiving thread needs to wait for the other thread to complete task processing before it can continue to receive DDS messages. Therefore, even if the priority of the DDS processing thread is higher than that of the other thread, the operation of the DDS processing thread will be blocked because the DDS receiving thread is waiting for the other thread to perform task processing, making it impossible for the application to receive and process DDS messages in a timely manner. Summary of the Invention

[0005] In view of the above problems, the present application provides a thread priority control method and related devices to reduce the situation where the application cannot receive and process DDS messages in a timely manner.

[0006] On the one hand, the present application provides a thread priority control method, which is applied to DDS communication middleware deployed in a vehicle's electronic control unit, comprising:

[0007] Determine the target DDS processing threads that are currently in a suspended state in the application;

[0008] Determine, based on the priorities of the target DDS processing threads in the application, a candidate priority corresponding to the target DDS processing thread with the highest priority;

[0009] The priority of the DDS receiving thread in the application is set as a target priority, wherein the target priority is the highest one of the initial priority assigned by the application to the DDS receiving thread and the candidate priority.

[0010] In a possible implementation, determining each target DDS processing thread currently in a suspended state in the application includes:

[0011] In response to a DDS processing thread of the application currently being suspended, at least one target DDS processing thread in the application currently in a suspended state is determined.

[0012] In another possible implementation, before the DDS processing thread of the application is suspended, the method further includes: setting the priority of the DDS receiving thread in the application to the initial priority assigned by the application to the DDS receiving thread;

[0013] Setting the priority of the DDS receiving thread in the application program to the target priority includes:

[0014] If the priority currently set for the DDS receiving thread in the application is lower than the candidate priority, setting the priority of the DDS receiving thread to the candidate priority;

[0015] If the priority currently set for the DDS receiving thread is not lower than the candidate priority, the priority currently set for the DDS receiving thread is maintained unchanged.

[0016] In yet another possible implementation, in response to a DDS processing thread of the application currently being suspended, determining at least one target DDS processing thread in the application currently in a suspended state includes:

[0017] In response to a DDS processing thread currently being suspended in the application, obtaining a thread identifier and a priority of the currently suspended target DDS processing thread, and associating the thread identifier and the priority of the currently suspended target DDS processing thread and storing them in a target thread list, wherein the target thread list includes the thread identifiers of each target DDS processing thread currently in a suspended state in the application and the priority corresponding to the thread identifier of each target DDS processing thread;

[0018] The determining, based on the priorities of the target DDS processing threads in the application, the candidate priority corresponding to the target DDS processing thread with the highest priority, includes:

[0019] Based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads, a candidate priority corresponding to the thread identifier with the highest priority is determined.

[0020] In yet another possible implementation, determining each target DDS processing thread currently in a suspended state in the application includes:

[0021] In response to an awakened DDS processing thread currently existing in the application, at least one target DDS processing thread currently in a suspended state in the application is determined.

[0022] In yet another possible implementation, setting the priority of the DDS receiving thread in the application to the target priority includes:

[0023] If the initial priority of the DDS receiving thread in the application is lower than the candidate priority, setting the priority of the DDS receiving thread to the candidate priority;

[0024] If the initial priority of the DDS receiving thread is not lower than the candidate priority, the priority of the DDS receiving thread is set to the initial priority of the DDS receiving thread.

[0025] In yet another possible implementation, in response to the application currently having an awakened DDS processing thread, determining at least one target DDS processing thread in the application currently in a suspended state includes:

[0026] In response to the application currently having an awakened DDS processing thread, determining the thread identifier of the currently awakened target DDS processing thread;

[0027] Deleting the thread ID and priority of the currently awakened target DDS processing thread from a target thread list, wherein the target thread list includes the thread IDs of each target DDS processing thread currently in a suspended state in the application program and the priorities corresponding to the thread IDs of each target DDS processing thread;

[0028] The determining, based on the priorities of the target DDS processing threads in the application, the candidate priority corresponding to the target DDS processing thread with the highest priority, includes:

[0029] Based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads, a candidate priority corresponding to the thread identifier with the highest priority is determined.

[0030] In another aspect, the present application further provides a thread priority control device, which is applied to DDS communication middleware deployed in a vehicle's electronic control unit, comprising:

[0031] A thread determination unit, configured to determine each target DDS processing thread currently in a suspended state in the application;

[0032] A priority determination unit, configured to determine a candidate priority corresponding to a target DDS processing thread with the highest priority based on the priorities of the target DDS processing threads in the application program;

[0033] The priority setting unit is configured to set the priority of the DDS receiving thread in the application to a target priority, wherein the target priority is the highest one of the initial priority assigned by the application to the DDS receiving thread and the candidate priority.

[0034] In another aspect, the present application further provides a vehicle-mounted terminal, comprising an electronic control unit and a memory;

[0035] Communication middleware is deployed in the electronic control unit;

[0036] The electronic control unit is configured to execute the thread priority control method described above through the communication middleware;

[0037] The memory is used to store the program required by the electronic control unit to perform operations.

[0038] On the other hand, the present application also provides a computer-readable storage medium, characterized in that the computer-readable storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the thread priority control method described in any one of the above.

[0039] On the other hand, the present application also provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any thread priority control method provided in the embodiments of the present application.

[0040] From the above content, it can be seen that in this application, based on the priorities of each target DDS processing thread in a suspended state in the application, the candidate priority corresponding to the target DDS thread with the highest priority is determined, and the higher of the candidate priority and the initial priority assigned by the application to the DDS receiving thread is set as the priority of the DDS receiving thread, so that the priority of the DDS receiving thread is not lower than the priority of each suspended DDS processing thread, thereby reducing the situation where the priority of other threads is lower than the priority of the suspended DDS processing thread but higher than the priority of the DDS receiving thread, and naturally reducing the situation where the higher priority DDS processing thread cannot obtain and process DDS messages in time due to other threads with lower priority than the DDS processing thread preempting the resources of the DDS receiving thread. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.

[0042] Figure 1 A flowchart of the thread priority control method provided by this application;

[0043] Figure 2 An example diagram showing a situation in which a high-priority DDS processing thread is blocked due to the preemption of resources of a low-priority DDS receiving thread;

[0044] Figure 3 An example diagram showing the scheduling order of multiple threads after adopting the solution of the present application;

[0045] Figure 4 A schematic diagram of another flow chart of the thread priority control method provided by this application;

[0046] Figure 5 A schematic diagram of another flow chart of the thread priority control method provided by this application;

[0047] Figure 6 This is an example diagram of the target thread list in this application;

[0048] Figure 7 A schematic diagram of the structure of a thread priority control device provided by this application;

[0049] Figure 8 A schematic diagram of the structure of the electronic device provided in this application. DETAILED DESCRIPTION

[0050] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation methods of the present application are only used to explain the specific embodiments of the present application and are not intended to limit the present application. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0051] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0052] like Figure 1 , shows a flow chart of a thread priority control method provided by an embodiment of the present application. The method of this embodiment is applied to the Data Distribution Service (DDS) communication middleware deployed in a vehicle's Electronic Control Unit (ECU). The ECU is also called an electronic controller. The communication middleware in the ECU is a program module running in the ECU for implementing message subscription and distribution. The method of this embodiment includes:

[0053] S101 , determining each target DDS processing thread currently in a suspended state in an application program.

[0054] In this application, the application may be any application running in an ECU that needs to use DDS communication middleware to exchange messages with other applications in the ECU or applications in other ECUs.

[0055] The DDS processing thread in the application is a thread created by the application to process DDS messages. The DDS processing thread can obtain DDS messages to be distributed to the application from the DDS communication middleware and process the obtained DDS messages.

[0056] It is understandable that an application can subscribe to messages of multiple topics from the DDS communication middleware, and messages of different topics may need to be processed by different DDS processing threads. Therefore, in this application, the application can create at least one DDS processing thread, and the DDS messages processed by different DDS processing threads belong to different topics.

[0057] In this application, for the sake of distinction, the DDS processing thread in the suspended state in the application is referred to as the target DDS processing thread.

[0058] As you can understand, to receive DDS messages, an application creates a DDS receiving thread by calling a specific interface in the DDS communication middleware. This DDS receiving thread is used to obtain DDS messages. This DDS receiving thread can obtain DDS messages for various topics required by the application. Based on this, the DDS receiving thread stores DDS messages for different topics in the message buffers corresponding to those topics in the DDS communication middleware.

[0059] Based on this, the DDS processing thread in the application can request DDS messages for the corresponding topic from the DDS communication middleware. If the DDS communication middleware determines that there are no DDS messages in the message buffer for the topic corresponding to the DDS processing thread, then there are no messages that need to be processed by the DDS processing thread. To reduce resource consumption, the DDS communication middleware will notify the application to suspend the DDS processing thread, and the application will suspend the DDS processing thread. Therefore, the DDS communication middleware can determine which DDS processing threads in the application are currently suspended and in a suspended state.

[0060] The DDS processing thread is in a suspended state, that is, the execution of the DDS processing thread is suspended. For example, the DDS processing thread is in a dormant state or a waiting state, so that it cannot be executed temporarily.

[0061] S102 : Determine a candidate priority level corresponding to a target DDS processing thread with the highest priority level based on the priorities of the target DDS processing threads in the application program.

[0062] It is understandable that after creating a thread, the application will assign a priority to the thread. Therefore, each DDS processing thread will have a corresponding priority. In this application, the communication middleware needs to determine the priority of each suspended target DDS processing thread in the application.

[0063] In this application, there is no limitation on the specific implementation of the DDS communication middleware determining the priority of the target DDS processing thread.

[0064] For example, when a DDS processing thread requests a DDS message from the DDS communication middleware, the DDS processing thread needs to call the DDS communication middleware's interface for reading DDS messages to obtain the DDS message from the DDS communication middleware's message buffer. For example, the DDS communication middleware's wait set interface can determine whether there is a DDS message in the DDS communication middleware's message buffer. If there is a DDS message, the wait set interface will return an indication to the DDS processing thread, which can then call an interface for reading DDS messages (such as a read interface or a take interface) to read the DDS message from the message buffer. When the DDS processing thread calls this interface, the DDS processing thread carries the DDS processing thread's thread information, which may include information such as the DDS processing thread's thread identifier and priority. Based on this, the DDS communication middleware can obtain the priority of the DDS processing thread, and naturally, the priority of each DDS processing thread that needs to be suspended.

[0065] In this application, for ease of distinction, the highest priority among the priorities corresponding to the suspended target DDS processing threads in the application is called the candidate priority. For example, assuming there are three target DDS processing threads, and the priorities of these three target DDS processing threads are priority 1, priority 2, and priority 3, respectively, among which priority 1 has the highest priority, then the candidate priority is priority 1.

[0066] S103: Set the priority of the DDS receiving thread in the application program to the target priority.

[0067] The target priority is the highest of the initial priority assigned by the application to the DDS receive thread and the candidate priority. For example, if the candidate priority is level 1 and the initial priority assigned by the application to the DDS receive thread is level 3, the target priority is level 1. If the candidate priority is level 3 and the initial priority assigned by the application to the DDS receive thread is level 2, the target priority is level 2.

[0068] The priority assigned by the application to the DDS receiving thread is the initial priority of the DDS receiving thread. The DDS receiving thread is used to obtain DDS messages, that is, to obtain DDS messages to be transmitted to the application. The creation and specific functions of the DDS receiving thread can be found in the previous description and will not be repeated here.

[0069] It is understandable that in addition to the DDS receiving thread and the DDS processing thread, there may be other types of threads in the application. If the priority of other types of threads is lower than that of the DDS processing thread, but higher than that of the DDS receiving thread, then other threads will preempt the resources of the DDS receiving thread, causing the DDS receiving thread to be unable to receive DDS messages. Naturally, the DDS processing thread with a relatively high priority will also be blocked due to the inability to obtain DDS messages.

[0070] To understand the situation where a high-priority DDS processing thread is blocked by other low-priority threads, see Figure 2 , which shows an example diagram of a high-priority DDS processing thread being blocked due to the preemption of resources of a low-priority DDS receiving thread.

[0071] exist Figure 2 In this example, we use three application threads: the DDS processing thread, thread A, and the DDS receiving thread. Thread A is a different type of thread. Assume that the DDS processing thread has the highest priority, 1; thread A has priority 2; and the DDS receiving thread has priority 3. Priority 2 is lower than priority 1 but higher than priority 3.

[0072] Depend on Figure 2 It can be seen that at the beginning, the DDS processing thread is in a suspended state and needs to wait for the DDS message to arrive. At a certain moment, the DDS receiving thread starts to receive the DDS message. However, in the process of the DDS receiving thread receiving the DDS message, thread A is ready and needs to perform task processing. At this time, due to the higher priority of thread A, the resources of the DDS receiving thread (such as CPU resources in the ECU) are preempted, resulting in the DDS receiving thread being unable to receive the DDS message. Only after thread A completes task processing and releases resources can the DDS receiving thread continue to receive DDS messages. It can be seen that although the priority of the DDS processing thread is higher than that of thread A, the DDS receiving thread cannot be scheduled, resulting in the high-priority DDS processing thread being unable to obtain the DDS message, causing the DDS processing thread to be blocked, and a priority inversion problem occurs.

[0073] In the present application, the priority assigned by the application to the DDS receiving thread and the higher of the highest priorities corresponding to the target DDS processing threads in the suspended state are set as the priority of the DDS receiving thread, thereby effectively ensuring that the priority of the DDS receiving thread is not lower than the priority of the target DDS processing threads in the suspended state (that is, waiting to receive DDS messages). Naturally, the situation where the priority of other threads is higher than the priority of the DDS receiving thread but lower than the priority of the target DDS processing thread waiting to receive DDS messages can be reduced, and naturally, the situation where the high-priority target DDS processing thread is blocked by other low-priority threads can be reduced.

[0074] In order to facilitate understanding of the benefits of this application, Figure 3 Provide explanation.

[0075] Figure 3 An example diagram shows the scheduling order of multiple threads after adopting the solution of the present application. Figure 3 The three threads included in Figure 2 The same, and the priorities assigned by the application to these three threads are also the same Figure 2 same.

[0076] However, after adopting the solution of this application, since the DDS processing thread is in a suspended state, and Figure 3 In the example, there is only one DDS processing thread in a suspended state. Since the priority of the DDS processing thread is higher than the priority of the DDS receiving thread, this application will adjust the priority of the DDS receiving thread to the priority corresponding to the DDS processing thread, that is, the priority of the DDS receiving thread is set to priority 1.

[0077] On this basis, Figure 3 It can be seen that at time t1, the DDS receiving thread starts to receive DDS messages. At time t2, thread A is ready, but because the adjusted priority of the DDS receiving thread is priority 1, which is higher than the priority of thread A (i.e., priority 2), the resources of the DDS receiving thread will not be preempted by thread A, and the DDS receiving thread can continue to receive DDS messages. At time t3, the DDS receiving thread completes the reception of the DDS message, and the DDS processing thread can be awakened. Since the priority of the DDS processing thread is higher than that of thread A, the DDS processing thread can process the DDS message. Only when the DDS processing thread completes the processing of the DDS message, that is, at time t4, can thread A obtain the corresponding resources and perform task processing, thereby avoiding the situation where the high-priority DDS processing thread is blocked due to the startup of the low-priority thread A.

[0078] From the above content, it can be seen that in this application, based on the priorities of each target DDS processing thread in a suspended state in the application, the candidate priority corresponding to the target DDS thread with the highest priority is determined, and the higher of the candidate priority and the initial priority assigned by the application to the DDS receiving thread is set as the priority of the DDS receiving thread, so that the priority of the DDS receiving thread is not lower than the priority of each suspended DDS processing thread, thereby reducing the situation where the priority of other threads is lower than the priority of the suspended DDS processing thread but higher than the priority of the DDS receiving thread, and naturally reducing the situation where the higher priority DDS processing thread cannot obtain and process DDS messages in time due to other threads with lower priority than the DDS processing thread preempting the resources of the DDS receiving thread.

[0079] It is understandable that, in the present application, there are many possibilities for determining the timing of the target DDS processing thread currently processing the suspended state in the application.

[0080] In one possible scenario, considering that the number of suspended DDS processing threads in an application may change dynamically at different times, and in order to ensure that each suspended DDS processing thread will not be blocked by other threads with relatively lower priority, the present application may determine at least one target DDS processing thread in the application that is currently in a suspended state in response to a DDS processing thread currently being suspended in the application.

[0081] It is understandable that if a newly suspended DDS processing thread is added to the application, in order to avoid the resources used to obtain DDS messages by the newly suspended DDS thread being preempted by other low-priority threads, this application needs to reasonably set the target priority corresponding to the DDS receiving thread in combination with the priority of each target DDS processing thread currently in the suspended state.

[0082] The following is an explanation of an implementation method. Figure 4 , shows another implementation flow diagram of the thread priority control method provided by the present application. The method of this embodiment is applied to the DDS communication middleware deployed in the electronic control unit of the vehicle. The method of this embodiment includes:

[0083] S401 : Setting the priority of the DDS receiving thread in the application to the initial priority assigned to the DDS receiving thread by the application.

[0084] For example, after the application creates a DDS receiving thread, the communication middleware sets the initial priority assigned by the application to the DDS receiving thread as the current priority of the DDS receiving thread.

[0085] S402 : In response to a DDS processing thread of an application currently being suspended, determining at least one target DDS processing thread in the application currently in a suspended state.

[0086] For example, when the DDS communication middleware detects that the DDS processing thread calls an interface for requesting to read DDS messages, if it determines that there is no DDS message that the DDS processing thread needs to process, it instructs the application to suspend the DDS processing thread. Accordingly, the DDS communication middleware confirms that the DDS processing thread is suspended.

[0087] S403 : Determine the candidate priority corresponding to the target DDS processing thread with the highest priority based on the priority of each target DDS processing thread in the application.

[0088] S404: If the priority currently set for the DDS receiving thread in the application is lower than the candidate priority, set the priority of the DDS receiving thread to the candidate priority.

[0089] S405: If the priority currently set for the DDS receiving thread is not lower than the candidate priority, the priority currently set for the DDS receiving thread is maintained unchanged.

[0090] It is understandable that as the number of suspended DDS processing threads in the application continues to change, the priority currently set for the DDS receiving thread may also continue to change. If the priority currently set for the DDS receiving thread is not lower than the highest priority corresponding to the currently suspended DDS processing threads, the priority currently set for the DDS receiving thread can be maintained unchanged; conversely, if the priority currently set for the DDS receiving thread is lower than the candidate priority, then in order to avoid the exception of priority inversion between other lower-priority threads and the higher-priority DDS processing thread due to the lower priority of the DDS receiving thread, the application needs to adjust the priority of the DDS receiving thread to the currently determined candidate priority.

[0091] It is understandable that when a DDS processing thread of an application is suspended, in order to more efficiently determine the currently suspended target DDS processing threads and the highest priority corresponding to each target DDS processing thread, the present application may also maintain a target thread list for storing relevant information of the suspended DDS processing threads.

[0092] Based on this, in response to a DDS processing thread currently being suspended in the application, the DDS communication middleware can obtain the thread ID and priority of the currently suspended target DDS processing thread, and associate the thread ID and priority of the currently suspended target DDS processing thread with each other and store them in a target thread list. This target thread list includes the thread IDs of each target DDS processing thread currently suspended in the application, as well as the priorities associated with each target DDS processing thread's thread IDs.

[0093] Accordingly, when determining the candidate priorities, the candidate priorities corresponding to the thread identifier with the highest priority can be determined directly based on the thread identifiers of each target DDS processing thread in the target thread list and the priorities corresponding to the thread identifiers of each target DDS processing thread, thereby being able to determine the candidate priorities more conveniently and efficiently.

[0094] It is understandable that when a target DDS processing thread in a suspended state needs to be awakened, if the target DDS processing thread is the DDS processing thread with the highest priority among all currently suspended DDS processing threads, then after the target DDS processing is awakened, if the priority of the DDS receiving thread is still maintained at the priority of the target DDS processing thread, it may affect the scheduling of other threads with relatively higher priorities.

[0095] Based on this, in another possible implementation, in response to the application currently having an awakened DDS processing thread, the present application can determine at least one target DDS processing thread currently in a suspended state in the application and perform subsequent processing.

[0096] Furthermore, when setting the priority of the DDS receiving thread to the target priority, the present application only needs to compare the initial priority of the DDS receiving thread with the candidate priorities corresponding to the remaining target DDS processing threads currently in a suspended state. Accordingly, if the initial priority of the DDS receiving thread in the application is lower than the candidate priority, the priority of the DDS receiving thread is set to the candidate priority. If the initial priority of the DDS receiving thread is not lower than the candidate priority, the priority of the DDS receiving thread is set to the initial priority of the DDS receiving thread.

[0097] In this possible implementation, if a target thread list is used to store the thread identifier and priority of each target DDS processing thread in a suspended state, the present application can also determine the thread identifier of the currently awakened target DDS processing thread in response to the existence of an awakened DDS processing thread in the application, and delete the thread identifier and priority of the currently awakened target DDS processing thread from the target thread list, so as to determine the candidate priority based on the priority of each remaining DDS processing thread in the target thread list.

[0098] The following is an explanation based on a specific implementation. Figure 5 , shows another flow chart of a thread priority control method provided by an embodiment of the present application. The method of this embodiment can be applied to the DDS communication middleware deployed in the electronic control unit of a vehicle. The method of this embodiment may include:

[0099] S501 : Setting the priority of a DDS receiving thread in an application program to the initial priority assigned to the DDS receiving thread by the application program.

[0100] S502 : In response to a DDS processing thread of the application being currently suspended, obtain the thread ID and priority of the currently suspended target DDS processing thread, and associate and store the thread ID and priority of the currently suspended target DDS processing thread in a target thread list.

[0101] The target thread list includes the thread identifiers of the target DDS processing threads currently in the suspended state in the application program and the priorities corresponding to the thread identifiers of the target DDS processing threads.

[0102] S503 : Determine a candidate priority corresponding to a thread identifier with the highest priority based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads.

[0103] like Figure 6 An example diagram of a target thread list is shown.

[0104] exist Figure 6 The target thread list shown includes multiple thread identifiers belonging to the DDS processing thread and the priority corresponding to each thread identifier. Figure 6It can be seen that at the current moment, the target thread list includes four suspended threads that are DDS processing threads. The thread identifiers of these four threads are thread 1, thread 2, thread 3, and thread 4, respectively. Among them, the priority of thread 1 is P1, the priority of thread 2 is P3, the priority of thread 3 is P4, and the priority of thread 4 is P2. The order of priority from high to low is P1, P2, P3, and P4. It can be seen that the thread with the highest priority is thread 1, and the priority P1 of thread 1 is the candidate priority.

[0105] S504: If the priority currently set for the DDS receiving thread in the application is lower than the candidate priority, set the priority of the DDS receiving thread to the candidate priority.

[0106] S505: If the priority currently set for the DDS receiving thread is not lower than the candidate priority, the priority currently set for the DDS receiving thread is maintained unchanged.

[0107] Still Figure 6 For example, suppose the last DDS processing thread added to the target thread list is thread 4. Assume that before thread 4 is suspended, the priority of the DDS receiving thread is priority P1, which corresponds to thread 1. After thread 4 is suspended, the highest priority in the target thread list is still priority P1, which is the same as the priority of the DDS receiving thread. Therefore, there is no need to adjust the priority of the DDS receiving thread. Conversely, suppose thread 1 is the last DDS processing thread added to the target thread list, and the DDS receiving thread is currently set to priority P2. After thread 1 is added to the target thread list, the priority of the DDS receiving thread needs to be adjusted to priority P1.

[0108] S506 : In response to the application program currently having an awakened DDS processing thread, determining the thread identifier of the currently awakened target DDS processing thread.

[0109] It's understood that after the DDS receiving thread receives a DDS message, the DDS communication middleware stores the received DDS message in the message buffer corresponding to the corresponding topic and, through the application, awakens the DDS processing thread corresponding to that topic, allowing the DDS processing thread of the corresponding topic to retrieve and process the DDS message. Based on this, the DDS communication middleware can determine whether the application currently has an awakened target DDS processing thread and the thread ID of the target DDS processing thread.

[0110] S507: Delete the thread identifier and priority of the currently awakened target DDS processing thread from the target thread list.

[0111] It is understandable that, since the relevant information of the awakened DDS processing thread will be deleted from the target thread list, the target thread list still only includes the thread identifiers of each target DDS processing thread currently in the suspended state in the application program and the priority corresponding to the thread identifier of each target DDS processing thread.

[0112] S508 : Determine a candidate priority corresponding to the thread identifier with the highest priority based on the priorities corresponding to the thread identifiers of the target DDS processing threads in the target thread list.

[0113] S509: Set the priority of the DDS receiving thread in the application program to the target priority.

[0114] The target priority is the highest one of the initial priority assigned by the application to the DDS receiving thread and the candidate priority.

[0115] Still Figure 6 For example, suppose that Figure 6 Based on this, assuming that the application assigns the initial priority of P4 to the DDS receiving thread, and it is determined that thread 1 needs to be awakened currently, then after thread 1 and its priority information are deleted from the target thread list, the highest priority in the target thread list is thread 4. Therefore, the priority P2 corresponding to thread 4 is the candidate priority, and the priority of the DDS receiving thread needs to be set to P2.

[0116] It should be noted that after a DDS processing thread is suspended, the suspended DDS processing thread may be awakened at any time. Therefore, the operation of step S506 is not performed every time a DDS processing thread is suspended.

[0117] On the other hand, corresponding to a thread priority control method of the present application, the present application also provides a thread priority control device.

[0118] like Figure 7 , shows a schematic diagram of the composition structure of a thread priority control device provided by the present application, which is applied to the DDS communication middleware deployed in the electronic control unit of a vehicle, including:

[0119] The thread determination unit 701 is used to determine each target DDS processing thread currently in a suspended state in the application;

[0120] A priority determination unit 702 is configured to determine a candidate priority corresponding to a target DDS processing thread with the highest priority based on the priorities of the target DDS processing threads in the application program;

[0121] The priority setting unit 703 is configured to set the priority of the DDS receiving thread in the application to a target priority, wherein the target priority is the highest one of the initial priority assigned by the application to the DDS receiving thread and the candidate priority.

[0122] In a possible implementation, the thread determination unit includes:

[0123] The first thread determination subunit is configured to determine at least one target DDS processing thread in the application that is currently in a suspended state in response to a DDS processing thread currently existing in the application being suspended.

[0124] Further, the apparatus further comprises: an initial configuration unit configured to, in response to the thread determination unit before the DDS processing thread in the application is suspended, set the priority of the DDS receiving thread in the application to the initial priority assigned by the application to the DDS receiving thread;

[0125] The priority setting unit includes:

[0126] a first setting subunit, configured to set the priority of the DDS receiving thread in the application to the candidate priority if the priority currently set to the DDS receiving thread in the application is lower than the candidate priority;

[0127] The second setting subunit is configured to maintain the priority currently set for the DDS receiving thread unchanged if the priority currently set for the DDS receiving thread is not lower than the candidate priority.

[0128] In yet another possible implementation, the first thread determination subunit includes:

[0129] a thread adding subunit, configured to obtain, in response to a DDS processing thread currently existing in the application being suspended, a thread identifier and a priority of the currently suspended target DDS processing thread, and associate the thread identifier and priority of the currently suspended target DDS processing thread with each other and store them in a target thread list, wherein the target thread list includes the thread identifiers of each target DDS processing thread currently in a suspended state in the application and the priority corresponding to the thread identifier of each target DDS processing thread;

[0130] The priority determination unit includes:

[0131] The first priority determination subunit is configured to determine a candidate priority corresponding to a thread identifier with the highest priority based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads.

[0132] In yet another possible implementation, the thread determination unit includes:

[0133] The second thread determination subunit is configured to determine at least one target DDS processing thread currently in a suspended state in the application program in response to a DDS processing thread currently being awakened in the application program.

[0134] Furthermore, the priority setting unit includes:

[0135] a third setting subunit, configured to set the priority of the DDS receiving thread in the application to the candidate priority if the initial priority of the DDS receiving thread in the application is lower than the candidate priority;

[0136] The fourth setting subunit is configured to set the priority of the DDS receiving thread to the initial priority of the DDS receiving thread if the initial priority of the DDS receiving thread is not lower than the candidate priority.

[0137] In yet another possible implementation, the second thread determining subunit includes:

[0138] an awakening determination subunit, configured to determine a thread identifier of a target DDS processing thread currently awakened in response to a DDS processing thread currently awakened by the application program;

[0139] a thread deletion subunit, configured to delete the thread identifier and priority of the currently awakened target DDS processing thread from a target thread list, wherein the target thread list includes the thread identifiers of each target DDS processing thread currently in a suspended state in the application program and the priority corresponding to the thread identifier of each target DDS processing thread;

[0140] The priority determination unit includes:

[0141] The second priority determination subunit is configured to determine a candidate priority corresponding to a thread identifier with the highest priority based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads.

[0142] The embodiment of the present application also provides a vehicle-mounted terminal. Figure 8 , which shows a schematic diagram of the structure of the vehicle-mounted terminal. The electronic device includes at least one electronic control unit 801 and a memory 802 connected to the electronic control unit;

[0143] The electronic control unit 801 is deployed with a communication middleware;

[0144] The electronic control unit 801 is configured to execute any one of the thread priority control methods described above through communication middleware;

[0145] The memory 802 is used to store programs required for the electronic control unit to perform operations.

[0146] It is understandable that the vehicle-mounted terminal may further include a display unit 803 and an input unit 804 .

[0147] Of course, the vehicle terminal can also have Figure 8 There is no limitation to more or fewer components.

[0148] A computer program product is also provided in an embodiment of the present application, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the thread priority control method described in any one of the above embodiments of the present application.

[0149] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the thread priority control method described in any of the above embodiments of the present application.

[0150] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.

[0151] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.

[0152] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0153] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website, a computer, a training device or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

Claims

1. A thread priority control method, characterized in that: DDS communication middleware deployed in vehicle electronic control units includes: Determine the target DDS processing threads that are currently in a suspended state in the application; Determine, based on the priorities of the target DDS processing threads in the application, a candidate priority corresponding to the target DDS processing thread with the highest priority; The priority of the DDS receiving thread in the application is set as a target priority, wherein the target priority is the highest one of the initial priority assigned by the application to the DDS receiving thread and the candidate priority.

2. The thread priority control method according to claim 1, wherein: The step of determining each target DDS processing thread currently in a suspended state in the application program includes: In response to a DDS processing thread of the application currently being suspended, at least one target DDS processing thread in the application currently in a suspended state is determined.

3. The thread priority control method according to claim 2, wherein: Before the DDS processing thread in the application is suspended, the method further includes: setting the priority of the DDS receiving thread in the application to the initial priority assigned to the DDS receiving thread by the application; Setting the priority of the DDS receiving thread in the application program to the target priority includes: If the priority currently set for the DDS receiving thread in the application is lower than the candidate priority, setting the priority of the DDS receiving thread to the candidate priority; If the priority currently set for the DDS receiving thread is not lower than the candidate priority, the priority currently set for the DDS receiving thread is maintained unchanged.

4. The thread priority control method according to claim 2, wherein: In response to a DDS processing thread of the application currently being suspended, determining at least one target DDS processing thread in the application currently in a suspended state includes: In response to a DDS processing thread currently being suspended in the application, obtaining a thread identifier and a priority of the currently suspended target DDS processing thread, and associating the thread identifier and the priority of the currently suspended target DDS processing thread and storing them in a target thread list, wherein the target thread list includes the thread identifiers of each target DDS processing thread currently in a suspended state in the application and the priority corresponding to the thread identifier of each target DDS processing thread; The determining, based on the priorities of the target DDS processing threads in the application, the candidate priority corresponding to the target DDS processing thread with the highest priority, includes: Based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads, a candidate priority corresponding to the thread identifier with the highest priority is determined.

5. The thread priority control method according to claim 1, wherein: The step of determining each target DDS processing thread currently in a suspended state in the application program includes: In response to an awakened DDS processing thread currently existing in the application, at least one target DDS processing thread currently in a suspended state in the application is determined.

6. The thread priority control method according to claim 5, characterized in that: Setting the priority of the DDS receiving thread in the application program to the target priority includes: If the initial priority of the DDS receiving thread in the application is lower than the candidate priority, setting the priority of the DDS receiving thread to the candidate priority; If the initial priority of the DDS receiving thread is not lower than the candidate priority, the priority of the DDS receiving thread is set to the initial priority of the DDS receiving thread.

7. The thread priority control method according to claim 5, characterized in that: In response to the application currently having an awakened DDS processing thread, determining at least one target DDS processing thread in the application currently in a suspended state includes: In response to the application currently having an awakened DDS processing thread, determining the thread identifier of the currently awakened target DDS processing thread; Deleting the thread ID and priority of the currently awakened target DDS processing thread from a target thread list, wherein the target thread list includes the thread IDs of each target DDS processing thread currently in a suspended state in the application program and the priorities corresponding to the thread IDs of each target DDS processing thread; The determining, based on the priorities of the target DDS processing threads in the application, the candidate priority corresponding to the target DDS processing thread with the highest priority, includes: Based on the thread identifiers of the target DDS processing threads in the target thread list and the priorities corresponding to the thread identifiers of the target DDS processing threads, a candidate priority corresponding to the thread identifier with the highest priority is determined.

8. A thread priority control device, characterized in that: DDS communication middleware deployed in vehicle electronic control units includes: A thread determination unit, configured to determine each target DDS processing thread currently in a suspended state in the application; A priority determination unit, configured to determine a candidate priority corresponding to a target DDS processing thread with the highest priority based on the priorities of the target DDS processing threads in the application program; The priority setting unit is configured to set the priority of the DDS receiving thread in the application to a target priority, wherein the target priority is the highest one of the initial priority assigned by the application to the DDS receiving thread and the candidate priority.

9. A vehicle-mounted terminal, characterized in that: comprising at least one electronic control unit, and a memory connected to the electronic control unit; Communication middleware is deployed in the electronic control unit; The electronic control unit is configured to execute the thread priority control method according to any one of claims 1 to 7 above through the communication middleware; The memory is used to store the program required by the electronic control unit to perform operations.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the thread priority control method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Communication method, system and device

    CN110187985A

  • Multi-protocol implementation method and system based on thread interaction

    CN111413945A

  • UWB data packet processing method and system, electronic equipment and storage medium thereof

    CN112714492A

  • Thread processing method and electronic equipment

    CN117271144A

  • Thread scheduling optimization method and device and electronic equipment

    CN119536942A