WO2023193527A1 - 线程执行方法、装置、电子设备及计算机可读存储介质 - Google Patents

线程执行方法、装置、电子设备及计算机可读存储介质 Download PDF

Info

Publication number
WO2023193527A1
WO2023193527A1 PCT/CN2023/077353 CN2023077353W WO2023193527A1 WO 2023193527 A1 WO2023193527 A1 WO 2023193527A1 CN 2023077353 W CN2023077353 W CN 2023077353W WO 2023193527 A1 WO2023193527 A1 WO 2023193527A1
Authority
WO
WIPO (PCT)
Prior art keywords
thread
priority
execution
target priority
target
Prior art date
Application number
PCT/CN2023/077353
Other languages
English (en)
French (fr)
Inventor
邝国立
钟斌
Original Assignee
深圳Tcl新技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳Tcl新技术有限公司 filed Critical 深圳Tcl新技术有限公司
Publication of WO2023193527A1 publication Critical patent/WO2023193527A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5021Priority
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the field of computer technology, and specifically to a thread execution method, device, electronic equipment and computer-readable storage medium.
  • Threads are the smallest units that the operating system can perform calculation scheduling. Among them , the thread is included in the process and is the actual operating unit in the process.
  • a thread refers to a single sequence of control flow in the process.
  • This application provides a thread execution method, device, electronic equipment and computer-readable storage medium, aiming to solve the technical problem of coordinating the execution priority of threads and improving the execution efficiency of the system.
  • this application provides a thread execution method, which method includes: When it is detected that the first thread wakes up the second thread, determine the target priority based on the current priority of the first thread; The target priority is passed to the second thread, and the second thread is executed according to the target priority.
  • embodiments of the present application also provide a thread execution device, including: A determination module configured to determine the target priority based on the current priority of the first thread when it is detected that the first thread wakes up the second thread; An execution module, configured to pass the target priority to the second thread, and execute the second thread according to the target priority.
  • the device further includes a return execution module, and the return execution module includes: A return unit, configured to return the execution result of the second thread to the first thread based on the wake-up, wherein the execution result is obtained after the second thread executes according to the target priority; An execution unit, configured to execute the first thread according to the execution result.
  • the execution unit includes: A waiting subunit, configured to set the first thread to a waiting state when the second thread is executed according to the target priority; A running subunit, configured to adjust the first thread to a running state according to the execution result when the first thread receives the execution result.
  • the determining module includes: A recording unit configured to record the number of times the first thread wakes up the second thread and the second thread wakes up the first thread within a preset time threshold to obtain the number of behaviors; A first determination unit configured to determine a target priority based on the current priority of the first thread when the number of behaviors is greater than a preset threshold.
  • the target priority is higher than or equal to the original priority of the second thread in the system configuration.
  • the determining module includes: The second determination unit is configured to directly use the current priority as the target priority.
  • the determining module includes: An acquisition unit, configured to acquire a mapping relationship set, where the mapping relationship set includes a mapping relationship between a preset current priority and a preset target priority;
  • the third determination unit is configured to determine the target priority corresponding to the current priority of the first thread according to the mapping relationship.
  • inventions of the present application also provide an electronic device.
  • the electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor.
  • the processor executes the computer program, the above-mentioned thread execution is implemented. steps in the method.
  • embodiments of the present application also provide a computer-readable storage medium.
  • a computer program is stored on the computer-readable storage medium.
  • the steps in the above thread execution method are implemented.
  • the embodiment of the present application determines the target priority based on the current priority of the first thread, and passes the target priority to the second thread, so that the second thread can perform tasks based on the target priority. Execution, among which, by adjusting the priority of the thread that is awakened for communication, the priority of the awakened thread can be increased to realize priority execution of the awakened thread and improve execution efficiency.
  • Figure 1 is a schematic diagram of a scenario of a thread execution method provided by an embodiment of the present application
  • Figure 2 is a schematic flowchart of a thread execution method provided by an embodiment of the present application
  • Figure 3 is a schematic diagram of a scenario in which the first thread is blocked by the second thread in the thread execution method provided by the embodiment of the present application
  • Figure 4 is a schematic flowchart of recording wake-up behavior in the thread execution method provided by the embodiment of the present application
  • Figure 5 is a schematic diagram of the priority parameter transfer process in the thread execution method provided by the embodiment of the present application
  • Figure 6 is a schematic structural diagram of a thread execution device provided by an embodiment of the present application
  • FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • Embodiments of the present application provide a thread execution method, device, electronic device, and computer-readable storage medium.
  • the electronic devices include terminals or servers and other devices, where the terminals can be computers, personal notebooks, mobile phones and other devices, and the servers can be independent physical servers, It can also be a server cluster or distributed system composed of multiple physical servers, or it can provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, and security services. , content delivery network (CDN, Content Delivery Network), and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms.
  • the servers can be connected directly or indirectly through wired or wireless communication methods.
  • the thread execution method can be executed by the terminal device alone, or the thread execution method can be executed by the server alone, or the terminal device and the server can jointly execute the thread execution method.
  • the terminal device and the server can jointly execute the thread execution method. Take the method as an example.
  • other devices can also be added to assist in completing the thread execution method.
  • the types of other devices are not limited here; the terminal device and the server are connected through a network, for example, through Wireless network connection, etc.
  • the specific execution process is as follows: After responding to the user's trigger operation, the terminal device 10 triggers the execution of the corresponding thread (such as the main thread). The thread wakes up the corresponding sub-thread during the execution process, and the main thread and the corresponding sub-thread jointly execute the response or completion of the user's trigger operation. feedback.
  • the server 11 When the server 11 detects that a wake-up operation occurs between threads, it determines the target priority based on the current priority of the wake-up thread (such as the first thread), sends the target priority to the awakened thread (such as the second thread), and The awakened thread is executed according to the target priority.
  • the awakening thread may include the main thread of the foreground application
  • the awakened thread may include the main thread of the background application.
  • the execution of the main thread of the foreground application is triggered. execution, and then the main thread of the foreground application responds accordingly by waking up the main thread of the background application.
  • the embodiment of the present application detects that the first thread wakes up the second thread, it determines the target priority according to the current priority of the first thread, and passes the target priority to the second thread, so that the second thread can determine the target priority according to the target priority. Execution is performed at different levels. By adjusting the priority of the thread that is awakened for communication, priority execution of the awakened thread can be achieved after increasing the priority of the awakened thread, thereby improving execution efficiency.
  • FIG 2 is a schematic flowchart of a thread execution method provided by an embodiment of the present application.
  • the specific process of the thread execution method can be as follows: 101. When it is detected that the first thread wakes up the second thread, determine the target priority based on the current priority of the first thread.
  • thread is the smallest unit that the operating system can perform calculation scheduling. It is included in the process and is the actual operating unit in the process.
  • a thread refers to a single sequential control flow in a process. Multiple threads can run concurrently in a process, and each thread performs different tasks in parallel. It is also called lightweight processes in Unix System V and SunOS, but lightweight processes refer more to kernel threads, while user threads are called threads.
  • the dynamic setting of the scene depends on the execution of the thread, and the execution of each thread depends on the configuration of the corresponding priority, such as the priority of the foreground application thread and the priority of the background application.
  • the levels are different.
  • high-priority threads have priority over low-priority threads.
  • the main thread can assign long-term tasks to sub-threads to complete.
  • the main thread wakes up the execution of the sub-thread, or the main thread allocates part of the tasks to the sub-thread, and completes the execution of the main thread's subsequent tasks based on the execution results of the sub-thread.
  • the first thread refers to the thread that initiates the awakening of other threads.
  • the first thread may include the main thread corresponding to the foreground application.
  • the second thread refers to a thread that is awakened by other threads.
  • the second thread may include the main thread corresponding to the background application.
  • the awakening of the second thread by the first thread includes the first thread calling a function (handler) to send a message (message) to the second thread, and the second thread starts running after receiving the message (message). , to realize the awakening of the first thread to the second thread.
  • the second thread that is, the awakened thread
  • the execution priority of the child thread is lower
  • the lower priority makes it take a longer time for the thread to obtain the execution result, making it difficult to execute the first thread.
  • Timely feedback of results Therefore, in the embodiment of the present application, by determining the target priority and adjusting the priority of the second thread, the time for the second thread to obtain the execution result is shortened, and the efficiency of the second thread to obtain the execution result is improved.
  • the determination of the target priority is used to adjust the priority of the second thread. Determining the target priority through the priority of the first thread can enable the priority of the second thread to match the priority of the first thread. , to facilitate the coordinated execution of the second thread and the first thread.
  • the priority of the second thread can be appropriately increased to reduce the execution wait of the first thread and avoid execution. Block or cause stuck phenomenon to improve execution efficiency.
  • the execution of a system task depends on multiple threads, and there is a first thread that wakes up to execute a second thread (at this time, the execution of the first thread does not depend on the execution of the second thread).
  • the execution efficiency or start execution time of the second thread affects the execution efficiency of the overall task of the system. Therefore, the priority of the second thread can be adjusted according to the priority of the first thread. To speed up the execution of the second thread and speed up the execution efficiency of the overall system task.
  • the execution of the first thread can also be carried out according to the execution result of the second thread, that is, optionally, in some embodiments of the present application, the step "transfer the target priority After giving the second thread and executing the second thread according to the target priority, the method further includes: Based on the wake-up, return the execution result of the second thread to the first thread, wherein the execution result is obtained after the second thread executes according to the target priority; The first thread is executed according to the execution result.
  • the first thread when the execution of the first thread depends on the execution result of the second thread, the first thread can be set to a waiting state during the execution of the second thread, that is, optionally,
  • the step "execute the first thread according to the execution result" includes: When the second thread executes according to the target priority, setting the first thread to a wait state; When the first thread receives the execution result, the first thread is adjusted to a running state according to the execution result.
  • the waiting state may include a sleep state.
  • the first thread may be set to the waiting state; when the execution of the second thread ends, The execution state of the first thread can be adjusted to the running state, and the first thread can be executed according to the execution result of the second thread.
  • the first thread wakes up the second thread and the second thread wakes up the first thread within the preset time threshold, indicating that there is mutual wake-up communication between the first thread and the second thread.
  • the second thread will The execution results are passed to the first thread. Based on this, the priority of the second thread can be adjusted according to the priority of the first thread to speed up the execution of the second thread.
  • the target priority is higher than or equal to the original priority of the second thread in the system configuration, where the original priority is the ordinary priority originally carried by the thread.
  • the execution of the second thread is accelerated, so that the system tasks corresponding to the first thread and the second thread can be executed and completed as soon as possible.
  • the current priority of the first thread can be directly used as the target priority of the second thread, that is, optionally, in some embodiments of the present application, the step "according to the first thread"
  • the current priority of the thread determines the target priority", including: Directly use the current priority as the target priority.
  • the second thread has the same scheduling resources as the first thread, so that the second thread can execute quickly in cooperation with the first thread, solving the problem of thread priority inversion. Problem (low-priority data cannot be adequately scheduled, resulting in high-priority threads waiting for shared data for too long).
  • the target priority of the second thread can also be determined according to the mapping relationship between the current priority and the target priority. That is, optionally, in some embodiments of the present application, the step "according to The current priority of the first thread determines the target priority, including: Obtain a mapping relationship set, which includes a mapping relationship between a preset current priority and a preset target priority; According to the mapping relationship, a target priority corresponding to the current priority of the first thread is determined.
  • mapping relationship set can be established in advance based on actual needs or experience parameters, wherein the target priority required by the second thread can be quickly located according to the mapping relationship set.
  • the adjustment of the priority can be realized by adjusting the corresponding priority parameter.
  • the priority parameter interval is [-20, 19], where the priority parameter -20 corresponds to the highest priority. Level, priority parameter 19 corresponds to the lowest priority, and the priority parameter can be adjusted to adjust the priority of the thread.
  • the method further includes: Adjust the priority of the second thread from the target priority to the original priority in the system configuration.
  • the target priority is determined according to the current priority of the first thread, and the target priority is passed to the second thread, so that the second thread can Execution is performed according to the target priority.
  • priority execution of the awakened thread can be achieved after increasing the priority of the awakened thread, thereby improving execution efficiency.
  • the execution efficiency of the first thread can also be improved to avoid the first thread processing waiting or sleeping state for a long time.
  • FIG. 3 is a schematic diagram of a scenario in which the first thread is blocked by the second thread provided in an embodiment of the present application.
  • the details are as follows: After the first thread wakes up the second thread by sending a message (message) by calling a function (handler) during the running process, since the first thread needs to wait for the execution result of the second thread before subsequent execution, during the execution process of the second thread The first thread is in a waiting state (sleeping state); The second thread starts execution after being awakened by the first thread. However, because the second thread has a lower priority, it needs to wait for other threads unrelated to the current task to complete before it can execute. Therefore, the second thread exists for a long time.
  • the second thread After the second thread re-executes, it calls the function (handler) to send a message (message), wakes up the first thread and ends the operation; The first thread performs subsequent execution based on the execution result of the second thread to complete system tasks.
  • embodiments of the present application can adjust the execution priority of the second thread to speed up the execution of the second thread and reduce the execution waiting time of the first thread.
  • the first thread calls the handler to send a message to the second thread.
  • the second thread starts running after receiving the message.
  • the first thread sends the message, it enters the waiting state, that is, it waits for the second thread to return the message. You can proceed to the next step and continue running until the second thread completes and returns the message.
  • the priority parameter is not transmitted to the second thread, the second thread will be allocated less time slices and lower priority parameters, causing the scheduling resources to be preempted by irrelevant threads, affecting the execution of the second thread, thereby blocking the first thread from running, reducing the System execution efficiency.
  • Figure 4 is a schematic flow chart of recording wake-up behaviors provided by an embodiment of the present application. The details are as follows: Identify threads and determine the first thread (identify key threads); Determine whether the first thread calls a function (handler) to send a message (message) to the second thread. If yes, execute step 123. If not, execute step 129; Determine whether the running of the second thread has timed out. If not, execute step 124. If yes, execute step 129; After the second thread finishes running, determine whether the second thread directly enters the sleep mode. If not, execute step 125. If yes, execute step 129; Determine whether the second thread returns information (message) to the first thread through the function (handler).
  • step 126 If yes, execute step 126; if not, execute step 129; Record the number of times it is woken up and returned (the number of behaviors or the number of relationship records), and the thread pair relationship record is obtained; Determine whether the number of relationship records in the thread's relationship record is greater than the preset number threshold. If yes, step 128 is executed. If not, step 129 is executed; Record the relationship pair between the first thread and the second thread (establish a relationship pair based on the IDs of the first thread and the second thread); Finish.
  • the behavior of the first thread waking up the second thread and the second thread waking up the first thread within the preset time threshold indicates that there is a cooperative relationship between the first thread and the second thread.
  • the execution of the first thread may depend on The execution result of the second thread.
  • the priority parameters are adjusted only after the number of behaviors exceeds the preset quantity threshold, so that the priority parameters can be adjusted after the preset quantity threshold is met. Pass, adjust the priority of the second thread, and speed up the start execution time of the second thread.
  • the wake-up behavior can be recorded in the call relationship management list.
  • the priority parameters are transferred according to the relationship management list. For example, by collecting asynchronous call characteristics between threads, For example, the asynchronous calling behavior recording module records the behavior of a high-priority thread asynchronously waking up a low-priority thread, and at the same time, the low-priority thread asynchronously wakes up the high-priority thread after a period of time.
  • the asynchronous call needs to infect the thread priority (the priority parameters of the high-priority thread are transmitted to the low-priority thread), and a call relationship management list is generated based on the number of records.
  • the call relationship management list determines whether to pass priority parameters.
  • Figure 5 is a schematic diagram of the priority parameter transfer process provided by an embodiment of the present application. The details are as follows: Identify threads and determine the first thread (identify key threads); Determine whether the first thread wakes up the second thread and the first thread is in a waiting state. If yes, execute step 132; if not, execute step 136; Determine whether the second thread is in the call relationship management list. If so, perform step 133. If not, perform step 136; Pass the target priority parameter to the second thread (the awakened thread) so that the second thread can execute according to the priority corresponding to the priority parameter; Determine whether the second thread returns information (message) through the function (handler) after it finishes running. If so, execute step 135; if not, execute step 136; Restore the priority parameters of the second thread and adjust the priority of the second thread to the original priority configured by the system (restoration of priority after thread processing); Finish.
  • the execution of the second thread is accelerated, and the priority is restored after the execution of the second thread is completed, so that the second thread can execute threads in the default priority order. Ensure system stability.
  • the present application also provides a thread execution device based on the above thread execution method.
  • the meaning of the third target word is the same as in the above thread execution method. For specific implementation details, please refer to the description in the method embodiment.
  • Figure 6 is a schematic structural diagram of a thread execution device provided by this application.
  • the thread execution device may include:
  • the determination module 201 is configured to determine a target priority based on the current priority of the first thread when it is detected that the first thread wakes up the second thread.
  • the execution module 202 is configured to pass the target priority to the second thread, and execute the second thread according to the target priority.
  • the device further includes a return execution module, and the return execution module includes: A return unit, configured to return the execution result of the second thread to the first thread based on the wake-up, wherein the execution result is obtained after the second thread executes according to the target priority; An execution unit, configured to execute the first thread according to the execution result.
  • the execution unit includes: A waiting subunit, configured to set the first thread to a waiting state when the second thread is executed according to the target priority; A running subunit, configured to adjust the first thread to a running state according to the execution result when the first thread receives the execution result.
  • the determining module 201 includes: A recording unit configured to record the number of times the first thread wakes up the second thread and the second thread wakes up the first thread within a preset time threshold to obtain the number of behaviors; A first determination unit configured to determine a target priority based on the current priority of the first thread when the number of behaviors is greater than a preset threshold.
  • the target priority is higher than or equal to the original priority of the second thread in the system configuration.
  • the determining module 201 includes: The second determination unit is configured to directly use the current priority as the target priority.
  • the determining module 201 includes: An acquisition unit, configured to acquire a mapping relationship set, where the mapping relationship set includes a mapping relationship between a preset current priority and a preset target priority;
  • the third determination unit is configured to determine the target priority corresponding to the current priority of the first thread according to the mapping relationship.
  • the determination module 201 determines the target priority according to the current priority of the first thread, and then the execution module 202 passes the target priority to the second thread, and The second thread is executed based on the target priority.
  • the embodiment of the present application detects that the first thread wakes up the second thread, it determines the target priority according to the current priority of the first thread, and passes the target priority to the second thread, so that the second thread can determine the target priority according to the target priority. Execution is performed at different levels. By adjusting the priority of the thread that is awakened for communication, priority execution of the awakened thread can be achieved after increasing the priority of the awakened thread, thereby improving execution efficiency.
  • the execution efficiency of the first thread can also be improved to avoid the first thread processing waiting or sleeping state for a long time. Improve the overall execution efficiency of the system.
  • this application also provides an electronic device, as shown in Figure 7, which shows a schematic structural diagram of the electronic device involved in this application.
  • the electronic device may include components such as a processor 401 of one or more processing cores, a memory 402 of one or more computer-readable storage media, a power supply 403, and an input unit 404.
  • a processor 401 of one or more processing cores may include components such as a processor 401 of one or more processing cores, a memory 402 of one or more computer-readable storage media, a power supply 403, and an input unit 404.
  • FIG. 7 does not constitute a limitation of the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange different components.
  • the processor 401 is the control center of the electronic device, using various interfaces and lines to connect various parts of the entire electronic device, by running or executing software programs and/or modules stored in the memory 402, and calling software programs stored in the memory 402. Data, perform various functions of electronic devices and process data.
  • the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, where the application processor mainly processes operating systems, user interfaces, application programs, etc. , the modem processor mainly handles wireless communications. It can be understood that the above modem processor may not be integrated into the processor 401.
  • the memory 402 can be used to store software programs and modules.
  • the processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402 .
  • the memory 402 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the storage data area may store a program based on Data created by the use of electronic devices, etc.
  • memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402 .
  • the electronic device also includes a power supply 403 that supplies power to various components.
  • the power supply 403 can be logically connected to the processor 401 through a power management system, so that functions such as charging, discharging, and power consumption management can be implemented through the power management system.
  • the power supply 403 may also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
  • the electronic device may also include an input unit 404 that may be used to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
  • an input unit 404 may be used to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
  • the electronic device may also include a display unit and the like, which will not be described again here.
  • the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the executable files stored in The application program in the memory 402 thereby implements the steps in any thread execution method provided by this application.
  • the embodiment of the present application determines the target priority based on the current priority of the first thread, and passes the target priority to the second thread, so that the second thread can perform tasks based on the target priority. Execution, among which, by adjusting the priority of the thread that is awakened for communication, the priority of the awakened thread can be increased to realize priority execution of the awakened thread and improve execution efficiency.
  • the execution efficiency of the first thread can also be improved to avoid the first thread processing waiting or sleeping state for a long time. Improve the overall execution efficiency of the system.
  • the present application provides a computer-readable storage medium.
  • a computer program is stored on the computer-readable storage medium.
  • the computer program can be loaded by a processor to execute any of the thread execution methods provided by the present application. A step of.
  • the computer-readable storage medium may include: read only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本申请实施例公开了一种线程执行方法、装置、电子设备及计算机可读存储介质,该方法包括:当检测到第一线程唤醒第二线程时,根据第一线程的当前优先级,确定目标优先级;将目标优先级传递给第二线程,并根据目标优先级执行第二线程。将目标优先级传递给第二线程,使得第二线程能够根据目标优先级进行执行,提升执行效率。

