Thread release method and device, electronic equipment and readable storage medium
By obtaining thread information and judging its running status during the upgrade and flashing process of the car OTA, we ensure that the client thread can be correctly released after completing the upgrade and flashing, solving the system abnormality problem caused by the thread's inability to release correctly, and ensuring the system's operation security and stability.
Patent Information
- Application Number
- CN202510035109.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-09
- Publication Date
- 2025-05-23
AI Technical Summary
During the process of upgrading and writing of automobile OTA, the client thread cannot be released correctly, resulting in system abnormality or crash, threatening the system's operational security and stability.
By obtaining thread information, we judge the thread running state. If it is a normal termination state, we notify the thread-termination module to perform the thread release operation; if the release fails, we notify the backup thread-termination module to perform the thread-destruction operation to ensure the correct release of the thread.
Ensure that the client thread can be correctly released after completing the upgrade and flushing, avoid system abnormalities or crashes, and ensure the security and stability of the system operation.
Smart Images

Figure CN120029764A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a thread releasing method, device, electronic device and readable storage medium. Background Art
[0002] Automotive OTA (Over the Air Technology) upgrade is a technology that downloads new software / firmware update packages from a remote server to upgrade the vehicle's ECU (electronic control unit).
[0003] When OTA upgrades one or more ECUs, it is usually necessary to establish one or more client threads to transmit upgrade data messages to each ECU. If the client thread cannot be released correctly after the upgrade is completed, it is easy to cause system abnormalities or even crashes, which seriously threatens the system's operating security and stability. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a thread release method, device, electronic device and readable storage medium to solve the problem in the prior art that the client thread cannot be correctly released after the upgrade is completed, which may easily cause the system to abnormally occur or even crash, thereby seriously threatening the operating security and stability of the system.
[0005] A first aspect of an embodiment of the present application provides a thread release method, comprising:
[0006] Get thread information, including thread ID and thread running status;
[0007] If the thread running state is a normal termination state, the thread to be released is determined based on the thread identifier, and the thread termination module is notified to perform a thread release operation to release the thread to be released;
[0008] If it is detected that the release of the thread to be released fails, the backup thread termination module is notified to perform a thread destruction operation to destroy the thread to be released.
[0009] A second aspect of the embodiments of the present application provides a thread release device, including: a thread monitoring module, a thread termination module and a backup thread termination module;
[0010] The thread monitoring module is configured to obtain thread information, wherein the thread information includes a thread identifier and a thread running state; if the thread running state is a normal termination state, determine the thread to be released based on the thread identifier, and notify the thread termination module to perform a thread release operation;
[0011] The thread termination module executes a thread release operation to release the thread to be released;
[0012] The thread monitoring module is further configured to notify the backup thread termination module to execute a thread destruction operation if it is detected that the release of the thread to be released fails;
[0013] The backup thread termination module is configured to execute a thread destruction operation to destroy the thread to be released.
[0014] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0015] According to a fourth aspect of an embodiment of the present application, a readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0016] Compared with the prior art, the beneficial effects of the embodiments of the present application include at least: when confirming that the thread running state is a normal termination state, first notify the thread termination module to perform a thread release operation to release the thread to be released; if it is subsequently monitored that the release of the thread to be released fails, then notify the backup thread termination module to perform a thread destruction operation to destroy the thread to be released, so as to ensure that the client thread can be correctly released after the upgrade is completed, thereby avoiding system abnormalities or even crashes, and thus ensuring the security and stability of the system operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 It is a schematic diagram of an application scenario of an embodiment of the present application;
[0019] Figure 2 It is a flowchart of the original Android system's method of processing thread exit and recycling;
[0020] Figure 3 This is a schematic diagram of the structure of an OTA upgrade master control provided in an embodiment of the present application;
[0021] Figure 4 It is a flowchart of a thread release method provided in an embodiment of the present application;
[0022] Figure 5It is a flowchart of another thread release method provided in an embodiment of the present application;
[0023] Figure 6 It is a structural diagram of another OTA upgrade master control provided in an embodiment of the present application;
[0024] Figure 7 This is a structural diagram of another OTA upgrade master control provided in an embodiment of the present application;
[0025] Figure 8 It is a structural schematic diagram of a thread releasing device provided in an embodiment of the present application;
[0026] Fig. 9 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0028] A thread releasing method and device according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0029] Figure 1 It is a scenario diagram of an application scenario of an embodiment of the present application. The application scenario may include CDC (Cockpit Domain Controller, intelligent cockpit) 101, VDC (Vehicle Domain Controller, vehicle controller) 102, vehicle integration gateway (Vehicle Integration Unit, referred to as "VIU") 101, 102, 103 and 104. Among them, CDC 101 can be connected to the OTA cloud platform through a 4G / 5G network or WiFi. CDC 101 and VDC 102 can be connected through Ethernet communication. CDC 101 and vehicle integration gateways 101, 102, 103 and 104 can be connected through Ethernet communication. VDC 102 and vehicle integration gateways 101, 102, 103 and 104 can be connected through Ethernet communication. CDC 101, VDC 102 and vehicle integration gateways 101, 102, 103 and 104 can be connected through Ethernet communication with their subordinate electronic control units respectively through Ethernet or CAN network.
[0030] As an example, see Figure 1 , CDC 101 is connected with ECU0-1...ECU0-n, with a total of n ECU components; VDC102 is connected with ECU5-1...ECU5-n, with a total of n ECU components; vehicle integration gateway 101 (VIU1) is connected with ECU1-1...ECU1-n, with a total of n ECU components; vehicle integration gateway 102 (VIU2) is connected with ECU2-1...ECU2-n, with a total of n ECU components; vehicle integration gateway 103 (VIU3) is connected with ECU3-1...ECU3-n, with a total of n ECU components; vehicle integration gateway 104 (VIU4) is connected with ECU4-1...ECU4-n, with a total of n ECU components.
[0031] The electronic and electrical architecture constructed by CDC 101, VDC 102, vehicle integration gateways 101, 102, 103 and 104 is an Ethernet ring network structure. The advantages of using the Ethernet ring network structure include at least: supporting SOA (Service-Oriented Architecture) service-oriented and communication channel protection, supporting the nearby access of each ECU according to functional classification, and saving wiring harness costs.
[0032] In some implementations, the CDC 101 carries an OTA upgrade master controller (UMC), the vehicle integration gateways 101, 102, 103 and 104 carry an OTA upgrade agent (UA), and each ECU carries an OTA upgrade slave controller (US). The OTA cloud platform is used to store and manage upgrade files of vehicle ECUs.
[0033] It can be understood that the specific types, quantities and combinations of CDC 101, VDC 102, vehicle integration gateways 101, 102, 103 and 104 can be adjusted according to the actual needs of the application scenario, and the embodiments of the present application are not limited to this.
[0034] As an example, see Figure 1, assuming that the ECUs (target ECUs) that need to be OTA upgraded and flashed include ECU4-1, ECU4-2 and ECU4-n attached to the vehicle integrated gateway 104 (VIU4), then the OTA upgrade master control (Upgrade master control, referred to as "UMC") in the CDC 101 can first establish TCP (Transmission Control Protocol) communication with the OTA upgrade agent (Upgrade Agent, referred to as "UA") in the vehicle integrated gateway 104 (VIU4), and then use UDS (Unified Diagnostic Services) and DOIP (Diagnostic communication over Internet Protocol, based on IP network diagnostic communication) protocols or ECUs through their own systems (such as Linux or Android) to upgrade and flash. During the OTA upgrade and flashing process, it is necessary to establish multiple client threads corresponding to the ECUs that need to be upgraded and flashed (including ECU4-1, ECU4-2 and ECU4-n) in the OTA upgrade master control (UMC) to realize the transmission of upgrade data files.
[0035] The ECU to be upgraded and flashed (or referred to as target ECU) may be one or more.
[0036] Figure 2 This is a flowchart of the original Android system's method of handling thread exit and recycling. Figure 2 The original Android system's method for processing thread exit and recycling includes the following steps:
[0037] Step S201, start the OTA master control application.
[0038] Step S202: Create an OTA client thread in the OTA upgrade master controller (UMC).
[0039] Step S203, determine whether the OTA client thread is successfully created. If the creation is unsuccessful, return to step S202; if the creation is successful, execute step S204.
[0040] Step S204: If the creation is successful, the OTA client thread is run.
[0041] Step S205, determining whether a thread termination signal (such as SIGUSR1 signal or SIGUSR2 signal) is received. If no thread termination signal is received, returning to step S204; if a thread termination signal is received, executing step S206.
[0042] Step S206, calling the function pthread_kill (thread ID, SIGUSR1), where thread ID indicates the thread ID.
[0043] Step S207, send the thread termination signal SIGUSR1 to the signal processing function static void pthread_exit_handler(int sig)
[0044] {
[0045] if (SIGUSR1 == sig)
[0046] {
[0047] pthread_exit(NULL);
[0048] }
[0049] }.
[0050] Step S208, executing the pthread_cancel (pthread_t threadId) thread recovery function, with the OTA client thread corresponding to the parameter thread id passed in step S206.
[0051] In the original Android system's method of processing thread exit and recycling, when the OTA client thread needs to be released, the function pthread_kill(threadid,SIGUSR1) is called, and the SIGUSR1 signal is sent to execute the function pthread_exit() to exit the thread. However, the SIGUSR1 signal is an unreliable signal, and it is difficult to ensure that the signal can be received by pthread_exit() and exit the thread, resulting in the thread not being able to exit correctly to release system resources, which in turn causes system abnormalities.
[0052] In view of this, an embodiment of the present application provides a thread release method. When it is confirmed that the thread running state is a normal termination state, the thread termination module is first notified to perform a thread release operation to release the thread to be released; if it is subsequently monitored that the release of the thread to be released fails, and the number of executions of the thread release operation is greater than or equal to a preset threshold, the backup thread termination module is notified to perform a thread destruction operation to destroy the thread to be released. This ensures that the client thread can be correctly released after the upgrade is completed, thereby avoiding system abnormalities or even crashes, and thus ensuring the security and stability of the system operation.
[0053] Figure 3 This is a schematic diagram of the structure of an OTA upgrade master control provided in an embodiment of the present application. Figure 3The OTA upgrade master control (Upgrade master control, referred to as "UMC") of the embodiment of the present application includes: an OTA master control application 301, a thread creation module 302, a thread running module 303, a thread monitoring module 304, a thread termination module 305, a backup thread termination module 306 and a thread recovery module 307.
[0054] The thread creation module 302 executes the thread creation task sent by the OTA master control application 301 to create an OTA client thread.
[0055] The thread running module 303 executes the thread running task sent by the OTA master control application 301 , runs the OTA client thread created by the thread creation module 302 , and reports thread information to the thread monitoring module 304 .
[0056] The thread monitoring module 304 monitors the thread running state of the OTA client thread based on the thread information reported by the thread running module 303. If it is confirmed that the thread running state of one or more OTA client threads is in a normal termination state, a thread release instruction is sent to the thread termination module 305. The thread release instruction includes the thread identifier (such as thread ID) of the thread to be released.
[0057] The thread termination module 305 , upon receiving the thread release instruction sent by the thread monitoring module 304 , executes a thread release operation to release the thread to be released.
[0058] The thread monitoring module 304 sends a thread destroying instruction to the backup thread termination module 306 when detecting that the release of the thread to be released fails.
[0059] The backup thread termination module 306 , upon receiving the thread destruction instruction sent by the thread monitoring module 304 , executes a thread destruction operation to destroy the thread to be released.
[0060] The thread recovery module 307 recovers the successfully released threads to be released, and waits for subsequent destruction or reuse of the threads to be released.
[0061] Figure 4 is a flowchart of a thread release method provided by an embodiment of the present application. The thread release method of the embodiment of the present application can be Figure 3 The thread monitoring module 304 in is executed.
[0062] See also Figure 4 , the thread release method may include the following steps:
[0063] Step S401, obtaining thread information, the thread information including thread identification and thread running status.
[0064] Thread identification, including thread name and thread ID, is used to distinguish different OTA client threads. Each OTA client thread has at least a unique thread ID.
[0065] Thread running status, including thread running status and thread termination status. Thread running status indicates the running status of the OTA client thread during the upgrade process. Thread termination status indicates the termination status of the OTA client thread after the upgrade is completed.
[0066] As an example, see Figure 3 , when OTA upgrades and flashes one or more ECUs, the OTA master application 301 and the thread monitoring module 304 are started. Afterwards, the OTA master application 301 calls the thread creation module 302, and the thread creation module 302 performs the thread creation operation to create one or more OTA client threads. Normally, one OTA client thread corresponds to one ECU. After creating the OTA client thread, the thread creation module 302 notifies the thread running module 303 to run the created OTA client thread. After receiving the notification sent by the thread creation module 302, the thread running module 303 runs the created OTA client thread and periodically or in real time reports the thread information of each OTA client thread to the thread monitoring module 304.
[0067] Step S402: If the thread running state is a normal termination state, the thread to be released is determined based on the thread identifier, and the thread termination module is notified to perform a thread release operation to release the thread to be released.
[0068] The normal termination state means that the OTA client thread has completed the upgrade and flashing task and is waiting to be released.
[0069] The thread release operation can be to execute the pthread_exit() function to release the thread that has completed the task, so that it can be restored to the state of waiting for the task to be assigned. It can also be understood as releasing the occupation of the thread.
[0070] As an example, see Figure 3, assuming that the target ECUs include ECU4-1, ECU4-2, and ECU4-n, the thread creation module 302 has successfully created OTA client threads 1, 2, and 3, wherein OTA client thread 1 corresponds to ECU4-1, OTA client thread 2 corresponds to ECU4-2, and OTA client thread 3 corresponds to ECU4-3; the thread running module 303 runs OTA client threads 1, 2, and 3, and reports thread information to the thread monitoring module 304. The thread information includes the thread identifiers and thread running states of OTA client threads 1, 2, and 3. Exemplarily, (thread ID_1, state_1) represents the thread identifier (thread ID_1) and thread running state (state_1) of OTA client thread 1; (thread ID_2, state_2) represents the thread identifier (thread ID_2) and thread running state (state_2) of OTA client thread 2; (thread ID_3, state_3) represents the thread identifier (thread ID_3) and thread running state (state_3) of OTA client thread 3.
[0071] The thread monitoring module 304 obtains and parses the thread information reported by the thread running module 303 to determine the thread running state of each OTA client thread. Exemplarily, if the thread running state (state_1) of the OTA client thread 1 is a normal termination state, based on the thread identifier (thread ID_1) corresponding to state_1, the OTA client thread 1 is determined to be a program to be released, and the thread termination module 305 is notified to perform a thread release operation to release the OTA client thread 1.
[0072] Step S403: if it is detected that the release of the thread to be released fails, the backup thread termination module is notified to execute a thread destruction operation to destroy the thread to be released.
[0073] The preset number threshold can be flexibly set according to actual conditions. For example, it can be set to 2 times, 3 times, 4 times, etc. The embodiment of the present application does not impose specific restrictions on this.
[0074] The thread destruction operation may be an operation of killing a thread (clearing a thread) using the kill command or the pkill command.
[0075] For ease of understanding, continue to use the above example, if the thread to be released is OTA client thread 1, after notifying the thread termination module 305 to perform the thread release operation for OTA client thread 1, the thread monitoring module 304 detects that OTA client thread 1 fails to be released, and the number of executions of the thread release operation is greater than or equal to the preset number threshold (such as 2 times), then notifies the backup thread termination module 306 to perform the thread destruction operation. After receiving the destruction instruction sent by the thread monitoring module 304, the backup thread termination module 306 performs a thread destruction operation, for example, executing the KILL thread ID operation to kill OTA client thread 1 and destroy OTA client thread 1.
[0076] The technical solution provided in the embodiment of the present application, when confirming that the thread running state is a normal termination state, first notifies the thread termination module to perform a thread release operation to release the thread to be released; if it is subsequently monitored that the release of the thread to be released fails, the backup thread termination module is notified to perform a thread destruction operation to destroy the thread to be released. This ensures that the client thread can be correctly released after the upgrade is completed, thereby avoiding system abnormalities or even crashes, and thus ensuring the security and stability of the system operation.
[0077] In some embodiments, if it is detected that the release of the thread to be released fails, the backup thread termination module is notified to perform a thread destruction operation to destroy the thread to be released, including:
[0078] If it is detected that the release of the thread to be released fails, the thread termination module is notified to execute the thread release operation again to release the thread to be released again;
[0079] If it is detected that the thread to be released still fails to be released, the number of executions of the thread release operation is determined;
[0080] If the number of executions of the thread release operation is less than the preset number threshold, returning to the step of notifying the thread termination module to execute the thread release operation again;
[0081] If the number of executions of the thread release operation is greater than or equal to a preset number threshold, the backup thread termination module is notified to execute a thread destruction operation to destroy the thread to be released.
[0082] Figure 5 is a flowchart of another thread release method provided by an embodiment of the present application. Figure 5 , the method comprises the following steps:
[0083] Step S501, start the OTA master control application and thread monitoring module.
[0084] Step S502: The OTA master control application notifies the thread creation module to create an OTA client thread.
[0085] Step S503: The thread creation module determines whether the OTA client thread is successfully created and feeds back to the OTA master application. If the creation is successful, step S504 is executed; if the creation fails, the process returns to step S502.
[0086] Step S504: The OTA master control application notifies the thread running module to run the OTA client thread. The thread running module runs the OTA client thread and sends thread information to the thread monitoring module.
[0087] Step S505: The thread monitoring module determines whether the thread running state of the OTA client thread is a normal termination state based on the thread information. If the thread running state of the OTA client thread is an abnormal termination state, step S506 is executed; if the thread running state of the OTA client thread is a normal termination state, step S507 is executed.
[0088] Step S506: The thread monitoring module notifies the thread running module to execute a thread running operation to restart the OTA client thread whose thread running state is an abnormal termination state.
[0089] Step S507: The thread monitoring module notifies the thread termination module to execute a thread release operation to release the OTA client thread whose thread running state is a normal termination state. Figure 4 In the process shown, the original Android system notifies the exit function to perform a thread release operation by sending a "signal SIGUSR1 or SIGUSR2" to release the thread to be released.
[0090] Step S508, the thread monitoring module determines whether the OTA client thread has been terminated, that is, whether the OTA client thread whose thread running state is the normal termination state has been released successfully. If the OTA client thread has been terminated (that is, released successfully), exit. If the OTA client thread has not been terminated (that is, released failed), execute step S509.
[0091] Step S509, the thread monitoring module determines whether the number of executions of the thread release operation is greater than or equal to a preset number threshold (which can be flexibly set according to actual conditions). If yes, execute step S510. If not, return to step S507.
[0092] In some implementations, if the thread monitoring module determines that the number of executions of the thread release operation is less than a preset threshold (eg, 2 times), the thread termination module may be notified to execute the function pthread_kill (thread id, SIGUSR1) to release the thread to be released again.
[0093] Step S510: The thread running module notifies the backup thread termination module to execute a thread destruction operation to destroy the thread to be released (the OTA client thread whose thread running state is a normal termination state).
[0094] As an example, the backup thread termination module may perform a KILL thread ID operation according to the thread ID of the thread to be released, so as to destroy the thread to be released.
[0095] The technical solution of the embodiment of the present application, when the thread running state of the OTA client thread is monitored to be in a normal termination state, first execute the original Android system once to notify the exit function to perform the thread release operation by sending "signal SIGUSR1 or SIGUSR2"; if it is monitored that the release of the thread to be released fails, and the number of executions of the thread release operation is less than the preset number of executions, then execute the thread release operation again to release the thread to be released again; if it is monitored that the thread to be released still fails to be released, and the number of executions of the thread release operation is greater than or equal to the preset number of executions, then execute the thread destruction operation to destroy the thread to be released. In this way, it can ensure that the client thread can be correctly released after the upgrade is completed, thereby avoiding system abnormalities or even crashes, and thus ensuring the security and stability of system operation.
[0096] In some embodiments, after obtaining the thread information, the method further includes:
[0097] If the thread running state is an abnormal termination state, determine the abnormal exit thread based on the thread identifier;
[0098] The thread running module is notified to execute the thread running operation so that the abnormally exited thread can resume the running state.
[0099] The abnormal termination state refers to the state where the thread is abnormally suspended or exited.
[0100] If a third party (such as a hacker) maliciously attacks the system, or if a system failure occurs (such as a network communication failure, hardware failure, etc.), the running OTA client thread is likely to terminate abnormally.
[0101] As an example, the thread running module 303 may periodically or in real time report the thread information of the OTA client thread to the thread monitoring module 304. The thread monitoring module 304 parses the thread information, and when it is found that the thread running state of the OTA client thread is abnormally terminated, the OTA client thread is determined as an abnormal exit thread, and the thread running module is notified to perform a thread running operation to restore the abnormal exit thread to a running state.
[0102] In this way, the operating reliability of the OTA client thread can be ensured, and the risk of failure of OTA upgrade and flashing ECU due to abnormal interruption of the OTA client thread can be reduced, thereby improving the reliability and success rate of OTA upgrade and flashing ECU.
[0103] In some embodiments, if the thread running state is a normal termination state, the thread to be released is determined based on the thread identifier, and the thread termination module is notified to perform a thread release operation to release the thread to be released, and the method further includes:
[0104] If it is detected that the thread to be released is released successfully, the thread recovery module is notified to perform a thread recovery operation to recover the thread to be released into the idle thread pool;
[0105] Call the thread manager to mark the threads to be released in the idle thread pool as idle threads, and start a timer to record the recycling time of the idle threads entering the idle thread pool;
[0106] If the thread scheduling request is not obtained when the recycling time reaches the preset destruction time, the idle thread will be removed from the idle thread pool and destroyed.
[0107] Figure 6 This is a schematic diagram of another OTA upgrade master control structure provided by the embodiment of the present application. Figure 6 The structure of the OTA upgrade master is similar to Figure 3 The structure of the OTA upgrade master controller shown is different in that it also includes: an idle thread pool 308 and a thread manager 309 .
[0108] The idle thread pool 308 stores the threads to be released that are recovered by the thread recovery module 307 .
[0109] The thread manager 309 manages and schedules the idle threads in the idle thread pool 308 .
[0110] The preset destruction time can be flexibly set according to actual conditions. For example, it can be set to 5 minutes, 10 minutes, etc., and the embodiment of the present application does not impose specific restrictions on this.
[0111] As an example, see Figure 6 , when the thread monitoring module 304 detects that the thread to be released (such as OTA client thread 1) is released successfully, it notifies the thread recovery module 307 to perform the thread recovery operation. The thread recovery module 307 executes the thread recovery function to recover the thread to be released (such as OTA client thread 1) and stores it in the idle thread pool 308. The thread monitoring module 304 calls the thread manager 309, marks the thread to be released (such as OTA client thread 1) recovered in the idle thread pool as an idle thread, and starts a timer to record the recovery time T of the idle thread (such as OTA client thread 1) entering the idle thread poolrec If the recycling time T rec Reach the preset destruction time T dec (e.g. 5 minutes, starting from the time when the idle thread enters the idle thread pool and the cumulative time reaches 5 minutes), the thread manager 309 still has not received the thread scheduling request sent by the OTA master control application 301, then the idle thread (e.g. OTA client thread 1) is removed from the idle thread pool for destruction.
[0112] In the above way, the recycled idle threads are stored in the idle thread pool, and the recycling time of each idle thread is recorded. rec Arrives at the preset destruction time T dec (i.e. T rec =T dec ) has not received a thread scheduling request, and then destroying the idle thread can not only improve the thread reuse rate and the response efficiency of the thread scheduling request initiated by the OTA master application, but also facilitate the maintenance and management of the thread, which is beneficial to improving the system performance stability.
[0113] In some embodiments, removing an idle thread from an idle thread pool and destroying the idle thread may include:
[0114] Determine the current system load rate;
[0115] If the current system load rate is less than or equal to the first load rate threshold and the duration is greater than the preset duration threshold, the idle thread is removed from the idle thread pool and destroyed.
[0116] The current system load rate refers to the resource load of the system at the current moment, including the load of network resources and memory resources.
[0117] The first load rate threshold can be set according to the system operation performance, memory, network and other resource usage, and generally indicates that the system is under a relatively light load. Usually, when the system load rate is lower than p1 (0 < p1 < 0.8), the system is under a relatively light load, the system response is faster, and the data transmission rate is faster.
[0118] The maintenance duration refers to the duration during which the current system load rate of the system maintains a state less than or equal to the first load rate threshold.
[0119] The preset duration threshold can be flexibly set according to actual conditions. For example, it can be set to 5 minutes, 10 minutes, etc., and the embodiments of the present application do not impose specific restrictions on this.
[0120] As an example, when the thread manager 309 detects that the recycling time of an idle thread (such as OTA client thread 1) in the idle thread pool 308 reaches the preset destruction time and is not scheduled, it can send a request message to the OTA master application 301 to obtain the current system load rate. When the thread manager 309 receives the response information returned by the OTA master application 301, it extracts the current system load rate in the response information and compares the current system load rate with the first load rate threshold. If the current system load rate is less than or equal to the first load rate threshold, and the maintenance duration is greater than the preset duration threshold, the idle thread (such as OTA client thread 1) is removed from the idle thread pool and destroyed.
[0121] In the above implementation, combined with the actual load of the system, when the current system load is relatively light, those idle threads in the idle thread pool that have reached the preset destruction time and have not been scheduled can be destroyed, thereby reducing the overhead of maintaining these threads.
[0122] In some implementations, when the current system load is relatively light, idle threads in the idle thread pool that have reached a preset destruction time and have not been scheduled may not be processed temporarily, so that the system can schedule them at any time to cope with sudden large-scale thread scheduling needs.
[0123] In some embodiments, removing an idle thread from an idle thread pool and destroying the idle thread may include:
[0124] Count the total number of idle threads in the idle thread pool;
[0125] Determine the current system load rate and the minimum number of maintenance threads, where the minimum number of maintenance threads refers to the minimum number of threads that can be dynamically allocated by the system based on business needs;
[0126] If the current system load rate is greater than the first load rate threshold and less than the second load rate threshold, the timer is reset to recalculate the recovery time for the idle thread to enter the idle thread pool so that the total number of idle threads is not less than the minimum number of maintenance threads; wherein the first load rate threshold is less than the second load rate threshold.
[0127] The second load rate threshold can be set according to the system operation performance, memory, network and other resource usage, and is generally used to indicate that the system is under heavy load. Usually, when the system load rate exceeds p2 (0.8 < p2 < 1), the system is under heavy load, the system response is slow, and the data transmission rate is slow.
[0128] As an example, see Figure 1, the OTA master application can determine the minimum number of threads that the system can dynamically allocate (minimum number of maintenance threads) based on business needs (for example, which ECUs need to be OTA upgraded and flashed). For example, the ECUs that need to be OTA upgraded and flashed include ECU4-1, ECU4-2 and ECU4-n attached to the vehicle integration gateway 104 (VIU4). To ensure that each ECU to be upgraded and flashed has at least one OTA client thread to execute the transmission of the upgrade data file, the minimum number of threads that the system can dynamically allocate is not less than 3.
[0129] As an example, assume that there are 5 idle threads in the idle thread pool 308, which are recorded as idle threads 1, 2, 3, 4 and 5, respectively, wherein the recycling time of idle threads 1, 2, 3, 4 and 5 is T respectively. rec1 、T rec2 、T rec3 、T rec4 and T rec5 , the minimum number of maintenance threads is 6, the first load rate threshold is 0.5, the second load rate threshold is 0.9, and the current system load rate is 0.6. Then the current system load rate (0.6) is greater than the first load rate threshold (0.5) and less than the second load rate threshold (0.9), and the total number of idle threads (5) is less than the minimum number of maintenance threads (6). If idle thread 1 has not been scheduled when it reaches the preset destruction time (such as 5 minutes), the thread manager 309 resets the timer corresponding to idle thread 1 to recalculate the recycling time T of idle thread 1 entering the idle thread pool. rec1 .
[0130] Through the above implementation, when the current system load rate is between the first load rate threshold and the second load rate threshold, the system runs slowly and the data transmission rate is slow. At this time, the timer corresponding to the idle thread that has reached the preset destruction time but has not been scheduled can be reset to maintain the number of idle threads in the idle thread pool not less than the minimum number of maintenance threads. This can adapt to the sudden thread scheduling requests of the OTA master control application, improve the thread reuse rate, and save the time of recreating the thread.
[0131] In some embodiments, after determining the current system load rate and the minimum number of maintenance threads, the method further includes:
[0132] If the current system load rate is greater than the first load rate threshold and less than the second load rate threshold, and the total number of idle threads is greater than the minimum number of maintenance threads, then determining the probability value of increasing the minimum number of maintenance threads;
[0133] If the probability value is within a preset value range, some idle threads in the idle thread pool are destroyed so that the number of remaining idle threads in the idle thread pool is less than or equal to the minimum number of maintenance threads.
[0134] As an example, the thread manager 309 can determine the minimum number of maintenance threads num in the idle thread pool according to actual business needs (such as which ECUs need to be flashed by OTA parallel upgrade, etc.). min For example, if ECU4-1, ECU4-2 and ECU4-n connected to the vehicle integration gateway 104 (VIU4) need to be upgraded and flashed in parallel via OTA, then the minimum number of maintenance threads in the idle thread pool is num min Can be set to 3.
[0135] When the total number of idle threads in the idle thread pool is num free Greater than the minimum number of maintenance threads num min , and when the current system load rate is greater than the first load rate threshold and less than the second load rate threshold, the thread manager 309 may, according to the system's carrying capacity (indicating the total number of threads num that the system can carry at most max ), user requirements for system response time, and other indicators to determine the probability value of increasing the minimum number of maintenance threads.
[0136] The total number of threads that the system can support is limited by the operating system and hardware resources. For example, in the Linux operating system, the default stack size of a process thread is 8MB. The upper limit of threads for a single process in a 32-bit system is 3GB / 8MB=384, and the upper limit of threads for a single process in a 64-bit system is 64GB / 8MB=8192. In other words, without any adjustments, the maximum number of threads that can be created in a process of an ordinary 32-bit Linux operating system is 384, and the maximum number of threads that can be created in a process of an ordinary 64-bit Linux operating system is 8192.
[0137] For example, when the user has high requirements for system response timeliness, if the total number of idle threads in the idle thread pool is num free Greater than the minimum number of maintenance threads num min , and the current system load rate is greater than the first load rate threshold and less than the second load rate threshold, then calculate num min With num free The sum of num total , and the number of required working threads num required to meet the user's requirements for system response timeliness and the needs of the currently executing OTA parallel upgrade flashing task dem Then, according to formula (1), the probability value P of increasing the minimum number of maintenance threads is calculated. dem .
[0138]
[0139] In formula (1), Pdem Indicates the probability value of increasing the minimum number of maintenance threads; num total Indicates the sum of the total number of idle threads in the idle thread pool and the minimum number of maintenance threads; num dem Indicates the number of required working threads to meet the user's requirements for system response timeliness and the needs of the currently executing OTA parallel upgrade flashing task.
[0140] If P dem ∈[0,0.5), when P dem When P approaches 0 and there are many idle threads in the idle thread pool, some of the idle threads in the idle thread pool can be destroyed to make the number of remaining idle threads in the idle thread pool less than or equal to the minimum number of maintenance threads. dem When it approaches 0.5, the timers corresponding to the idle threads whose recycling time exceeds the preset destruction time and are not scheduled can be reset to recalculate the recycling time of these idle threads entering the idle thread pool.
[0141] Through the above implementation, combined with the current system load rate, the total number of idle threads, and the minimum number of maintenance threads, the probability value of increasing the minimum number of maintenance threads is determined, and based on the probability value, the idle threads in the idle thread pool are maintained at an appropriate number. This can not only adapt to the sudden thread scheduling requests of the OTA master control application and improve the thread reuse rate, but also ensure the system response time to meet user needs, and can also minimize the overhead of maintaining threads in the idle thread pool.
[0142] Figure 7 This is a structural diagram of another OTA upgrade master control provided in the embodiment of the present application. Figure 7 The OTA upgrade master control (UMC) of the embodiment of the present application includes: an OTA master control application 301, a thread creation module 302, a thread running module 303, a thread monitoring module 304, a thread termination module 305, a backup thread termination module 306 and a thread recovery module 307.
[0143] The OTA master control application 301 sends a thread creation task to the thread creation module 302 .
[0144] The thread creation module 302 executes the thread creation task sent by the OTA master control application 301, creates an OTA client thread in the OTA upgrade master control (UMC), and sends a notification of running the OTA client thread to the thread running module 303 after the creation is completed.
[0145] When receiving the notification of running the OTA client thread sent by the thread creation module 302 , the thread running module 303 runs the OTA client thread created by the thread creation module 302 and reports the thread information to the thread monitoring module 304 .
[0146] The thread monitoring module 304 receives the thread monitoring instruction sent by the OTA master application 301, and monitors the thread running state of the OTA client thread based on the thread information reported by the thread running module 303. If it is confirmed that the thread running state of a certain (some) OTA client thread is in a normal termination state, a thread release instruction is sent to the thread termination module 305. The thread release instruction includes the thread identifier (such as thread ID) of the thread to be released.
[0147] The thread termination module 305 , upon receiving the thread release instruction sent by the thread monitoring module 304 , executes a thread release operation to release the thread to be released.
[0148] The thread monitoring module 304 sends a destruction instruction to the backup thread termination module 306 through the thread termination module 305 when it is detected that the release of the thread to be released fails and the number of executions of the thread release operation by the thread termination module 305 is greater than or equal to a preset number threshold.
[0149] The backup thread termination module 306 , upon receiving the destruction instruction sent by the thread monitoring module 304 , executes a thread destruction operation to destroy the thread to be released.
[0150] The thread recovery module 307 recovers the threads to be released successfully released by the thread termination module 305 or the backup thread termination module 306, and waits for subsequent destruction or reuse of the threads to be released.
[0151] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0152] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0153] Figure 8 1 is a structural diagram of a thread release device provided in an embodiment of the present application. The thread release device may be an OTA upgrade master control, and the OTA upgrade master control may be set in a CDC (Cockpit Domain Controller, smart cockpit).
[0154] like Figure 8 As shown, the thread releasing device includes: a thread monitoring module 304, a thread termination module 305 and a backup thread termination module 306.
[0155] The thread monitoring module 304 is configured to obtain thread information, the thread information including thread identifier and thread running state; if the thread running state is a normal termination state, determine the thread to be released based on the thread identifier, and notify the thread termination module to perform a thread release operation;
[0156] The thread termination module 305 executes a thread release operation to release the thread to be released;
[0157] The thread monitoring module 304 is further configured to notify the backup thread termination module to execute a thread destruction operation if it is detected that the release of the thread to be released fails;
[0158] The backup thread termination module 306 is configured to execute a thread destruction operation to destroy the thread to be released.
[0159] In some embodiments, the thread monitoring module 304 includes:
[0160] The first monitoring unit is configured to notify the thread termination module to execute the thread release operation again to release the thread to be released again if it is detected that the release of the thread to be released fails;
[0161] A second monitoring unit is configured to determine the number of executions of the thread release operation if it is detected that the thread to be released still fails to be released;
[0162] A first notification unit is configured to return to the step of notifying the thread termination module to execute the thread release operation again if the number of executions of the thread release operation is less than a preset number threshold;
[0163] The second notification unit is configured to notify the backup thread termination module to execute a thread destruction operation to destroy the thread to be released if the number of executions of the thread release operation is greater than or equal to a preset number threshold.
[0164] In some embodiments, the thread monitoring module 304 may further include:
[0165] A determination unit, if the thread running state is an abnormal termination state, determines the abnormal exit thread based on the thread identifier;
[0166] The pull-up unit notifies the thread running module to execute the thread running operation so that the abnormally exited thread can resume the running state.
[0167] In some embodiments, the thread monitoring module 304 may further include:
[0168] The recycling unit, if monitoring that the thread to be released is released successfully, notifies the thread recycling module to perform a thread recycling operation to recycle the thread to be released into the idle thread pool;
[0169] The calling unit calls the thread manager, marks the to-be-released threads recycled into the idle thread pool as idle threads, and starts a timer to record the recycling time of the idle threads entering the idle thread pool;
[0170] The destruction unit, if the thread scheduling request is not obtained when the recycling time reaches the preset destruction time, the idle thread is removed from the idle thread pool and destroyed.
[0171] In some embodiments, the above-mentioned destruction unit includes:
[0172] A load determination component determines the current system load rate;
[0173] The first destruction component moves the idle thread out of the idle thread pool and destroys it if the current system load rate is less than or equal to the first load rate threshold and the maintenance time is greater than the preset time threshold.
[0174] In some other embodiments, the above-mentioned destruction unit includes:
[0175] Statistics component, counts the total number of idle threads in the idle thread pool;
[0176] A first determination component determines the current system load rate and the minimum number of maintenance threads, wherein the minimum number of maintenance threads refers to the minimum number of threads that can be dynamically allocated by the system determined according to business requirements;
[0177] Reset component, if the current system load rate is greater than the first load rate threshold and less than the second load rate threshold, reset the timer to recalculate the recycling time of the idle thread entering the idle thread pool so that the total number of idle threads is not less than the minimum number of maintenance threads; wherein the first load rate threshold is less than the second load rate threshold.
[0178] In some embodiments, the above-mentioned destruction unit further includes:
[0179] A second determining component determines a probability value of increasing the minimum number of maintenance threads if the current system load rate is greater than a first load rate threshold and less than a second load rate threshold, and the total number of idle threads is greater than a minimum number of maintenance threads;
[0180] The second destruction component destroys some idle threads in the idle thread pool if the probability value is within a preset value range, so that the number of remaining idle threads in the idle thread pool is less than or equal to the minimum number of maintenance threads.
[0181] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0182] Fig. 9 Schematic diagram of an electronic device 9 provided in an embodiment of the present application. Fig. 9 As shown, the electronic device 9 of this embodiment includes: a processor 901, a memory 902, and a computer program 903 stored in the memory 902 and executable on the processor 901. When the processor 901 executes the computer program 903, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 901 executes the computer program 903, the functions of the modules / units in the above-mentioned device embodiments are implemented.
[0183] The electronic device 9 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 9 may include, but is not limited to, a processor 901 and a memory 902. Those skilled in the art will appreciate that Fig. 9 The electronic device 9 is merely an example and does not limit the electronic device 9 , and may include more or less components than those shown in the figure, or different components.
[0184] The processor 901 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0185] The memory 902 may be an internal storage unit of the electronic device 9, for example, a hard disk or memory of the electronic device 9. The memory 902 may also be an external storage device of the electronic device 9, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 9. The memory 902 may also include both an internal storage unit of the electronic device 9 and an external storage device. The memory 902 is used to store computer programs and other programs and data required by the electronic device.
[0186] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0187] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium (e.g., a computer-readable storage medium). Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. Computer-readable storage media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0188] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A thread release method, characterized in that: include: Obtaining thread information, wherein the thread information includes a thread identifier and a thread running state; If the thread running state is a normal termination state, determining the thread to be released based on the thread identifier, and notifying a thread termination module to perform a thread release operation to release the thread to be released; If it is detected that the release of the thread to be released fails, the backup thread termination module is notified to perform a thread destruction operation to destroy the thread to be released.
2. The method according to claim 1, characterized in that If it is detected that the release of the thread to be released fails, the backup thread termination module is notified to perform a thread destruction operation to destroy the thread to be released, including: If it is detected that the release of the thread to be released fails, the thread termination module is notified to execute the thread release operation again to release the thread to be released again; If it is detected that the thread to be released still fails to be released, the number of executions of the thread release operation is determined; If the number of executions of the thread release operation is less than the preset number threshold, returning to the step of notifying the thread termination module to execute the thread release operation again; If the number of executions of the thread release operation is greater than or equal to a preset number threshold, the backup thread termination module is notified to execute a thread destruction operation to destroy the thread to be released.
3. The method according to claim 1, characterized in that After obtaining thread information, it also includes: If the thread running state is an abnormal termination state, determining the abnormal exit thread based on the thread identifier; The thread running module is notified to execute the thread running operation so that the abnormally exited thread can resume the running state.
4. The method according to claim 1, characterized in that If the thread running state is a normal termination state, the method further includes: determining a thread to be released based on the thread identifier, and notifying a thread termination module to perform a thread release operation to release the thread to be released. If it is monitored that the thread to be released is released successfully, the thread recovery module is notified to perform a thread recovery operation to recover the thread to be released into the idle thread pool; Calling a thread manager, marking the to-be-released thread that is recycled into the idle thread pool as an idle thread, and starting a timer to record the recycling time of the idle thread entering the idle thread pool; If the thread scheduling request is not obtained when the recycling time reaches the preset destruction time, the idle thread is removed from the idle thread pool and destroyed.
5. The method according to claim 4, characterized in that The idle thread is removed from the idle thread pool and destroyed, including: Determine the current system load rate; If the current system load rate is less than or equal to a first load rate threshold and the duration is greater than a preset duration threshold, the idle thread is removed from the idle thread pool and destroyed.
6. The method according to claim 4, characterized in that The idle thread is removed from the idle thread pool and destroyed, including: Counting the total number of idle threads in the idle thread pool; Determine the current system load rate and the minimum number of maintenance threads, wherein the minimum number of maintenance threads refers to the minimum number of threads that can be dynamically allocated by the system determined according to business requirements; If the current system load rate is greater than the first load rate threshold and less than the second load rate threshold, the timer is reset to recalculate the recycle time for the idle thread to enter the idle thread pool so that the total number of idle threads is not less than the minimum number of maintenance threads; wherein the first load rate threshold is less than the second load rate threshold.
7. The method according to claim 6, characterized in that After determining the current system load rate and the minimum number of maintenance threads, it also includes: If the current system load rate is greater than a first load rate threshold and less than a second load rate threshold, and the total number of idle threads is greater than the minimum number of maintenance threads, then determining a probability value for increasing the minimum number of maintenance threads; If the probability value is within a preset value range, some idle threads in the idle thread pool are destroyed so that the number of remaining idle threads in the idle thread pool is less than or equal to the minimum number of maintenance threads.
8. A thread release device, characterized in that: include: Thread monitoring module, thread termination module and backup thread termination module; The thread monitoring module is configured to obtain thread information, wherein the thread information includes a thread identifier and a thread running state; If the thread running state is a normal termination state, determining the thread to be released based on the thread identifier, and notifying the thread termination module to perform a thread release operation; The thread termination module executes a thread release operation to release the thread to be released; The thread monitoring module is further configured to notify the backup thread termination module to execute a thread destruction operation if it is detected that the release of the thread to be released fails; The backup thread termination module is configured to execute a thread destruction operation to destroy the thread to be released.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.