Description

线程执行方法、装置、电子设备及计算机可读存储介质
本申请要求于2022年04月07日提交中国专利局、申请号为202210363999.0、申请名称为“线程执行方法、装置、电子设备及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术领域,具体涉及一种线程执行方法、装置、电子设备及计算机可读存储介质。
背景技术
随着计算机技术的快速发展,终端设备的种类和功能越来越多,其中,终端设备系统的执行或者功能的多样性依赖于线程的执行,线程是操作系统能够进行运算调度的最小单位,其中,线程被包含在进程之中,是进程中的实际运作单位,一条线程指的是进程中一个单一顺序的控制流。
技术问题
但是,随着终端设备系统功能多样性的增加,一个进程中可以并发多个线程,每条线程并行执行不同的任务,而多个线程完成同一系统功能时,存在线程之间互相等待执行,系统反馈时延较长的问题。
技术解决方案
本申请提供一种线程执行方法、装置、电子设备及计算机可读存储介质,旨在解决的技术问题在于:协调线程的执行优先级,提升系统的执行效率。
为实现上述目的,本申请解决技术问题所采用的技术方案如下:
第一方面,本申请提供一种线程执行方法,该方法包括:
当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级;
将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
第二方面,本申请实施例还提供了一种线程执行装置,包括:
确定模块,用于当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级;
执行模块,用于将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
其中,在本申请的一些实施例中,该装置还包括返回执行模块,返回执行模块包括:
返回单元,用于基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
执行单元,用于根据所述执行结果进行所述第一线程的执行。
其中,在本申请的一些实施例中,执行单元包括:
等待子单元,用于当所述第二线程根据所述目标优先级执行时,将所述第一线程设置为等待状态;
运行子单元,用于当所述第一线程接收到所述执行结果时,根据所述执行结果将所述第一线程调整为运行状态。
其中,在本申请的一些实施例中,确定模块包括:
记录单元,用于记录所述第一线程唤醒所述第二线程、且所述第二线程在预设时间阈值内唤醒所述第一线程的次数,得到行为次数;
第一确定单元,用于当所述行为次数大于预设数量阈值后,根据所述第一线程的当前优先级确定目标优先级。
其中,在本申请的一些实施例中,目标优先级高于或等于所述第二线程在系统配置中的原始优先级。
其中,在本申请的一些实施例中,确定模块包括:
第二确定单元,用于直接将所述当前优先级作为目标优先级。
其中,在本申请的一些实施例中,确定模块包括:
获取单元,用于获取映射关系集合,所述映射关系集合包括预设当前优先级与预设目标优先级的映射关系;
第三确定单元,用于根据所述映射关系,确定所述第一线程的当前优先级对应的目标优先级。
第三方面,本申请实施例还提供了一种电子设备,电子设备包括存储器、处理器及存储在存储器中并可在处理器上运行的计算机程序,处理器执行计算机程序时实现上述的线程执行方法中的步骤。
第四方面,本申请实施例还提供了一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序,计算机程序被处理器执行时实现上述的线程执行方法中的步骤。
有益效果
本申请实施例在检测到第一线程唤醒第二线程时,根据第一线程的当前优先级确定目标优先级,并将目标优先级传递给第二线程,使得第二线程能够根据目标优先级进行执行,其中,通过对被唤醒通信的线程的优先级的调整,可在提升被唤醒的线程的优先级后,实现被唤醒线程的优先执行,提升执行效率。
附图说明
下面结合附图,通过对本申请的具体实施方式详细描述,将使本申请的技术方案及其有益效果显而易见。
图1是本申请实施例提供的线程执行方法的场景示意图;
图2是本申请实施例提供的线程执行方法的流程示意图;
图3是本申请实施例提供的线程执行方法中第一线程被第二线程阻塞的场景示意图;
图4是本申请实施例提供的线程执行方法中对唤醒行为进行记录的流程示意图;
图5是本申请实施例提供的线程执行方法中优先级参数传递流程示意图;
图6是本申请实施例提供的线程执行装置的结构示意图;
图7是本申请实施例提供的电子设备的结构示意图。
本发明的实施方式
下面将结合本申请中的附图,对本申请中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
本申请实施例提供一种线程执行方法、装置、电子设备及计算机可读存储介质。具体地,本申请实施例提供适用于电子设备的线程执行装置,其中,电子设备包括终端或者服务器等设备,其中,终端可以为计算机、个人笔记本或者手机等设备,服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、内容分发网络(CDN,Content Delivery Network)、以及大数据和人工智能平台等基础云计算服务的云服务器,服务器可以通过有线或无线通信方式进行直接或间接地连接。
本申请实施例可以单独由终端设备执行线程执行方法,或者是单独由服务器执行线程执行方法,或者是终端设备和服务器共同执行线程执行方法,请参阅图1,以终端设备和服务器共同执行线程执行方法为例,其中,在终端设备和服务器的基础上也可以增加其他设备来辅助完成线程执行方法,在此对其他设备的类型不做限定;终端设备与服务器之间通过网络连接,比如,通过无线网络连接等,具体执行过程如下:
终端设备10在响应用户的触发操作后,触发执行相应的线程(如主线程),线程在执行过程中唤醒相应的子线程,由主线程和相应的子线程共同执行完成用户触发操作的响应或反馈。
其中,服务器11在检测到线程之间发生唤醒操作时,根据唤醒线程(如第一线程)的当前优先级确定目标优先级,将目标优先级发送给被唤醒线程(如第二线程),并根据目标优先级执行被唤醒线程。
其中,在本申请实施例中,唤醒线程可以包括前台应用的主线程,被唤醒线程可以包括后台应用的主线程,相应的,用户在终端设备的用户界面触发操作后,触发执行前台应用主线程的执行,随后,前台应用主线程通过唤醒后台应用主线程进行相应的响应反馈。
其中,本申请实施例在检测到第一线程唤醒第二线程时,根据第一线程的当前优先级确定目标优先级,并将目标优先级传递给第二线程,使得第二线程能够根据目标优先级进行执行,其中,通过对被唤醒通信的线程的优先级的调整,可在提升被唤醒的线程的优先级后,实现被唤醒线程的优先执行,提升执行效率。
以下分别进行详细说明。需说明的是,以下实施例的描述顺序不作为对实施例优先顺序的限定。
请参阅图2,图2为本申请实施例提供的线程执行方法的流程示意图。该线程执行方法的具体流程可以如下:
101、当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级。
其中,线程(thread)是操作系统能够进行运算调度的最小单位。它被包含在进程之中,是进程中的实际运作单位。一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务。在Unix System V及SunOS中也被称为轻量进程(lightweight processes),但轻量进程更多指内核线程(kernel thread),而把用户线程(user thread)称为线程。
例如,在安卓林纳斯(Linux)桌面系统中,场景动态的设置依赖于线程的执行,而各个线程的执行依赖于相应优先级的配置,如,前台应用线程的优先级与后台应用的优先级不同,一般来说,高优先级的线程要优先于低优先级线程的执行,而通过对各个线程优先级的配置,使得各个线程能够有序执行。
其中,线程在执行过程中并非全部是各自独立的,即存在部分线程需要唤醒其他线程来协同执行完成系统任务的情况,例如,主线程可以将耗时较长的任务分配给子线程去完成,由主线程唤醒子线程的执行,或者,主线程将一部分任务分配给子线程,并根据子线程的执行结果来完成主线程后续任务的执行。
其中,在本申请实施例中,第一线程指发起唤醒其他线程的线程,在本申请实施例中,第一线程可以包括前台应用对应的主线程。
其中,在本申请实施例中,第二线程指被其他线程唤醒的线程,在本申请实施例中,第二线程可以包括后台应用对应的主线程。
其中,在本申请实施例中,第一线程对第二线程的唤醒包括第一线程调用函数(handler)向第二线程发送信息(message),第二线程在收到信息(message)后开始运行,实现第一线程对第二线程的唤醒。
其中,由于第二线程即被唤醒的线程一般包括子线程,而子线程的执行优先级较低,而较低的优先级使得线程获取执行结果的时间较长,难以实现对第一线程的执行结果的及时回馈,因此,在本申请实施例中,通过确定目标优先级,对第二线程进行优先级调整,缩短第二线程获取执行结果的时间,提升第二线程获取执行结果的效率。
其中,目标优先级的确定用于对第二线程的优先级调整,其中,通过第一线程的优先级确定目标优先级,可使得第二线程的优先级能够与第一线程的优先级相互匹配,便于实现第二线程与第一线程的协调执行。
102、将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
其中,通过根据第一线程的优先级确定的目标优先级,并根据目标优先级对第二线程的执行进行调度,可实现第二线程与第一线程的协调执行。
例如,在本申请实施例中,当第一线程依赖于第二线程的执行结果才能进行执行时,可以将第二线程的优先级进行适当的提升,以减少第一线程的执行等待,避免执行阻塞或者形成卡顿现象,提高执行效率。
再例如,在本申请实施例中,当系统任务的执行依赖于多个线程时,且存在有第一线程唤醒执行第二线程时(此时第一线程的执行不依赖于第二线程的执行结果,仅存在唤醒多个子线程的情况),第二线程的执行效率或者开始执行时间影响系统整体任务的执行效率,因此,可以根据第一线程的优先级对第二线程的优先级进行调整,以加快第二线程的执行,加快系统整体任务的执行效率。
其中,在本申请实施例中,还可以根据第二线程的执行结果来进行第一线程的执行,即,可选的,在本申请的一些实施例中,步骤“将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程”之后,该方法还包括:
基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
根据所述执行结果进行所述第一线程的执行。
其中,由于系统执行或者场景动画的配置需要多个线程的协同执行,且在复杂场景中,需要线程之间的相互唤醒通信来完成整体任务的执行,而线程之间的相互唤醒存在等待对方线程执行结果才能进行执行处理的情况。而针对第一线程的执行依赖于第二线程的执行结果时,可以将第二线程的优先级进行调整,例如提升第二线程的优先级,提升开始执行的时间点,提升系统的执行效率,避免出现阻塞、卡顿等现象。
其中,在本申请实施例中,当第一线程的执行依赖于第二线程的执行结果时,在第二线程执行过程中,可以将第一线程设置为等待状态,即,可选的,在本申请的一些实施例中,步骤“根据所述执行结果进行所述第一线程的执行”,包括:
当所述第二线程根据所述目标优先级执行时,将所述第一线程设置为等待状态;
当所述第一线程接收到所述执行结果时,根据所述执行结果将所述第一线程调整为运行状态。
其中,等待状态可以包括休眠状态,当第一线程的执行依赖于第二线程的执行结果,且第二线程正在执行时,可以将第一线程设置为等待状态;当第二线程执行结束后,可以将第一线程的执行状态调整为运行状态,根据第二线程的执行结果对第一线程进行执行。
其中,在本申请实施例中,还可以根据唤醒次数来确定是否需要对第二线程进行优先级的重新确定,即,可选的,在本申请的一些实施例中,步骤“根据所述第一线程的当前优先级,确定目标优先级”,包括:
记录所述第一线程唤醒所述第二线程、且所述第二线程在预设时间阈值内唤醒所述第一线程的次数,得到行为次数;
当所述行为次数大于预设数量阈值后,根据所述第一线程的当前优先级确定目标优先级。
其中,第一线程唤醒第二线程且第二线程在预设时间阈值内又唤醒了第一线程,说明了第一线程与第二线程之间存在相互唤醒通信的情况,例如,第二线程将执行结果传递给了第一线程。基于此,可以根据第一线程的优先级对第二线程的优先级进行调整,以加快第二线程的执行。
其中,在本申请实施例中,目标优先级高于或者等于第二线程在系统配置中的原始优先级,其中,原始优先级是线程原始携带的普通优先级。其中,通过提升第二线程的优先级,加快第二线程的执行,使得第一线程和第二线程对应的系统任务能够尽快执行和完成。
其中,在本申请实施例中,可以将第一线程的当前优先级直接作为第二线程的目标优先级,即,可选的,在本申请的一些实施例中,步骤“根据所述第一线程的当前优先级,确定目标优先级”,包括:
直接将所述当前优先级作为目标优先级。
其中,通过将第二线程调整为与第一线程相同的优先级,使得第二线程拥有与第一线程相同的调度资源,使得第二线程能够与第一线程协同快速执行,解决线程优先级翻转问题(低优先级数据无法得到足够的调度导致高优先级线程等待共享数据时延过长)。
其中,在本申请实施例中,还可以根据当前优先级与目标优先级的映射关系来确定第二线程的目标优先级,即,可选的,在本申请的一些实施例中,步骤“根据所述第一线程的当前优先级,确定目标优先级”,包括:
获取映射关系集合,所述映射关系集合包括预设当前优先级与预设目标优先级的映射关系;
根据所述映射关系,确定所述第一线程的当前优先级对应的目标优先级。
其中,该映射关系集合可以预先根据实际需要或者经验参数进行建立,其中,根据映射关系集合,可以快速定位第二线程所需的目标优先级。
其中,在本申请实施例中,对优先级的调整可以通过对相应的优先级参数进行调整来实现,例如,优先级参数区间为[-20,19],其中优先级参数-20对应最高优先级,优先级参数19对应最低优先级,可以调整优先级参数来调整线程的优先级。
其中,在本申请实施例中,在第二线程根据目标优先级执行后,可以将第二线程的优先级进行恢复,以保证第二线程再被其他线程唤醒时能够保证系统执行稳定性,即,可选的,在本申请实施例中,步骤“根据所述目标优先级执行所述第二线程”之后,该方法还包括:
将第二线程的优先级由目标优先级调整为系统配置中的原始优先级。
其中,在本申请实施例中,在检测到第一线程唤醒第二线程时,根据第一线程的当前优先级确定目标优先级,并将目标优先级传递给第二线程,使得第二线程能够根据目标优先级进行执行,其中,通过对被唤醒通信的线程的优先级的调整,可在提升被唤醒的线程的优先级后,实现被唤醒线程的优先执行,提升执行效率。同时,当第一线程的执行依赖于第二线程的执行结果时,在实现第二线程的优先执行后,还可以提升第一线程的执行效率,避免第一线程长时间处理等待或者休眠状态,提升系统(安卓系统不同优先级线程之间的异步调用)整体执行效率。解决不同优先级线程之间异步调用时由于异步线程(第二线程)优先级低被抢占,阻塞主关键线程(第一线程)运行。
其中,由于第二线程(如子线程)在执行过程中容易因资源调度情况不够(如可调度资源被占用)而处于等待状态,进一步使得第一线程不能及时获取第二线程的反馈,使得第一线程出现阻塞,影响系统执行效率,例如,请参阅图3,图3是本申请实施例提供的第一线程被第二线程阻塞的场景示意图,具体如下:
第一线程在运行过程中通过调用函数(handler)发送信息(message)唤醒第二线程后,由于第一线程需等待第二线程的执行结果才能进行后续的执行,因此,在第二线程执行过程中第一线程处于等待状态(休眠状态);
第二线程在被第一线程唤醒后开始执行,但是由于第二线程的优先级较低,需等待其他与当前任务无关的线程执行完成后才能执行,因此,第二线程存在一段时间较长的待运行状态,并在无关线程释放资源后才继续执行;
第二线程重新执行后调用函数(handler)发送信息(message)唤醒第一线程后结束运行;
第一线程根据第二线程的执行结果进行后续的执行,完成系统任务。
其中,由于第一线程与第二线程之间存在相互唤醒的情况,例如,第一线程的执行依赖于第二线程的执行结果,因此,当第二线程的执行存在等待延迟时,影响第一线程的执行,因此,本申请实施例可以对第二线程的执行优先级进行调整,以加快第二线程的执行,减少第一线程的执行等待时间。
例如,请参阅图3,第一线程运行时调用handler发送message给第二线程,第二线程收到message后开始运行,第一线程发送完message后进入等待状态,即等待第二线程返回message才可进行下一步操作,直到第二线程运行结束返回message才继续运行。若不传染优先级参数给第二线程,则第二线程由于分配的时间片少、优先级参数低,使得调度资源被无关线程抢占,影响第二线程的执行,进而阻塞第一线程运行,降低系统执行效率。
请参阅图4,图4是本申请实施例提供的对唤醒行为进行记录的流程示意图,具体如下:
对线程进行识别,确定第一线程(识别关键线程);
判断第一线程是否调用函数(handler)向第二线程发送信息(message),如果是,则执行步骤123,如果否,则执行步骤129;
判断第二线程的运行是否超时,如果否,则执行步骤124,如果是,则执行步骤129;
在第二线程运行结束后,判断第二线程是否直接进行休眠模式,如果否,则执行步骤125,如果是,则执行步骤129;
判断第二线程是否通过函数(handler)向第一线程返回信息(message),如果是,则执行步骤126,如果否,则执行步骤129;
记录唤醒且返回的次数(行为次数或关系记录次数),得到线程对关系记录;
判断线程对关系记录中关系记录次数是否大于预设数量阈值,如果是,则执行步骤128,如果否,则执行步骤129;
记录第一线程与第二线程关系对(根据第一线程和第二线程的id建立关系对);
结束。
其中,第一线程唤醒第二线程且第二线程在预设时间阈值内又唤醒第一线程的行为表明第一线程与第二线程之间存在协同关系,例如,第一线程的执行可能依赖于第二线程的执行结果。
其中,在本申请实施例中,为提高优先级调整的准确性,在行为次数超过预设数量阈值后才进行优先级参数的调整,使得能够在满足预设数量阈值后,进行优先级参数的传递,调整第二线程的优先级,加快第二线程的开始执行时间。
其中,在本申请实施例中,可以将唤醒行为记录在调用关系管理列表中,在后续线程唤醒后,根据关系管理列表进行优先级参数的传递,例如,通过收集线程之间的异步调用特征,如异步调用行为记录模块记录高优先级线程异步唤醒了低优先级线程,同时低优先级线程经过一段时间后又异步唤醒了高优先级线程的行为,行为次数超过了预先设置好的次数时,则认为该异步调用需要传染线程优先级(高优先级线程的优先级参数传染到低优先级线程中),根据记录次数生成调用关系管理列表,应用重新启动运行且发生异步调用关系时,同时查询该调用关系管理列表,决定是否传递优先级参数。
例如,请参阅图5,图5是本申请实施例提供的优先级参数传递流程示意图,具体如下:
对线程进行识别,确定第一线程(识别关键线程);
判断第一线程是否唤醒第二线程,且第一线程处于等待状态,如果是,则执行步骤132,如果否,则执行步骤136;
判断第二线程是否在调用关系管理列表中,如果是,则执行步骤133,如果否,则执行步骤136;
传递目标优先级参数给第二线程(被唤醒线程),以使得第二线程能够根据优先级参数对应的优先级进行执行;
判断第二线程结束运行后是否通过函数(handler)返回信息(message),如果是,则执行步骤135,如果否,则执行步骤136;
恢复第二线程的优先级参数,将第二线程的优先级调整为系统配置的原始优先级(线程处理后优先级的恢复);
结束。
其中,通过对第二线程的优先级的调整,加快了第二线程的执行,并在第二线程执行完成后对优先级的恢复,使得第二线程能够按照默认的优先级顺序进行线程执行,保证系统的稳定性。
为便于更好的实施本申请的线程执行方法,本申请还提供一种基于上述线程执行方法的线程执行装置。其中第三目标词语的含义与上述线程执行方法中相同,具体实现细节可以参考方法实施例中的说明。
请参阅图6,图6为本申请提供的线程执行装置的结构示意图,其中,该线程执行装置可以包括:
确定模块201,用于当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级。
执行模块202,用于将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
其中,在本申请的一些实施例中,该装置还包括返回执行模块,返回执行模块包括:
返回单元,用于基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
执行单元,用于根据所述执行结果进行所述第一线程的执行。
其中,在本申请的一些实施例中,执行单元包括:
等待子单元,用于当所述第二线程根据所述目标优先级执行时,将所述第一线程设置为等待状态;
运行子单元,用于当所述第一线程接收到所述执行结果时,根据所述执行结果将所述第一线程调整为运行状态。
其中,在本申请的一些实施例中,确定模块201包括:
记录单元,用于记录所述第一线程唤醒所述第二线程、且所述第二线程在预设时间阈值内唤醒所述第一线程的次数,得到行为次数;
第一确定单元,用于当所述行为次数大于预设数量阈值后,根据所述第一线程的当前优先级确定目标优先级。
其中,在本申请的一些实施例中,目标优先级高于或等于所述第二线程在系统配置中的原始优先级。
其中,在本申请的一些实施例中,确定模块201包括:
第二确定单元,用于直接将所述当前优先级作为目标优先级。
其中,在本申请的一些实施例中,确定模块201包括:
获取单元,用于获取映射关系集合,所述映射关系集合包括预设当前优先级与预设目标优先级的映射关系;
第三确定单元,用于根据所述映射关系,确定所述第一线程的当前优先级对应的目标优先级。
本申请实施例由确定模块201在检测到第一线程唤醒第二线程时,根据第一线程的当前优先级确定目标优先级,然后,由执行模块202将目标优先级传递给第二线程,并根据目标优先级执行第二线程。
其中,本申请实施例在检测到第一线程唤醒第二线程时,根据第一线程的当前优先级确定目标优先级,并将目标优先级传递给第二线程,使得第二线程能够根据目标优先级进行执行,其中,通过对被唤醒通信的线程的优先级的调整,可在提升被唤醒的线程的优先级后,实现被唤醒线程的优先执行,提升执行效率。同时,当第一线程的执行依赖于第二线程的执行结果时,在实现第二线程的优先执行后,还可以提升第一线程的执行效率,避免第一线程长时间处理等待或者休眠状态,提升系统整体执行效率。
此外,本申请还提供一种电子设备,如图7所示,其示出了本申请所涉及的电子设备的结构示意图,具体来讲:
该电子设备可以包括一个或者一个以上处理核心的处理器401、一个或一个以上计算机可读存储介质的存储器402、电源403和输入单元404等部件。本领域技术人员可以理解,图7中示出的电子设备结构并不构成对电子设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。其中:
处理器401是该电子设备的控制中心,利用各种接口和线路连接整个电子设备的各个部分,通过运行或执行存储在存储器402内的软件程序和/或模块,以及调用存储在存储器402内的数据,执行电子设备的各种功能和处理数据。可选的,处理器401可包括一个或多个处理核心;优选的,处理器401可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器401中。
存储器402可用于存储软件程序以及模块,处理器401通过运行存储在存储器402的软件程序以及模块,从而执行各种功能应用以及数据处理。存储器402可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据电子设备的使用所创建的数据等。此外,存储器402可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。相应地,存储器402还可以包括存储器控制器,以提供处理器401对存储器402的访问。
电子设备还包括给各个部件供电的电源403,优选的,电源403可以通过电源管理系统与处理器401逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。电源403还可以包括一个或一个以上的直流或交流电源、再充电系统、电源故障检测电路、电源转换器或者逆变器、电源状态指示器等任意组件。
该电子设备还可包括输入单元404,该输入单元404可用于接收输入的数字或字符信息,以及产生与用户设置以及功能控制有关的键盘、鼠标、操作杆、光学或者轨迹球信号输入。
尽管未示出,电子设备还可以包括显示单元等,在此不再赘述。具体在本实施例中,电子设备中的处理器401会按照如下的指令,将一个或一个以上的应用程序的进程对应的可执行文件加载到存储器402中,并由处理器401来运行存储在存储器402中的应用程序,从而实现本申请所提供的任一种线程执行方法中的步骤。
本申请实施例在检测到第一线程唤醒第二线程时,根据第一线程的当前优先级确定目标优先级,并将目标优先级传递给第二线程,使得第二线程能够根据目标优先级进行执行,其中,通过对被唤醒通信的线程的优先级的调整,可在提升被唤醒的线程的优先级后,实现被唤醒线程的优先执行,提升执行效率。同时,当第一线程的执行依赖于第二线程的执行结果时,在实现第二线程的优先执行后,还可以提升第一线程的执行效率,避免第一线程长时间处理等待或者休眠状态,提升系统整体执行效率。
本领域普通技术人员可以理解,上述实施例的各种方法中的全部或部分步骤可以通过指令来完成,或通过指令控制相关的硬件来完成,该指令可以存储于一计算机可读存储介质中,并由处理器进行加载和执行。
为此,本申请提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序能够被处理器进行加载,以执行本申请所提供的任一种线程执行方法中的步骤。
其中,该计算机可读存储介质可以包括:只读存储器(ROM,Read Only Memory)、随机存取记忆体(RAM,Random Access Memory)、磁盘或光盘等。
由于该计算机可读存储介质中所存储的指令,可以执行本申请所提供的任一种图像处理中的步骤,因此,可以实现本申请所提供的任一种线程执行方法所能实现的有益效果,详见前面的实施例,在此不再赘述。
以上对本申请所提供的一种线程执行方法、装置、电子设备以及计算机可读存储介质进行了详细介绍,本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想;同时,对于本领域的技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。

Claims (20)

  1. 一种线程执行方法,其中,包括:
    当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级;
    将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
  2. 根据权利要求1所述的方法,其中,所述将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程之后,所述方法还包括:
    基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
    根据所述执行结果进行所述第一线程的执行。
  3. 根据权利要求2所述的方法,其中,所述根据所述执行结果进行所述第一线程的执行,包括:
    当所述第二线程根据所述目标优先级执行时,将所述第一线程设置为等待状态;
    当所述第一线程接收到所述执行结果时,根据所述执行结果将所述第一线程调整为运行状态。
  4. 根据权利要求1所述的方法,其中,所述根据所述第一线程的当前优先级,确定目标优先级,包括:
    记录所述第一线程唤醒所述第二线程、且所述第二线程在预设时间阈值内唤醒所述第一线程的次数,得到行为次数;
    当所述行为次数大于预设数量阈值后,根据所述第一线程的当前优先级确定目标优先级。
  5. 根据权利要求1所述的方法,其中,所述目标优先级高于或等于所述第二线程在系统配置中的原始优先级。
  6. 根据权利要求1所述的方法,其中,所述根据所述第一线程的当前优先级,确定目标优先级,包括:
    直接将所述当前优先级作为目标优先级。
  7. 根据权利要求1所述的方法,其中,所述根据所述第一线程的当前优先级,确定目标优先级,包括:
    获取映射关系集合,所述映射关系集合包括预设当前优先级与预设目标优先级的映射关系;
    根据所述映射关系,确定所述第一线程的当前优先级对应的目标优先级。
  8. 根据权利要求1所述的方法,其中,所述根据所述目标优先级执行所述第二线程之后,所述方法还包括:
    将第二线程的优先级由目标优先级调整为系统配置中的原始优先级。
  9. 一种线程执行装置,其中,包括:
    确定模块,用于当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级;
    执行模块,用于将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
  10. 根据权利要求9所述的装置,其中,所述装置还包括返回执行模块,返回执行模块包括:
    返回单元,用于基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
    执行单元,用于根据所述执行结果进行所述第一线程的执行。
  11. 根据权利要求10所述的装置,其中,所述执行单元包括:
    等待子单元,用于当所述第二线程根据所述目标优先级执行时,将所述第一线程设置为等待状态;
    运行子单元,用于当所述第一线程接收到所述执行结果时,根据所述执行结果将所述第一线程调整为运行状态。
  12. 根据权利要求9所述的装置,其中,所述确定模块包括:
    记录单元,用于记录所述第一线程唤醒所述第二线程、且所述第二线程在预设时间阈值内唤醒所述第一线程的次数,得到行为次数;
    第一确定单元,用于当所述行为次数大于预设数量阈值后,根据所述第一线程的当前优先级确定目标优先级。
  13. 根据权利要求9所述的装置,其中,所述第一确定单元具体用于:
    目标优先级高于或等于所述第二线程在系统配置中的原始优先级。
  14. 根据权利要求9所述的装置,其中,所述确定模块包括:
    第二确定单元,用于直接将所述当前优先级作为目标优先级。
  15. 根据权利要求9所述的装置,其中,所述确定模块包括:
    获取单元,用于获取映射关系集合,所述映射关系集合包括预设当前优先级与预设目标优先级的映射关系;
    第三确定单元,用于根据所述映射关系,确定所述第一线程的当前优先级对应的目标优先级。
  16. 根据权利要求9所述的装置,其中,执行模块还包括:
    调整单元,用于将第二线程的优先级由目标优先级调整为系统配置中的原始优先级。
  17. 一种电子设备,其中,所述电子设备包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,其中,所述处理器执行所述计算机程序时实现:
    当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级;
    将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
  18. 根据权利要求17所述的一种电子设备,其中,所述处理器执行所述计算机程序时还实现:
    基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
    根据所述执行结果进行所述第一线程的执行。
  19. 一种计算机可读存储介质,其中,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现:
    当检测到第一线程唤醒第二线程时,根据所述第一线程的当前优先级,确定目标优先级;
    将所述目标优先级传递给所述第二线程,并根据所述目标优先级执行所述第二线程。
  20. 根据权利要求19所述的一种计算机可读存储介质,其中,所述计算机程序被处理器执行时还实现:
    基于所述唤醒,将所述第二线程的执行结果返回给所述第一线程,其中,所述执行结果是所述第二线程根据所述目标优先级执行后得到的;
    根据所述执行结果进行所述第一线程的执行。
PCT/CN2023/077353 2022-04-07 2023-02-21 线程执行方法、装置、电子设备及计算机可读存储介质 WO2023193527A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210363999.0 2022-04-07
CN202210363999.0A CN116932194A (zh) 2022-04-07 2022-04-07 线程执行方法、装置、电子设备及计算机可读存储介质

Publications (1)

Publication Number Publication Date
WO2023193527A1 true WO2023193527A1 (zh) 2023-10-12

Family

ID=88243945

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/077353 WO2023193527A1 (zh) 2022-04-07 2023-02-21 线程执行方法、装置、电子设备及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN116932194A (zh)
WO (1) WO2023193527A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117271144B (zh) * 2023-11-22 2024-04-23 荣耀终端有限公司 一种线程的处理方法和电子设备

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1605988A (zh) * 2003-10-09 2005-04-13 国际商业机器公司 增强调度线程的优先级引导的系统、设备和方法
CN108509260A (zh) * 2018-01-31 2018-09-07 深圳市万普拉斯科技有限公司 线程识别处理方法、装置、计算机设备和存储介质
CN111767124A (zh) * 2020-06-03 2020-10-13 Oppo广东移动通信有限公司 请求响应方法、装置、存储介质和电子设备

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1605988A (zh) * 2003-10-09 2005-04-13 国际商业机器公司 增强调度线程的优先级引导的系统、设备和方法
CN108509260A (zh) * 2018-01-31 2018-09-07 深圳市万普拉斯科技有限公司 线程识别处理方法、装置、计算机设备和存储介质
CN111767124A (zh) * 2020-06-03 2020-10-13 Oppo广东移动通信有限公司 请求响应方法、装置、存储介质和电子设备

Also Published As

Publication number Publication date
CN116932194A (zh) 2023-10-24

Similar Documents

Publication Publication Date Title
TWI783355B (zh) 深度學習模型的分布式訓練方法以及裝置
US7137115B2 (en) Method for controlling multithreading
EP2893444B1 (en) Quota-based resource management
JP5960262B2 (ja) 接続型スタンバイのためのプロセスの一時停止及び/又は制限
JP5951771B2 (ja) 接続型スタンバイのためのプロセスの一時停止及び/又は制限
WO2017014913A1 (en) Systems and methods for scheduling tasks in a heterogeneous processor cluster architecture using cache demand monitoring
JP5809366B2 (ja) ポータブルコンピューティングデバイスにおいて要求をスケジューリングするための方法およびシステム
WO2021000758A1 (zh) 机器人资源任务周期管控方法及装置
US20120297216A1 (en) Dynamically selecting active polling or timed waits
WO2018018611A1 (zh) 一种任务处理方法以及网卡
WO2023193527A1 (zh) 线程执行方法、装置、电子设备及计算机可读存储介质
WO2024119988A1 (zh) 多cpu环境下的进程调度方法、装置、电子设备和介质
CN112306652A (zh) 带有上下文提示的功能的唤醒和调度
CN116578422B (zh) 资源分配方法和电子设备
CN117573355A (zh) 任务处理方法、装置、电子设备以及存储介质
WO2018206793A1 (en) Multicore processing system
WO2023151498A1 (zh) 一种消息执行处理方法、装置、电子设备和存储介质
WO2023165485A1 (zh) 调度方法及计算机系统
US10884477B2 (en) Coordinating accesses of shared resources by clients in a computing device
WO2023279829A1 (zh) 消息延迟检测方法、装置、电子设备及存储介质
CN114880042A (zh) 应用启动方法、装置、电子设备及计算机可读存储介质
CN112764837B (zh) 数据上报方法、装置、存储介质及终端
WO2020206703A1 (zh) 终端控制方法、装置、存储介质及电子设备
CN111143055A (zh) 虚拟云主机预分配方法、装置、可读存储介质与电子设备
CN117596184B (zh) 一种通信连接检测方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23784091

Country of ref document: EP

Kind code of ref document: A1