A thread management method and apparatus

By dynamically allocating threads based on load levels and task queue types through the operating system, the problems of thread abuse and thread explosion in applications are solved, thereby improving the operating efficiency of the operating system and applications.

CN113535251BActive Publication Date: 2026-06-12HUAWEI TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2020-04-13
Publication Date
2026-06-12

Smart Images

  • Figure CN113535251B_ABST
    Figure CN113535251B_ABST
Patent Text Reader

Abstract

The application discloses a thread management method and device. In the method, an application program can submit first information to an operating system through an API, and the first information is used for indicating at least one first task to be executed by the application program. Through the first information, the operating system allocates the at least one first task to be executed by the application program to a corresponding first task queue, and allocates a thread to the first task queue according to a current load level of the operating system and a type of the first task queue. Through the scheme disclosed in the embodiment of the application, the operating system can allocate threads required by the application program, and in the process of allocating the threads, the operating system considers the load level of the operating system, thereby avoiding the abuse of the threads by the application program, avoiding the burst of the number of threads, and enabling the operating system to run efficiently.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of operating system technology, specifically to a thread management method and apparatus. Background Technology

[0002] To meet the diverse needs of users for electronic devices, electronic devices are usually equipped with a variety of applications, and each application often performs multiple functions to meet user needs.

[0003] In this process, an application needs to execute the corresponding task to implement each function. To improve the efficiency of task execution, current electronic device operating systems typically enable concurrency capabilities. During application execution, an operating system with enabled concurrency capabilities allows the application to create threads to execute the tasks it needs, and these threads then perform the corresponding tasks.

[0004] However, during the research process of this application, the inventors discovered that when an application needs to perform many tasks, it often creates a large number of threads, resulting in the abuse of threads by the application and causing an explosion in the number of threads. This explosion in the number of threads often increases the load on the operating system and reduces the operating efficiency of the operating system. Summary of the Invention

[0005] To address the problem that existing thread management methods often result in applications creating a large number of threads, leading to an explosion in the number of threads, this application discloses a thread management method.

[0006] In a first aspect, embodiments of this application disclose a thread management method, including:

[0007] The operating system determines at least one piece of first information about the application, the first information being used to indicate a first task to be performed by the application;

[0008] The operating system assigns the at least one first task to a corresponding first task queue;

[0009] The operating system allocates threads to the first task queue based on its current load level and the type of the first task queue.

[0010] The solution disclosed in this application allows the operating system to allocate threads required by the application. Furthermore, the operating system considers its own load level during the thread allocation process, thereby avoiding the abuse of threads by the application, reducing the phenomenon of thread explosion, and enabling the operating system to run efficiently.

[0011] In one optional design, the operating system allocates threads to the first task queue based on its current load level and the type of the first task queue, including:

[0012] The operating system determines the priority of the first task queue;

[0013] The operating system determines the first target task queue for allocating threads based on the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool. The first thread pool includes idle threads created by the operating system based on its current load level.

[0014] The operating system allocates idle threads from the first thread pool to the first target task queue according to the type of the first target task queue.

[0015] Through the above steps, the operating system can allocate idle threads from the first thread pool to the first task queue according to its priority, thus eliminating the need to create threads temporarily for the first target task queue. Therefore, this approach improves the speed at which the operating system allocates threads to applications, thereby increasing the speed at which applications execute tasks through threads and providing a better user experience.

[0016] In one optional design, the operating system allocates idle threads from the first thread pool to the first target task queue according to the type of the first target task queue, including:

[0017] When the first target task queue includes a serial task queue, the operating system allocates an idle thread from the first thread pool to the serial task queue;

[0018] When the first target task queue includes a parallel task queue, the operating system allocates n idle threads from the first thread pool to the parallel task queue based on the number of tasks in the parallel task queue, where the maximum value of n is the number of tasks included in the parallel task queue.

[0019] Through the above steps, the operating system allocates an idle thread from the first thread pool to the serial task queue, so that this idle thread executes each task in the serial task queue sequentially, thereby reducing thread waste. Furthermore, the operating system can allocate n idle threads to the parallel task queue, thereby improving the processing efficiency of the parallel task queue.

[0020] An alternative design also includes:

[0021] After at least one task in the first target task queue is completed, the operating system will either reclaim the thread allocated to the first target task queue back to the first thread pool, or schedule the thread allocated to the target task queue to another task queue, or destroy the thread allocated to the first target task queue.

[0022] Through the above steps, the operating system can reclaim, schedule, and destroy threads that have completed tasks, thereby reducing thread waste and minimizing the phenomenon of thread number explosions.

[0023] An alternative design also includes:

[0024] When the operating system determines that the first task queue includes the second target task queue and the first thread pool does not include a thread for executing tasks in the second target task queue, the operating system creates and allocates a corresponding thread for the second target task queue, or the operating system supports the application in creating a corresponding thread for the second target task queue.

[0025] Wherein, the second target task queue is a first task queue with a higher priority than the first priority, and / or, the second target task queue includes target tasks.

[0026] Through the above steps, when the first thread pool does not include a thread for executing tasks in the second target task queue, in order to ensure the smooth execution of tasks in the second target task queue, the operating system can create and allocate a corresponding thread for the second target task queue, or support the application to create a corresponding thread for the second target task queue so that tasks in the second target task queue can be executed smoothly.

[0027] In one optional design, the operating system determines the priority of the first task queue by:

[0028] The operating system determines the priority of the first task queue based on the second information of the at least one first task submitted by the application.

[0029] And / or,

[0030] The operating system determines the priority of the first task queue based on the third information of the application. The third information includes at least one of the following: the application's running platform, whether the application is currently visible, whether the application's function is currently perceptible, and the application's application frequency.

[0031] And / or,

[0032] The operating system determines the priority of the first task queue based on the types of tasks included in the first task queue;

[0033] And / or,

[0034] The operating system determines the priority of the first task queue based on the waiting time of the first task queue.

[0035] Through the above steps, the operating system can determine the priority of the first task queue based on the second information of the at least one first task submitted by the application, the third information of the application, the type of task included in the first task queue, and / or the waiting time of the first task queue.

[0036] In one optional design, the operating system determines the priority of the first task queue based on third information from the application, including:

[0037] When the third information includes the running platform of the application, the operating system determines that the priority of the first task queue of the first application is higher than the priority of the first task queue of the second application, the running platform of the first application is the foreground, and the running platform of the second application is the background.

[0038] When the third information includes whether the application is currently visible, the operating system determines that the priority of the first task queue of the third application is higher than the priority of the first task queue of the fourth application, the third application is currently visible, and the second application is currently not visible;

[0039] When the third information includes whether the function of the application is currently perceptible, the operating system determines that the priority of the first task queue of the fifth application is higher than the priority of the first task queue of the sixth application, the function of the fifth application is currently perceptible, and the function of the sixth application is currently not perceptible.

[0040] When the third information includes the application frequency of the application, the operating system determines that the priority of the first task queue of the seventh application is higher than the priority of the first task queue of the eighth application, and the application frequency of the seventh application is higher than the application frequency of the eighth application.

[0041] An alternative design also includes:

[0042] The operating system identifies at least one first application whose application frequency exceeds a first threshold during a first time period.

[0043] The operating system determines the target thread in which the frequency of the first application application is higher than the second threshold during the first time period.

[0044] The operating system determines the number of target threads that it can support based on its current load level, and generates a corresponding number of target threads, which are located in the first thread pool.

[0045] Through the above steps, the operating system can generate threads in the first thread pool. Furthermore, the target threads generated by the operating system are those frequently used by the first application, which is a frequently used application within the electronic device. In this case, the threads generated by the operating system are frequently used threads, thus enabling the threads in the first thread pool to meet the needs of most scenarios.

[0046] In one alternative design, the load level of the operating system is determined by at least one of the following parameters: the idle ratio of the processor running the operating system, the number of currently created threads, the memory usage of the processor, and the read / write activity of the memory of the electronic device on which the operating system is installed.

[0047] An alternative design also includes:

[0048] The operating system will assign at least one second task to be executed to the corresponding second task queue;

[0049] The operating system determines the priority of the second task queue;

[0050] The operating system allocates idle threads from the second thread pool to the second task queue according to the priority of the second task queue. The idle threads in the second thread pool are created by the operating system according to its current load level.

[0051] Secondly, embodiments of this application disclose a thread management method, including:

[0052] When the application needs to perform the first task, it submits the first information to the operating system through the first application programming interface (API) corresponding to the first task. The first information is used to indicate the first task.

[0053] The application executes the first task through a thread allocated to the first task by the operating system.

[0054] Through the embodiments of this application, the user program does not need to create a thread for the first task. Instead, the operating system allocates the threads required by the application. That is, the operating system allocates the thread for the first task to the user program, thereby avoiding the abuse of threads by the application, reducing the phenomenon of thread number explosion, and enabling the operating system to run efficiently.

[0055] An alternative design also includes:

[0056] If the application fails to obtain the thread allocated by the operating system for the first task within a first time period after submitting the first information, the application transmits a first request to the operating system through the second API corresponding to the first task.

[0057] After obtaining the first feedback corresponding to the first request, the application generates a thread corresponding to the first task and executes the first task through the thread.

[0058] Through the above steps, if the application fails to obtain a thread allocated to the task by the operating system, it can call the second API. After determining that the application has called the second API, the operating system typically supports the application in generating a thread corresponding to the task, thereby preventing the application from waiting for an excessively long time.

[0059] An alternative design also includes:

[0060] The application submits second information about the first task to the operating system through a first API corresponding to the first task. The second information is used to indicate the priority of the first task.

[0061] Through the above steps, the operating system can obtain the second information of the first task submitted by the application, and determine the priority of the task queue in which the first task is located through the second information.

[0062] Thirdly, embodiments of this application disclose a thread management device, comprising:

[0063] Processor and Application Programming Interface (API);

[0064] The API is used to obtain at least one piece of first information from the application, the first information being used to indicate the first task to be performed by the application;

[0065] The processor is configured to assign the at least one first task to a corresponding first task queue, and to allocate threads to the first task queue according to the current load level of the processor's operating system and the type of the first task queue.

[0066] In one alternative design, the processor is specifically used to determine the priority of the first task queue;

[0067] Based on the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool, a first target task queue for allocating threads is determined. The first thread pool includes idle threads created according to the current load level of the operating system.

[0068] Based on the type of the first target task queue, allocate an idle thread from the first thread pool to the first target task queue.

[0069] In one alternative design, the processor is specifically configured to allocate an idle thread from the first thread pool to the serial task queue when the first target task queue includes a serial task queue.

[0070] When the first target task queue includes a parallel task queue, n idle threads from the first thread pool are allocated to the parallel task queue according to the number of tasks in the parallel task queue, where the maximum value of n is the number of tasks included in the parallel task queue.

[0071] In an optional design, the processor is further configured to, after at least one task in the first target task queue is completed, reclaim the thread allocated to the first target task queue to the first thread pool, or schedule the thread allocated to the target task queue to another task queue, or destroy the thread allocated to the first target task queue.

[0072] In an optional design, the processor is further configured to, when the first task queue includes a second target task queue and the first thread pool does not include a thread for executing tasks in the second target task queue, create and allocate a corresponding thread for the second target task queue, or support the application in creating a corresponding thread for the second target task queue.

[0073] Wherein, the second target task queue is a first task queue with a higher priority than the first priority, and / or, the second target task queue includes target tasks.

[0074] In one optional design, the processor is configured to determine the priority of the first task queue based on second information of the at least one first task submitted by the application.

[0075] And / or,

[0076] The processor is configured to determine the priority of the first task queue based on third information of the application, wherein the third information includes at least one of the following: the application's running platform, whether the application is currently visible, whether the application's functions are currently perceptible, and the application's application frequency;

[0077] And / or,

[0078] The processor is used to determine the priority of the first task queue based on the type of tasks included in the first task queue;

[0079] And / or,

[0080] The processor is used to determine the priority of the first task queue based on the waiting time of the first task queue.

[0081] In an optional design, when the third information includes the running platform of the application, the processor is used to determine that the priority of the first task queue of the first application is higher than the priority of the first task queue of the second application, wherein the running platform of the first application is the foreground and the running platform of the second application is the background.

[0082] When the third information includes whether the application is currently visible, the processor is used to determine that the priority of the first task queue of the third application is higher than the priority of the first task queue of the fourth application, the third application is currently visible, and the second application is currently not visible;

[0083] When the third information includes whether the function of the application is currently perceptible, the processor is used to determine that the priority of the first task queue of the fifth application is higher than the priority of the first task queue of the sixth application, the function of the fifth application is currently perceptible, and the function of the sixth application is currently not perceptible.

[0084] When the third information includes the application frequency of the application, the processor determines that the priority of the first task queue of the seventh application is higher than the priority of the first task queue of the eighth application, and the application frequency of the seventh application is higher than the application frequency of the eighth application.

[0085] In an alternative design, the processor is further configured to determine at least one first application whose application frequency is higher than a first threshold during a first time period.

[0086] Identify the target thread whose frequency of application of the first application exceeds the second threshold during the first time period;

[0087] Based on the current load level of the operating system, determine the number of target threads that can be supported, and generate a corresponding number of target threads, which are located in the first thread pool.

[0088] In one alternative design, the load level of the operating system is determined by at least one of the following parameters: the idle ratio of the processor running the operating system, the number of currently created threads, the memory usage of the processor, and the read / write activity of the memory of the electronic device on which the operating system is installed.

[0089] In an optional design, the processor is further configured to allocate at least one second task to be executed to a corresponding second task queue.

[0090] Determine the priority of the second task queue;

[0091] Based on the priority of the second task queue, idle threads included in the second thread pool are allocated to the second task queue. The idle threads included in the second thread pool are created by the operating system based on its current load level.

[0092] Fourthly, embodiments of this application disclose a thread management device, comprising:

[0093] Processor and first application programming interface (API);

[0094] When the application needs to perform the first task, the first API corresponding to the first task is used to submit first information to the operating system, and the first information is used to indicate the first task.

[0095] The processor is used to execute the first task through the thread allocated to the first task by the operating system.

[0096] An alternative design also includes:

[0097] Second API;

[0098] If no thread is allocated by the operating system for the first task within a first time period after the first information is submitted, the second API corresponding to the first task is used to transmit a first request to the operating system.

[0099] The processor is further configured to, after obtaining the first feedback corresponding to the first request, generate a thread corresponding to the first task, and execute the first task through the thread.

[0100] In an optional design, the processor is further configured to submit second information of the first task to the operating system via a first API corresponding to the first task, wherein the second information is used to indicate the priority of the first task.

[0101] Fifthly, embodiments of this application disclose a terminal device, comprising:

[0102] At least one processor and memory,

[0103] The memory is used to store program instructions;

[0104] The processor is configured to call and execute program instructions stored in the memory to cause the terminal device to execute the thread management method described in any of the first aspects.

[0105] Sixthly, embodiments of this application disclose a terminal device, comprising:

[0106] At least one processor and memory,

[0107] The memory is used to store program instructions;

[0108] The processor is configured to call and execute program instructions stored in the memory to cause the terminal device to perform the thread management method described in any of the second aspects.

[0109] In a seventh aspect, embodiments of this application disclose a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the thread management method as described in any of the first aspects.

[0110] Eighthly, embodiments of this application disclose a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the thread management method as described in any of the second aspects.

[0111] Ninthly, embodiments of this application disclose a computer program product containing instructions that, when the computer program product is run on an electronic device, enable the electronic device to perform all or part of the steps in the embodiments corresponding to the first aspect.

[0112] In a tenth aspect, embodiments of this application disclose a computer program product containing instructions that, when the computer program product is run on an electronic device, enable the electronic device to perform all or part of the steps in the embodiments corresponding to the second aspect.

[0113] In the thread management method disclosed in this application, the application can submit first information to the operating system via an API. This first information indicates at least one first task to be executed by the application. Based on this first information, the operating system allocates the at least one first task to be executed by the application to a corresponding first task queue, and allocates threads to the first task queue according to its current load level and the type of the first task queue.

[0114] The solution disclosed in this application allows the operating system to allocate the threads required by the application. Furthermore, the operating system considers its own load level during the thread allocation process, thereby preventing the application from abusing threads and avoiding a surge in the number of threads, thus enabling the operating system to run efficiently.

[0115] Furthermore, in the scheme disclosed in this application embodiment, the operating system can create a first thread pool based on its own load level. The first thread pool includes idle threads created by the operating system based on its current load level. When allocating threads to the first task queue, the operating system allocates idle threads from the first thread pool to the first task queue, thereby improving the speed at which the first task queue obtains the required threads and improving the efficiency of the application in executing tasks. Attached Figure Description

[0116] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0117] Figure 1 This is an example diagram of the software structure block diagram of an electronic device disclosed in an embodiment of this application;

[0118] Figure 2 This is a schematic diagram illustrating the workflow of a thread management method disclosed in an embodiment of this application;

[0119] Figure 3 This is a schematic diagram of data interaction in a thread management method disclosed in an embodiment of this application;

[0120] Figure 4 This is a schematic diagram illustrating the workflow of another thread management method disclosed in an embodiment of this application;

[0121] Figure 5 This is a schematic diagram illustrating a scenario of a thread management method disclosed in an embodiment of this application;

[0122] Figure 6This is a schematic diagram illustrating another thread management method disclosed in an embodiment of this application.

[0123] Figure 7 This is a schematic diagram illustrating another thread management method disclosed in an embodiment of this application.

[0124] Figure 8 This is a schematic diagram illustrating the workflow of another thread management method disclosed in an embodiment of this application;

[0125] Figure 9 This is a schematic diagram of the structure of a thread management device disclosed in an embodiment of this application;

[0126] Figure 10 This is a schematic diagram of the structure of another thread management device disclosed in an embodiment of this application;

[0127] Figure 11 This is a schematic diagram of the structure of a terminal device disclosed in an embodiment of this application. Detailed Implementation

[0128] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0129] In the description of the embodiments of this application, unless otherwise stated, " / " means "or", for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more.

[0130] Hereinafter, the terms "first" and "second" are used for descriptive purposes only. In the description of the embodiments of this application, unless otherwise stated, "a plurality of" means two or more.

[0131] The thread management method disclosed in this application can be applied to various electronic devices. In some embodiments, the electronic device may be a mobile phone, tablet computer, desktop computer, laptop computer, notebook computer, ultra-mobile personal computer (UMPC), handheld computer, netbook, personal digital assistant (PDA), wearable electronic device, and smartwatch, etc. Various applications can run on this electronic device, including pre-installed applications and applications installed by the user according to their needs. For example, when a user needs to send and receive emails, they can install email-related applications on the electronic device through app stores or other means.

[0132] in, Figure 1 This is an example diagram of the software structure block diagram of an electronic device according to an embodiment of this application.

[0133] In this layered architecture, the software of an electronic device is divided into several layers, each with a clear role and function. Layers interact with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the framework layer, the system library layer, and the kernel layer. The framework layer, system library layer, and kernel layer together constitute the operating system of the electronic device.

[0134] The application layer can include a series of applications, which may include applications that are pre-installed on the electronic device at the factory, as well as applications that are installed by the user during use of the electronic device. For example... Figure 1 As shown, the application layer can accommodate applications such as camera, gallery, calendar, call, map, navigation, Bluetooth, music, video, and SMS, and also includes applications that users install on their electronic devices according to their own usage needs, such as... Figure 1 The first application and the second application are included. The first application and the second application can be data interaction applications, shopping applications, music playback applications, and game applications, etc., and this application embodiment does not limit them.

[0135] Applications at the application layer often perform multiple tasks. For example, music playback applications can not only play music selected by the user, but also collect user preferences, recommend relevant music based on those preferences, and display music recommended by the user's friends.

[0136] In addition, the application includes an application programming interface (API) and can interact with the operating system via the API.

[0137] The framework layer provides APIs and programming frameworks, through which the operating system can interact with applications in the application layer. The framework layer includes some predefined functions.

[0138] like Figure 1As shown, the framework layer may include a display policy service, a power manager service (PMS), and a display manager service (DMS). Of course, the framework layer may also include an activity manager, a window manager, a content provider, a view system, a phone manager, a resource manager, and a notification manager, etc., and this embodiment of the application does not impose any limitations on this.

[0139] The system library typically includes 2D / 3D graphics processing libraries, surface managers, and media libraries, while the kernel layer provides drivers, which may include display drivers, camera drivers, audio drivers, and sensor drivers.

[0140] It should be noted that although the embodiments of this application are described using the Android system as an example, the basic principles are also applicable to electronic devices based on operating systems such as iOS or Windows.

[0141] An application often performs multiple tasks. To improve the efficiency of task execution, the operating system of electronic devices often enables concurrency capabilities. Operating systems with enabled concurrency capabilities allow applications to create multiple threads simultaneously, and each thread executes its corresponding task, thereby improving the application's task execution efficiency.

[0142] In existing technologies, applications can create corresponding threads based on the tasks they need to execute. Typically, each application has a separate thread interface for each task. When an application needs to execute a task, it calls the corresponding thread interface. An operating system that supports concurrency determines that the application has called the thread interface and then allows the application to create a thread to execute that task. In other words, in existing technologies, the number of threads created by an application is determined by the tasks the application needs to execute; the operating system does not control the number of threads created by the application.

[0143] In this scenario, under current technology, when an application needs to perform many tasks, it often creates a large number of threads, resulting in an explosion in the number of threads. This explosion in the number of threads often increases the load on the operating system and reduces its operating efficiency.

[0144] The implementation of this embodiment will now be described in detail with reference to the accompanying drawings.

[0145] To address the problem that existing thread management methods often result in applications creating a large number of threads, leading to an explosion in the number of threads, this application discloses a thread management method.

[0146] See Figure 2The flowchart shown in this application illustrates the thread management method disclosed in this embodiment, which includes the following steps:

[0147] Step S11: The operating system determines at least one piece of first information for the application, the first information being used to indicate the first task to be performed by the application.

[0148] See Figure 1 The schematic diagram illustrates that the application includes an API, which can interact with the operating system. In this embodiment, the application has a first API for submitting first information to the operating system, and can submit first information to the operating system through the first API. Furthermore, the first API of the application typically has a one-to-one correspondence with the tasks of the application; that is, one first API of the application is typically used to submit the first information of one of the tasks to the operating system. When the application needs to execute multiple first tasks, the application can configure multiple first APIs and submit the first information of the first task to the operating system through the first API corresponding to each first task.

[0149] In this case, after obtaining the first information, the operating system can determine at least one first task to be executed by the application based on the first information.

[0150] Step S12: The operating system assigns the at least one first task to the corresponding first task queue.

[0151] In this embodiment of the application, the operating system can pre-generate multiple types of first task queues and assign the first task to the corresponding first task queue.

[0152] For example, the first task queue can be categorized based on the time dependency between tasks. In this case, the first task queue may include a serial task queue and a parallel task queue. Accordingly, when allocating the first task, the operating system can determine the first task queue corresponding to the first task based on whether there is a time dependency between the first tasks.

[0153] For example, when there is a strong time dependency between task A and task B, meaning task B can only be executed after task A is completed, the operating system will allocate A and task B to the serial task queue. Conversely, when there is no time dependency between task A and task B, meaning task A and task B can be executed simultaneously, or one task can be executed after the other, the operating system will allocate A and task B to the parallel task queue.

[0154] Alternatively, the operating system can also classify the type of the first task queue based on the parameter of the task content. Accordingly, after determining the first task, the operating system can allocate the first task to the corresponding task queue according to the content of the first task.

[0155] For example, some applications need to update their user interface (UI). In this case, the application needs to perform a UI update task. The operating system pre-creates a first task queue corresponding to the UI update task. After determining, based on the first information, that the first task to be performed by the application includes a UI update task, the operating system can assign the UI update task to the first task queue corresponding to that UI update task.

[0156] Of course, the operating system can also generate other types of first task queues, and correspondingly, the operating system can also allocate the at least one first task to other types of first task queues. Furthermore, the operating system can simultaneously use two or more partitioning parameters to divide the types of first task queues. For example, the operating system can simultaneously divide the first task queues based on both the existence of time dependencies between tasks and the content of the tasks. In this case, the operating system can simultaneously generate a serial task queue, a parallel task queue, and a queue corresponding to the task content. After determining at least one first task, the operating system prioritizes allocating that first task to the queue corresponding to the task content, and then allocates the remaining first tasks to the serial task queue and the parallel task queue.

[0157] Step S13: The operating system allocates threads to the first task queue according to its current load level and the type of the first task queue.

[0158] The type of the first task queue typically includes a serial task queue and a parallel task queue, and / or the type of the first task queue is determined according to the content of the tasks included in the first task queue. For example, when the first task queue includes a task for UI update, the type of the first task queue is a UI update task queue.

[0159] The operating system allocates threads to the first task queue based on its current load level, meaning the operating system manages the threads required by the application. Furthermore, the operating system considers its own load level when allocating threads; therefore, it typically allocates an appropriate number of threads to the first task queue while ensuring its own smooth operation, thereby avoiding an explosion in the number of threads and ensuring the smooth operation of the operating system.

[0160] In this embodiment of the application, the load level of the operating system can be determined by at least one of the following parameters: the idle ratio of the processor running the operating system, the number of currently created threads, the memory usage of the processor, and the read / write status of the memory of the electronic device on which the operating system is installed.

[0161] Specifically, the idle ratio of the processor running the operating system indicates that when the processor is idle, the operating system can typically allocate more threads to the first task queue. Conversely, when the idle ratio indicates that the processor is busy, the operating system can typically allocate fewer threads to the first task queue or temporarily allocate no threads. More specifically, the processor's idle ratio can be divided into multiple levels, and a correspondence between different levels and the number of threads that the operating system can allocate can be configured. The operating system can then allocate corresponding threads to the first task queue according to this correspondence.

[0162] Additionally, a large number of threads already created by the operating system typically indicates a high operating system load. In such cases, to avoid an explosion in the number of threads, the operating system usually allocates fewer threads to the first task queue.

[0163] During operation, the operating system often consumes processor memory. A higher memory usage rate typically indicates a higher current load on the operating system. In such cases, to ensure smooth operation, the operating system can usually allocate fewer threads to the first task queue when the memory usage rate is high.

[0164] Furthermore, during operation, the operating system often needs to write data to and read data from the electronic device's memory. The more frequently the memory is read and written, the higher the current load on the operating system. In this case, to ensure smooth operation of the operating system, when memory reads and writes are frequent, the operating system can typically allocate fewer threads to the first task queue.

[0165] Of course, the load level of the operating system can also be determined by other parameters, but this application embodiment does not limit this.

[0166] After the operating system allocates a thread to the first task queue, the thread can execute the tasks in the first task queue to meet the application's task execution requirements, thereby realizing the functions required by the application.

[0167] In the thread management method disclosed in this application, the application can submit first information to the operating system via an API. This first information indicates at least one first task to be executed by the application. Based on this first information, the operating system determines the at least one first task to be executed by the application, assigns the at least one first task to a corresponding first task queue, and allocates threads to the first task queue according to its current load level and the type of the first task queue.

[0168] In other words, the solution disclosed in the embodiments of this application enables the operating system to allocate the threads required by the application. Furthermore, the operating system will consider its own load level during the thread allocation process, thereby avoiding the abuse of threads by the application, reducing the phenomenon of thread number explosion, and enabling the operating system to run efficiently.

[0169] To clarify the solutions disclosed in the embodiments of this application, the disclosure... Figure 3 , Figure 3 This is a schematic diagram illustrating the data interaction between the application and the operating system in the scheme disclosed in the embodiments of this application.

[0170] In this embodiment, the operating system needs to determine the first information of the application in order to manage the threads required by the application based on the first information. In this case, the application has at least one first API, and each first API can be used to submit the first information of the task corresponding to the first API to the operating system. That is, when the application needs to execute task A, the application can submit the first information of task A to the operating system through the first API corresponding to task A, so that the operating system can allocate task A to the corresponding first task queue.

[0171] See Figure 3 The operating system typically sets up a third API, through which the operating system can obtain the first information submitted by the application, and determine at least one first task to be executed by the application based on the first information, and assign the at least one first task to the corresponding first task queue.

[0172] In existing technologies, when an application needs to perform a task, it often creates the necessary threads. In this case, the application sets up corresponding second APIs for each task. When the application needs to perform a specific task, it calls the second API corresponding to that task. After determining that the application has called the second API, the operating system supports the application in generating the corresponding threads, thereby enabling the application to generate the appropriate threads for the tasks it needs to perform.

[0173] Compared with the prior art, in the solution disclosed in the embodiments of this application, the second API corresponding to a certain task in the application can be updated to the first API corresponding to the task, so that the operating system can control the thread required by the task, that is, the operating system can allocate a thread for the task.

[0174] Furthermore, applications often perform multiple tasks, and in some scenarios, applications may wish to create threads for some of these tasks themselves. For example, for confidentiality reasons, an application may not want to submit the initial information for some tasks to the operating system; in such cases, the application can create threads for those tasks itself. In this situation, the application can retain the second API corresponding to these tasks and not update it to the first API.

[0175] For example, an application may execute tasks A, B, C, D, and E, where the application wishes to create threads for tasks D and E itself. In this case, see [reference needed]. Figure 3 The application can retain the second APIs corresponding to tasks D and E respectively, and update the second APIs corresponding to tasks A, B, and C to the first APIs respectively. When the application needs to execute task D, it can call the second API corresponding to task D and, with the support of the operating system, create a thread corresponding to task D. When the application needs to execute task A, it can submit the first information of task A to the operating system through the first API corresponding to task A. After obtaining the first information of task A, the operating system can allocate a corresponding thread for task A according to its own load level.

[0176] This approach allows the operating system to manage some of the threads required by the application while ensuring application confidentiality, thereby reducing the number of threads generated by the application and lowering the possibility of thread overload.

[0177] In this application embodiment, an operation is disclosed in which the operating system allocates threads to the first task queue based on its current load level and the type of the first task queue. This operation can be implemented in various ways.

[0178] In one feasible approach, after assigning the first task to the corresponding first task queue, the operating system determines, based on its current load level, whether it can generate a corresponding thread for the first task. When the operating system determines that its current load level supports creating a thread for the first task, the operating system then creates the corresponding thread for the first task and assigns the thread to the first task queue.

[0179] In this way, the operating system can create threads for the application whenever the application needs them and its own load level supports it, thereby avoiding an explosion in the number of threads.

[0180] In another feasible approach, see Figure 4 The operating system allocates threads to the first task queue based on its current load level and the type of the first task queue, including the following steps:

[0181] Step S131: The operating system determines the priority of the first task queue.

[0182] In this embodiment, the operating system can determine the order of thread allocation based on the priority of the first task queue. In this case, the operating system typically prioritizes allocating threads to the first task queue, which has a higher priority.

[0183] In addition, the operating system can determine the priority of the first task queue in a variety of ways, such as based on relevant information of the application or the type of tasks included in the first task queue.

[0184] Step S132: The operating system determines the first target task queue for allocating threads based on the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool. The first thread pool includes idle threads created by the operating system based on its current load level.

[0185] In this embodiment, the operating system can pre-create at least one idle thread based on its current load level, and the at least one idle thread is located in a first thread pool. Here, the idle thread refers to a thread that is not executing any tasks.

[0186] Furthermore, different threads can be used to execute different types of tasks. In this case, the operating system can determine the first target task queue for which threads can be allocated based on the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool.

[0187] For example, when the idle threads in the first thread pool include a first thread, a second thread, and a third thread, and the first thread can be used to execute tasks in the first task queue A and the first task queue B, the second thread and the third thread are used to execute tasks in the first task queue C, and the priority of the first task queue A is higher than the priority of the first task queue B, then the first task queue A can be determined as the first target task queue.

[0188] Step S133: The operating system allocates idle threads from the first thread pool to the first target task queue according to the type of the first target task queue.

[0189] The type of the first target task queue typically includes a serial task queue and / or a parallel task queue. Alternatively, the type of the first target task queue can be determined by the task content included in the first target task queue. For example, if the task content included in the first target task queue is a UI update task, then the type of the first target task queue is a UI update task type. Of course, the first target task queue may also include other types of task queues, and this application embodiment does not limit this.

[0190] To clarify the method for allocating threads to the first task queue in this application's embodiments, an example is disclosed. See also... Figure 5 The illustrated scenario shows an electronic device with application A and application B installed, and the operating system of the electronic device manages the threads required by application A and application B.

[0191] The first tasks to be executed by application A include tasks 1, 2, 3...10, and application A submits first information for each of these first tasks to the operating system. The first tasks to be executed by application B include a UI update task, and application B submits first information for this UI update task to the operating system.

[0192] After receiving the first information submitted by applications A and B, the operating system can allocate the first tasks of applications A and B to corresponding first task queues based on the first information. In this example, the operating system allocates the first task of application A to a serial task queue and a parallel task queue. The serial task queue includes tasks 1, 2, 3...6 of application A, and the parallel task queue includes tasks 7, 8, 9, and 10 of application B. Additionally, the operating system allocates the first task of application B to the UI update task queue.

[0193] The operating system creates a first thread pool, which includes idle threads created by the operating system based on its own load level. When the operating system determines the serial task queue and parallel task queue corresponding to application A, and the UI update task queue corresponding to application B, as the first target task queues based on the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool, the operating system can allocate threads to the serial task queue and parallel task queue corresponding to application A, and the UI update task queue corresponding to application B, thereby enabling application A and application B to execute corresponding tasks according to the threads allocated by the operating system.

[0194] In the scheme disclosed in steps S131 to S133, the operating system pre-generates a first thread pool including idle threads based on its own load level. When a thread needs to be allocated to the first target task queue, the operating system allocates the pre-created idle thread from the first thread pool to the first target task queue, thus eliminating the need to temporarily create threads for the first target task queue. Therefore, this scheme can improve the speed at which the operating system allocates threads to applications, and correspondingly improve the speed at which applications execute tasks through threads, providing a better user experience.

[0195] When the type of the first target task queue typically includes a serial task queue and / or a parallel task queue, in this embodiment of the application, the following method is typically used to allocate idle threads from the first thread pool to the first target task queue:

[0196] When the first target task queue includes a serial task queue, the operating system allocates an idle thread from the first thread pool to the serial task queue;

[0197] When the first target task queue includes a parallel task queue, the operating system allocates n idle threads from the first thread pool to the parallel task queue based on the number of tasks in the parallel task queue, where the maximum value of n is the number of tasks included in the parallel task queue.

[0198] The tasks in the serial task queue have strong time dependencies and typically need to be executed sequentially, meaning one task must be completed before the next can begin. If a large number of threads are allocated to this serial task queue, other threads will be idle while one is working, resulting in wasted threads. Therefore, in this embodiment, an idle thread from a first thread pool is allocated to the serial task queue so that this idle thread can execute the tasks in the queue sequentially, thereby reducing thread waste.

[0199] Furthermore, the tasks in the parallel task queue do not have strong time dependencies; tasks can be executed simultaneously, or one task can be completed before another begins. In this case, the operating system can allocate threads to the parallel task queue based on the number of tasks in the queue, and the operating system can allocate a maximum of n idle threads to the parallel task queue, where n is the number of tasks in the queue, to avoid thread waste.

[0200] For example, when there are many idle threads in the first thread pool that can execute tasks in the parallel task queue, and the number of tasks in the parallel task queue is large, the operating system can allocate more threads to the parallel task queue to improve task execution efficiency; when there are few idle threads in the first thread pool that can execute tasks in the parallel task queue, and the number of tasks in the parallel task queue is small, the operating system can allocate fewer threads to the parallel task queue to avoid an explosion in the number of threads.

[0201] In the thread management method disclosed in this application embodiment, the operating system manages the threads required by the application and allocates corresponding threads to the application. Furthermore, this application embodiment may also include the following operations:

[0202] After at least one task in the first target task queue is completed, the operating system will either reclaim the thread allocated to the first target task queue back to the first thread pool, or schedule the thread allocated to the target task queue to another task queue, or destroy the thread allocated to the first target task queue.

[0203] If a task in the first target task queue is completed, the thread previously allocated to that queue enters an idle state. To avoid wasting this thread, the operating system can reclaim it to the first thread pool. After being reclaimed to the first thread pool, the thread can be allocated to other task queues and continue executing tasks in those queues, thereby reducing thread waste.

[0204] Alternatively, after the tasks in the first target task queue are completed, if the thread allocated to the first target task queue can still execute tasks in other task queues, the operating system can allocate the thread to the other task queue so that the thread can execute tasks in the other task queue, thereby avoiding the thread being wasted and also improving the execution efficiency of tasks in other task queues.

[0205] Additionally, if the other task queues include a serial task queue, and a thread has already been assigned to the serial task queue, the operating system will not assign the thread to the serial task queue.

[0206] Alternatively, after the tasks in the first target task queue are completed, the operating system may also destroy the threads allocated to the first target task queue to reduce the number of threads and further avoid the phenomenon of thread number explosion.

[0207] In existing technologies, threads created by applications often continue to exist even after the application no longer needs them, leading to a waste of thread resources.

[0208] In the solution of this application embodiment, the operating system can reclaim, schedule and destroy threads that have completed tasks, thereby reducing thread waste and reducing the phenomenon of thread number explosion.

[0209] To clarify the control that the operating system can exercise over threads in the embodiments of this application, this application discloses an example. See also Figure 6 The illustrated scenario shows that, in this example, application tasks are assigned to two first task queues, namely a first parallel task queue and a second parallel task queue. The first parallel task queue includes tasks 1, 2, 3, ..., 6, etc., and the second parallel task queue includes tasks 7, 8, and 9, etc., and the operating system allocates corresponding threads to these two first task queues respectively.

[0210] As tasks in the second parallel task queue are gradually completed, the number of tasks in the second parallel task queue decreases. When the second parallel task queue contains three tasks to be executed, and the operating system previously allocated four threads to the second parallel task queue, in order to avoid thread waste, the operating system can reclaim one of the threads, and let the remaining three threads execute the three tasks to be executed respectively, thereby reducing thread waste.

[0211] Furthermore, as threads are recycled, the number of idle threads in the first thread pool increases, while the first parallel task queue contains a large number of tasks to be executed. When an idle thread added to the first thread pool is available to execute a task in the first parallel task queue, the operating system can schedule that thread to the first parallel task queue. That is, the number of threads allocated to the first parallel task queue by the operating system increases, thereby improving the execution efficiency of tasks in the first parallel task queue.

[0212] In one feasible solution of this application embodiment, the operating system pre-creates a first thread pool according to its own load level. After determining the first target task queue, the operating system can determine the thread in the first thread pool used to execute the task in the first target task queue and allocate the thread to the first target task queue.

[0213] However, applications often perform multiple tasks. In some cases, an application needs to perform a specific task, but the first thread pool created by the operating system does not include a thread for that task. In this situation, this application discloses another embodiment. This embodiment further includes the following steps:

[0214] When the operating system determines that the first task queue includes a second target task queue and the first thread pool does not include a thread for executing tasks in the second target task queue, the operating system creates and allocates a corresponding thread for the second target task queue, or the operating system supports the application in creating a corresponding thread for the second target task queue.

[0215] Wherein, the second target task queue is a first task queue with a higher priority than the first priority, and / or, the second target task queue includes target tasks.

[0216] In this embodiment, a first priority can be set according to user needs. When the priority of a task queue is higher than the first priority, it indicates that the tasks in that task queue are more important. Additionally, the operating system can set at least one target task based on the importance placed on each task; the target task is typically a task of greater concern. If the priority of the second target task queue is higher than the first priority, or if the second target task queue includes the target task, then the second target task queue is a more important task queue.

[0217] In this case, when the first thread pool does not include a thread for executing tasks in the second target task queue, in order to ensure the smooth execution of tasks in the second target task queue, the operating system may create and allocate a corresponding thread for the second target task queue, or the application may be supported in creating a corresponding thread for the second target task queue so that tasks in the second target task queue can be executed smoothly.

[0218] Through the above steps, the operating system can create and allocate the corresponding thread for a task queue when the first thread pool does not include the thread for a certain important task queue, so as to ensure that the tasks in the task queue are executed smoothly.

[0219] In the above embodiments, schemes for determining the first target task queue and the second target task queue based on the priority of the first task queue are disclosed. In the embodiments of this application, the priority of the first task queue can be determined in a variety of ways.

[0220] In one feasible implementation, the operating system determines the priority of the first task queue by:

[0221] The operating system determines the priority of the first task queue based on the second information of the at least one first task submitted by the application.

[0222] In this implementation, the application submits second information about a first task to the operating system. This second information indicates the priority of the first task. Then, the operating system determines the priority of the first task based on the second information, and further determines the priority of a first task queue that includes the first task based on the priority of the first task. In other words, in this implementation, the operating system determines the priority of the first task queue based on the information submitted by the application.

[0223] For example, the operating system may determine that the priority of the first task queue is the same as the priority of the first task. Alternatively, when the first task queue includes multiple first tasks, the operating system may determine that the average priority of the multiple first tasks is the priority of the first task queue.

[0224] Furthermore, in this implementation, the application can submit the second information of the first task to the operating system through the first API corresponding to the first task. Moreover, the first and second information of the first task can be loaded into the same message; by submitting this message, the operating system can simultaneously obtain both the first and second information of the first task. Alternatively, the first and second information of the first task can also be two separate messages; this embodiment does not limit this approach.

[0225] Alternatively, in another feasible implementation, the operating system determines the priority of the first task queue based on third information from the application.

[0226] The third piece of information includes at least one of the following: the application's operating platform, whether the application is currently visible, whether the application's functions are currently perceptible, and the application's usage frequency.

[0227] The application's runtime platform typically includes a foreground and a background. Applications running in the foreground are usually those that users are more interested in, and consequently, their task queues have a higher priority. Therefore, when the third information includes the application's runtime platform, the operating system determines that the first application's first task queue has a higher priority than the second application's first task queue, with the first application running in the foreground and the second application running in the background.

[0228] Whether an application is currently visible refers to whether its interface and / or information are visible. Specifically, if an application is running in the foreground and the user can see its interface, then the application is currently visible. Additionally, some applications, even when running in the background, will display a thumbnail of a new message in the notification bar; in this case, the application is generally considered currently visible. For example, if the application is a messaging app running in the background, to prevent the user from missing messages sent by other users, a thumbnail of the message may be displayed in the notification bar of the electronic device, depending on the user's settings; in this case, the messaging app is a currently visible application.

[0229] If an application is currently visible, it indicates that the user is paying more attention to that application. Accordingly, when the third information includes whether the application is currently visible, the operating system determines that the priority of the first task queue of the third application is higher than the priority of the first task queue of the fourth application, the third application is currently visible, and the second application is currently not visible.

[0230] Additionally, the third piece of information may include whether the application's functionality is currently perceptible. The application often includes multiple functions, some of which are perceptible to the user. For example, when the application is an audio playback application, the user can hear the audio while it is playing, so the application's functionality is currently perceptible; or, when the application is a navigation application, the user can hear the navigation instructions issued by the application, so the application's functionality is currently perceptible.

[0231] If the functionality of a certain application is currently perceptible, it indicates that the user is paying more attention to the application. Accordingly, when the third information includes whether the functionality of the application is currently perceptible, the operating system determines that the priority of the first task queue of the fifth application is higher than the priority of the first task queue of the sixth application, the functionality of the fifth application is currently perceptible, and the functionality of the sixth application is currently not perceptible.

[0232] In addition, the operating system can also determine the priority of the application's task queue based on the application's usage frequency. In this case, the operating system can also count the usage frequency of each application. Accordingly, when the third information includes the application's usage frequency, the operating system determines that the priority of the first task queue of the seventh application is higher than the priority of the first task queue of the eighth application, and the application frequency of the seventh application is higher than that of the eighth application. That is, the application with a higher usage frequency has a higher priority in its task queue.

[0233] The above scheme describes a method for determining the priority of the first task queue when the third information includes the application's operating platform, whether the application is currently visible, whether the application's function is currently perceptible, and the application's application frequency. Alternatively, the priority of the application's first task queue can be determined by combining two or more of the above-mentioned third information.

[0234] For example, when the third information includes the application's running platform and the application's application frequency, the operating system typically determines that the first task queue of the application with a higher application frequency has the highest priority when the running platform is in the foreground, and the first task queue of the application with a lower application frequency has the lowest priority when the running platform is in the background.

[0235] Alternatively, when combining two or more third pieces of information to jointly determine the priority of the first task queue of the application, different confidence levels can be set for different third pieces of information. In this case, the operating system determines the priority of the first task queue based on the confidence level.

[0236] In another feasible implementation, the operating system determines the priority of the first task queue by: the operating system determining the priority of the first task queue based on the types of tasks included in the first task queue.

[0237] In this implementation, the operating system establishes a correspondence between the types of each task and their priorities. Based on this correspondence and the type of the first task, the operating system determines the priority of the first task, and then determines the priority of a first task queue including the first task based on the priority of the first task. In other words, in this implementation, the operating system determines the priority of the first task queue including the first task based on the priority of the first task.

[0238] For example, in this implementation, the priority of a UI update task for a certain application can be set to the highest priority. When the operating system determines that the first task to be executed by the application includes a UI update task, the priority of the UI update task can be determined according to this correspondence, and then the priority of the task queue including the UI update task can be determined according to the priority of the UI update task.

[0239] Alternatively, in another feasible implementation, the operating system determines the priority of the first task queue by: the operating system determining the priority of the first task queue based on the waiting time of the first task queue.

[0240] In this embodiment, to avoid an explosion in the number of threads, the operating system may prioritize allocating threads to a portion of the first task queue. When the operating system's load level is insufficient to support allocating threads to all first task queues, some first task queues often need to wait for a period of time before obtaining threads allocated by the operating system. To prevent the first task queue from waiting for too long and affecting the normal operation of the application, the operating system may determine the priority of the first task queue based on the waiting time of the first task queue.

[0241] In this implementation, the operating system can raise the priority of the first task queue by one level every time the waiting time of the first task queue exceeds the first time period, until the operating system can allocate a thread for it, thereby avoiding the waiting time of the first task queue from being too long.

[0242] The above description discloses a scheme by which the operating system determines the priority of the first task queue based on second information of the first task, third information of the application, the type of the task, and the waiting time of the first task queue. Alternatively, the priority of the first task queue can be determined by combining two or more of the above methods.

[0243] For example, the operating system can simultaneously determine the priority of the first task queue based on the third information of the application and the types of tasks included in the first task queue. The third information of the application can be the application's running platform. In this case, when an application's running platform is in the foreground and the types of tasks in the application's first task queue correspond to higher priorities, then the priority of the application's first task queue can be determined to be high priority.

[0244] In this embodiment of the application, the operating system generates a first thread pool based on its current load level. The first thread pool includes idle threads generated by the operating system, so that the operating system can allocate corresponding threads for the tasks that the application needs to perform.

[0245] Different threads can execute different tasks, and different applications need to execute different tasks. The operating system can generate a first thread pool based on its current load level. In this case, the embodiments of this application further include the following steps:

[0246] First, the operating system determines at least one first application whose application frequency is higher than a first threshold during a first time period;

[0247] The second step is for the operating system to determine the target thread in which the frequency of the first application application is higher than the second threshold during the first time period.

[0248] Third, the operating system determines the number of target threads that can be supported based on its current load level, and generates a corresponding number of target threads, which are located in the first thread pool.

[0249] Through the above steps, the operating system can generate threads in the first thread pool. Furthermore, the target threads generated by the operating system are those frequently used by the first application, which is a frequently used application within the electronic device. In this case, the threads generated by the operating system are frequently used threads, thus enabling the threads in the first thread pool to meet the needs of most scenarios.

[0250] Alternatively, in another method where the operating system generates a first thread pool based on its current load level, the operating system may have a correspondence between each application and the threads required by the application. During the operation of the electronic device, the operating system determines the applications installed in the electronic device and generates corresponding threads based on the correspondence between the applications and the threads required by the applications. These threads are located in the first thread pool.

[0251] Of course, the operating system can also generate threads in the first thread pool in other ways, and this application embodiment does not limit this.

[0252] Furthermore, after creating the first thread pool, the operating system can adjust the threads included in the first thread pool according to changes in its own load level. For example, when the operating system's load level increases, the operating system can destroy some of the threads to ensure the smooth operation of the operating system. When the operating system's load level decreases, the operating system can generate new idle threads and place them in the first thread pool so that the first thread pool can meet the application's increased thread requirements.

[0253] The above embodiments disclose methods for managing threads required by applications within an operating system. Furthermore, during the operation of the operating system, the operating system itself often needs to perform certain tasks, and correspondingly, the operating system requires threads to execute these tasks. To manage these required threads, this application also discloses the following steps:

[0254] The operating system will assign at least one second task to be executed to the corresponding second task queue;

[0255] The operating system determines the priority of the second task queue;

[0256] The operating system allocates idle threads from the second thread pool to the second task queue according to the priority of the second task queue. The idle threads in the second thread pool are created by the operating system according to its current load level.

[0257] In this embodiment of the application, when the operating system itself needs to execute a second task, it assigns the second task to the corresponding second task queue, and then allocates idle threads from the second thread pool to the second task queue according to the priority of the second task queue.

[0258] Different second task queues can correspond to different task types. For example, the operating system usually executes display rendering tasks (i.e., render tasks) and UI update tasks. The operating system can create second task queues corresponding to display rendering tasks and UI update tasks respectively, and assign the display rendering tasks and UI update tasks to the corresponding second task queues respectively.

[0259] Furthermore, the operating system typically determines the priority of the second task queue based on the types of tasks included in it. For example, the operating system typically prioritizes display rendering tasks; therefore, it usually assigns a higher priority to the second task queue that includes display rendering tasks.

[0260] In this embodiment, the operating system creates a second thread pool based on its current load level, and the second thread pool includes idle threads. In this case, the operating system can prioritize allocating idle threads from the second thread pool to the higher-priority second task queue according to the priority of the second task queue.

[0261] Furthermore, in this embodiment, the second thread pool and the first thread pool may be the same thread pool, meaning that the thread pool includes threads required by both the operating system and the application. Alternatively, the second thread pool and the first thread pool may be different thread pools; this embodiment does not limit this.

[0262] In this application, when the first thread pool and the second thread pool are the same thread pool, an example is disclosed to clarify the method for allocating threads to the second task queue in order to clarify the embodiments of this application. See also Figure 7 The diagram shown illustrates an example where an electronic device has application A and application B installed, and the operating system of the electronic device manages the threads required by application A and application B.

[0263] In this example, the first tasks to be executed by application A include tasks 1, 2, 3...10, and the first tasks to be executed by application B include a UI update task. After receiving the first information submitted by applications A and B, the operating system can allocate the first tasks of applications A and B to corresponding first task queues based on the first information. In this example, the operating system allocates the first task of application A to both the serial task queue and the parallel task queue, and allocates the first task of application B to the UI update task queue.

[0264] The operating system creates a first thread pool, which includes idle threads created by the operating system according to its own load level. The operating system can allocate threads from the first thread pool to the serial task queue and parallel task queue corresponding to application A, and the UI update task queue corresponding to application B, so that application A and application B can execute corresponding tasks according to the threads allocated by the operating system.

[0265] Furthermore, since the first thread pool and the second thread pool are the same thread pool in this example, the first thread pool also includes threads allocated for tasks required by the operating system. In this case, after the operating system allocates the second task to the second task queue, the operating system can also allocate threads in the first thread pool that can execute the second task to the second task queue, so that the threads can execute the tasks in the second task queue.

[0266] Accordingly, this application also discloses a thread management method. This thread management method is executed by the application; see [link to relevant documentation]. Figure 8 The workflow diagram shown illustrates that this thread management method includes the following steps:

[0267] Step S21: When the application needs to execute the first task, it submits first information to the operating system through the first application programming interface (API) corresponding to the first task. The first information is used to indicate the first task.

[0268] Step S22: The application executes the first task through the thread allocated to the first task by the operating system.

[0269] In this embodiment, the application submits first information to the operating system via its first API. Based on this first information, the operating system determines a first task to be executed, assigns the at least one first task to a corresponding first task queue, and then allocates threads to the first task queue based on its current load level and the type of the first task queue. The application then executes the first task through the thread allocated by the operating system.

[0270] In this scenario, the user program does not need to create the thread for the first task. Instead, the operating system allocates the required threads to the application. That is, the operating system allocates the thread for the first task to the user program, thereby avoiding the abuse of threads by the application, reducing the phenomenon of thread explosion, and enabling the operating system to run efficiently.

[0271] Furthermore, in this embodiment of the application, the following steps are also included:

[0272] If the application fails to obtain the thread allocated by the operating system for the first task within a first time period after submitting the first information, the application transmits a first request to the operating system through the second API corresponding to the first task.

[0273] After obtaining the first feedback corresponding to the first request, the application generates a thread corresponding to the first task and executes the first task through the thread.

[0274] An application can have both a first API and a second API for the same task. When the application needs to execute the task, it first submits the task's initial information to the operating system via the first API, so that the operating system can allocate a thread for the task. However, if the application fails to obtain a thread allocated by the operating system for the task after a first time period, it can call the second API. After determining that the application has called the second API, the operating system typically supports the application in generating a thread corresponding to the task, thereby preventing the application from waiting for an excessively long time.

[0275] Furthermore, in the embodiments of this application, it also includes:

[0276] The application submits second information about the first task to the operating system through the first API corresponding to the first task. The second information is used to indicate the priority of the first task.

[0277] Through the above steps, the operating system can obtain the second information of the first task submitted by the application, and determine the priority of the task queue in which the first task is located through the second information.

[0278] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.

[0279] In this application embodiment, a thread management device is disclosed, see [link to relevant documentation]. Figure 9 The schematic diagram shown illustrates that the thread management device includes:

[0280] Processor 110 and Application Programming Interface (API) 120.

[0281] API 120 is used to obtain at least one piece of first information from the application, wherein the first information is used to indicate the first task to be performed by the application.

[0282] The processor 110 is configured to assign the at least one first task to a corresponding first task queue, and to allocate threads to the first task queue according to the current load level of the processor's operating system and the type of the first task queue.

[0283] The solution disclosed in this application allows the operating system to allocate threads required by the application. Furthermore, the operating system considers its own load level during the thread allocation process, thereby avoiding the abuse of threads by the application, reducing the phenomenon of thread explosion, and enabling the operating system to run efficiently.

[0284] Furthermore, the processor is specifically used to determine the priority of the first task queue;

[0285] Based on the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool, a first target task queue for allocating threads is determined. The first thread pool includes idle threads created according to the current load level of the operating system.

[0286] Based on the type of the first target task queue, allocate an idle thread from the first thread pool to the first target task queue.

[0287] In this embodiment, the operating system can create a first thread pool, which includes idle threads. In this case, when a thread needs to be allocated to a first target task queue, the operating system allocates the pre-created idle threads from the first thread pool to the first target task queue, thus eliminating the need to temporarily create threads for the first target task queue. Therefore, this solution can improve the speed at which the operating system allocates threads to applications, thereby increasing the speed at which applications execute tasks through threads and providing a better user experience.

[0288] In addition, depending on the type of the first target task queue, the processor can allocate corresponding threads to the first target task queue in different ways.

[0289] In one feasible approach, in the apparatus disclosed in the embodiments of this application, the processor is specifically configured to allocate an idle thread from the first thread pool to the serial task queue when the first target task queue includes a serial task queue.

[0290] When the first target task queue includes a parallel task queue, n idle threads from the first thread pool are allocated to the parallel task queue according to the number of tasks in the parallel task queue, where the maximum value of n is the number of tasks included in the parallel task queue.

[0291] The tasks in the serial task queue have strong time dependencies and typically need to be executed sequentially, meaning one task must be completed before the next can begin. If a large number of threads are allocated to this serial task queue, other threads will be idle while one is working, resulting in wasted threads. Therefore, in this embodiment, an idle thread from a first thread pool is allocated to the serial task queue so that this idle thread can execute the tasks in the queue sequentially, thereby reducing thread waste.

[0292] Furthermore, the tasks in the parallel task queue do not have strong time dependencies; tasks can be executed simultaneously, or one task can be completed before another begins. In this case, the operating system can allocate threads to the parallel task queue based on the number of tasks in the queue, and the operating system can allocate a maximum of n idle threads to the parallel task queue, where n is the number of tasks in the queue, to avoid thread waste.

[0293] Furthermore, in the apparatus disclosed in the embodiments of this application, the processor is further configured to, after at least one task in the first target task queue is completed, reclaim the thread allocated to the first target task queue to the first thread pool, or schedule the thread allocated to the target task queue to other task queues, or destroy the thread allocated to the first target task queue.

[0294] The thread management device disclosed in this application can reclaim, schedule, and destroy threads that have completed tasks, thereby reducing thread waste and minimizing the phenomenon of thread number explosions.

[0295] Furthermore, in the apparatus disclosed in the embodiments of this application, the processor is further configured to, when the first task queue includes a second target task queue and the first thread pool does not include a thread for executing tasks in the second target task queue, create and allocate a corresponding thread for the second target task queue, or support the application to create a corresponding thread for the second target task queue.

[0296] Wherein, the second target task queue is a first task queue with a higher priority than the first priority, and / or, the second target task queue includes target tasks.

[0297] In the scheme disclosed in the embodiments of this application, when the first thread pool does not include a thread for executing tasks in the second target task queue, in order to ensure the smooth execution of tasks in the second target task queue, the process can create and allocate a corresponding thread for the second target task queue, or support the application to create a corresponding thread for the second target task queue so that the tasks in the second target task queue can be executed smoothly.

[0298] In this embodiment, the priority of the first task queue can be determined in multiple ways. Specifically, the processor is configured to determine the priority of the first task queue based on second information of the at least one first task submitted by the application.

[0299] And / or, the processor is configured to determine the priority of the first task queue based on third information of the application, the third information including at least one of the following: the application's running platform, whether the application is currently visible, whether the application's functions are currently perceptible, and the application's application frequency;

[0300] And / or, the processor is configured to determine the priority of the first task queue based on the type of tasks included in the first task queue;

[0301] And / or, the processor is configured to determine the priority of the first task queue based on the waiting time of the first task queue.

[0302] When the third information includes the running platform of the application, the processor is used to determine that the priority of the first task queue of the first application is higher than the priority of the first task queue of the second application, the running platform of the first application is the foreground, and the running platform of the second application is the background.

[0303] When the third information includes whether the application is currently visible, the processor is used to determine that the priority of the first task queue of the third application is higher than the priority of the first task queue of the fourth application, the third application is currently visible, and the second application is currently not visible;

[0304] When the third information includes whether the function of the application is currently perceptible, the processor is used to determine that the priority of the first task queue of the fifth application is higher than the priority of the first task queue of the sixth application, the function of the fifth application is currently perceptible, and the function of the sixth application is currently not perceptible.

[0305] When the third information includes the application frequency of the application, the processor determines that the priority of the first task queue of the seventh application is higher than the priority of the first task queue of the eighth application, and the application frequency of the seventh application is higher than the application frequency of the eighth application.

[0306] In addition, in the apparatus disclosed in the embodiments of this application, the processor is specifically used to determine at least one first application whose application frequency is higher than a first threshold during a first time period.

[0307] Identify the target thread whose frequency of application of the first application exceeds the second threshold during the first time period;

[0308] Based on the current load level of the operating system, determine the number of target threads that can be supported, and generate the corresponding number of target threads.

[0309] In the apparatus disclosed in the embodiments of this application, the load level of the operating system is determined by at least one of the following parameters: the idle ratio of the processor running the operating system, the number of currently created threads, the memory usage of the processor, and the read / write status of the memory of the electronic device on which the operating system is installed.

[0310] Furthermore, in the apparatus disclosed in the embodiments of this application, the processor is also configured to allocate at least one second task to be executed to a corresponding second task queue.

[0311] Determine the priority of the second task queue;

[0312] Based on the priority of the second task queue, idle threads included in the second thread pool are allocated to the second task queue. The idle threads included in the second thread pool are created by the operating system based on its current load level.

[0313] In the thread management method disclosed in this application, the application can submit first information to the operating system via an API. This first information indicates at least one first task to be executed by the application. Based on this first information, the operating system determines the at least one first task to be executed by the application, assigns the at least one first task to a corresponding first task queue, and allocates threads to the first task queue according to its current load level and the type of the first task queue.

[0314] The solution disclosed in this application allows the operating system to allocate threads required by the application. Furthermore, the operating system considers its own load level during the thread allocation process, thereby avoiding the abuse of threads by the application, reducing the phenomenon of thread explosion, and enabling the operating system to run efficiently.

[0315] Accordingly, embodiments of this application also disclose a thread management device. See [link to related document]. Figure 10 The schematic diagram shown illustrates that the thread management device includes:

[0316] Processor 210 and first application programming interface (API) 220.

[0317] Wherein, when the application needs to perform the first task, the first API 220 corresponding to the first task is used to submit first information to the operating system, and the first information is used to indicate the first task;

[0318] The processor 210 is used to execute the first task through the thread allocated to the first task by the operating system.

[0319] The thread management device disclosed in this application allows the operating system to allocate the threads required for the first task to the user program, eliminating the need for the user program to create the threads for the first task. This avoids the abuse of threads by the application, reduces the phenomenon of thread number explosion, and enables the operating system to run efficiently.

[0320] Furthermore, the thread management device disclosed in this application embodiment also includes:

[0321] Second API;

[0322] If no thread is allocated by the operating system for the first task within a first time period after the first information is submitted, the second API corresponding to the first task is used to transmit a first request to the operating system.

[0323] The processor is further configured to, after obtaining the first feedback corresponding to the first request, generate a thread corresponding to the first task, and execute the first task through the thread.

[0324] Furthermore, in the thread management device disclosed in this application embodiment, the processor is also used to submit second information of the first task to the operating system through a first API corresponding to the first task, wherein the second information is used to indicate the priority of the first task.

[0325] The operating system can determine the priority of the first task by using the second information transmitted through the first API.

[0326] Correspondingly, in accordance with the lane line determination method described above, this application also discloses a terminal device. See also Figure 11 The structural diagram shown indicates that the terminal device includes:

[0327] At least one processor 1101 and memory,

[0328] The memory is used to store program instructions;

[0329] The processor is configured to call and execute program instructions stored in the memory, so that the terminal device performs [operations]. Figure 2 and Figure 4 All or part of the steps in the corresponding embodiments.

[0330] Furthermore, the terminal device may also include a transceiver 1102 and a bus 1103, and the memory includes a random access memory 1104 and a read-only memory 1105.

[0331] The processor is coupled to the transceiver, random access memory (RAM), and read-only memory (ROM) via a bus. When the terminal device needs to be run, it is booted by the basic input / output system (BIS) or the bootloader in the embedded system, which is embedded in the ROM, thus guiding the device into normal operation. After the device enters normal operation, the application program and operating system run in the RAM, enabling the mobile terminal control device to perform operations. Figure 2 and Figure 4 All or part of the steps in the corresponding embodiments.

[0332] The apparatus of this invention can correspond to the above. Figure 2 and Figure 4 The thread management device in the corresponding embodiment, and the processor in the thread management device, etc., can implement Figure 2 and Figure 4 For the sake of brevity, the functions of the thread management device in the corresponding embodiments and / or the various steps and methods implemented will not be described in detail here.

[0333] Correspondingly, in accordance with the lane line determination method described above, this application also discloses a terminal device, which includes:

[0334] At least one processor and memory,

[0335] The memory is used to store program instructions;

[0336] The processor is configured to call and execute program instructions stored in the memory, so that the terminal device performs [operations]. Figure 8 All or part of the steps in the corresponding embodiments.

[0337] Furthermore, the terminal device may also include a transceiver and a bus, and the memory includes random access memory and read-only memory.

[0338] The processor is coupled to the transceiver, random access memory (RAM), and read-only memory (ROM) via a bus. When the terminal device needs to be run, it is booted by the basic input / output system (BIS) or the bootloader in the embedded system, which is embedded in the ROM, thus guiding the device into normal operation. After the device enters normal operation, the application program and operating system run in the RAM, enabling the mobile terminal control device to perform operations. Figure 8 All or part of the steps in the corresponding embodiments.

[0339] The apparatus of this invention can correspond to the above. Figure 8The thread management device in the corresponding embodiment, and the processor in the thread management device, etc., can implement Figure 8 For the sake of brevity, the functions of the thread management device in the corresponding embodiments and / or the various steps and methods implemented will not be described in detail here.

[0340] In a specific implementation, embodiments of this application also provide a computer-readable storage medium, which includes instructions. Wherein, a computer-readable medium disposed in any device, when executed on a computer, can implement instructions including... Figure 2 and Figure 4 All or part of the steps in the corresponding embodiments. The storage medium of the computer-readable medium may be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0341] In a specific implementation, embodiments of this application also provide a computer-readable storage medium, which includes instructions. Wherein, a computer-readable medium disposed in any device, when executed on a computer, can implement instructions including... Figure 8 All or part of the steps in the corresponding embodiments. The storage medium of the computer-readable medium may be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0342] Additionally, another embodiment of this application discloses a computer program product containing instructions that, when executed on an electronic device, enable the electronic device to implement the following: Figure 2 and Figure 4 All or part of the steps in the corresponding embodiments.

[0343] Accordingly, another embodiment of this application also discloses a computer program product containing instructions that, when executed on an electronic device, enable the electronic device to implement, including... Figure 8 All or part of the steps in the corresponding embodiments.

[0344] The various illustrative logic units and circuits described in the embodiments of this application can be implemented or operate the described functions using a general-purpose processor, digital information processor, application-specific integrated circuit (ASIC), field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof. The general-purpose processor can be a microprocessor; alternatively, it can also be any conventional processor, controller, microcontroller, or state machine. The processor can also be implemented using a combination of computing devices, such as a digital information processor and a microprocessor, multiple microprocessors, one or more microprocessors combined with a digital information processor core, or any other similar configuration.

[0345] The steps of the methods or algorithms described in the embodiments of this application can be directly embedded in hardware, software units executed by a processor, or a combination of both. The software units can be stored in RAM, flash memory, ROM, EPROM, EEPROM, registers, hard disks, removable disks, CD-ROMs, or any other form of storage medium in the art. Exemplarily, the storage medium can be connected to the processor so that the processor can read information from and write information to the storage medium. Optionally, the storage medium can also be integrated into the processor. The processor and storage medium can be disposed in an ASIC, which can be disposed in the UE. Optionally, the processor and storage medium can also be disposed in different components within the UE.

[0346] It should be understood that in the various embodiments of this application, the sequence number of each process does not imply 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 this application.

[0347] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).

[0348] The same or similar parts between the various embodiments in this specification can be referred to interchangeably. Each embodiment focuses on the differences from other embodiments. In particular, the device and system embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to in the description of the method embodiments section.

[0349] Those skilled in the art will clearly understand that the techniques in the embodiments of the present invention can be implemented using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solutions in the embodiments of the present invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments or certain parts of the embodiments of the present invention.

[0350] The same or similar parts between the various embodiments in this specification can be referred to mutually. In particular, the embodiments of the road constraint determination device disclosed in this application are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description in the method embodiments.

[0351] The embodiments of the present invention described above do not constitute a limitation on the scope of protection of the present invention.

Claims

1. A thread management method, characterized in that, include: The operating system determines at least one piece of first information about the application, the first information being used to indicate a first task to be performed by the application; The operating system assigns the at least one first task to a corresponding first task queue, wherein the first task queue includes: a serial task queue, a parallel task queue, and / or a task queue determined according to the content of the first task; The operating system allocates idle threads from the first thread pool to the first target task queue in the first task queue according to the type of the first task queue. The idle threads are created in advance by the operating system according to its current load level. The first target task queue is a task queue with available threads determined by the operating system according to the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool. Wherein, when the first target task queue includes a serial task queue, the operating system allocates an idle thread from the first thread pool to the serial task queue; When the first target task queue includes a parallel task queue, the operating system allocates n idle threads from the first thread pool to the parallel task queue according to the number of tasks in the parallel task queue, where the maximum value of n is the number of tasks included in the parallel task queue. When the operating system determines that the first task queue includes the second target task queue and the first thread pool does not include a thread for executing tasks in the second target task queue, the operating system creates and allocates a corresponding thread for the second target task queue. Alternatively, if the application does not submit the first information of the tasks in the second target task queue to the operating system, the operating system supports the application in creating a corresponding thread for the second target task queue. Wherein, the second target task queue is a first task queue with a higher priority than the first priority, and / or, the second target task queue includes target tasks.

2. The method according to claim 1, characterized in that, Also includes: After at least one task in the first target task queue is completed, the operating system will either reclaim the thread allocated to the first target task queue back to the first thread pool, or schedule the thread allocated to the target task queue to another task queue, or destroy the thread allocated to the first target task queue.

3. The method according to claim 1, characterized in that, The operating system determines the priority of the first task queue, including: The operating system determines the priority of the first task queue based on the second information of the at least one first task submitted by the application. And / or, The operating system determines the priority of the first task queue based on the third information of the application. The third information includes at least one of the following: the application's running platform, whether the application is currently visible, whether the application's function is currently perceptible, and the application's application frequency. And / or, The operating system determines the priority of the first task queue based on the types of tasks included in the first task queue; And / or, The operating system determines the priority of the first task queue based on the waiting time of the first task queue.

4. The method according to claim 3, characterized in that, The operating system determines the priority of the first task queue based on third information from the application, including: When the third information includes the running platform of the application, the operating system determines that the priority of the first task queue of the first application is higher than the priority of the first task queue of the second application, the running platform of the first application is the foreground, and the running platform of the second application is the background. When the third information includes whether the application is currently visible, the operating system determines that the priority of the first task queue of the third application is higher than the priority of the first task queue of the fourth application, the third application is currently visible, and the second application is currently not visible; When the third information includes whether the function of the application is currently perceptible, the operating system determines that the priority of the first task queue of the fifth application is higher than the priority of the first task queue of the sixth application, the function of the fifth application is currently perceptible, and the function of the sixth application is currently not perceptible. When the third information includes the application frequency of the application, the operating system determines that the priority of the first task queue of the seventh application is higher than the priority of the first task queue of the eighth application, and the application frequency of the seventh application is higher than the application frequency of the eighth application.

5. The method according to claim 1, characterized in that, Also includes: The operating system identifies at least one first application whose application frequency exceeds a first threshold during a first time period. The operating system determines the target thread in which the frequency of the first application application is higher than the second threshold during the first time period. The operating system determines the number of target threads that it can support based on its current load level, and generates a corresponding number of target threads, which are located in the first thread pool.

6. The method according to any one of claims 1 to 5, characterized in that, The load level of the operating system is determined by at least one of the following parameters: the idle ratio of the processor running the operating system, the number of currently created threads, the memory usage of the processor, and the read / write activity of the memory of the electronic device on which the operating system is installed.

7. The method according to any one of claims 1 to 5, characterized in that, Also includes: The operating system will assign at least one second task to be executed to the corresponding second task queue; The operating system determines the priority of the second task queue; The operating system allocates idle threads from the second thread pool to the second task queue according to the priority of the second task queue. The idle threads in the second thread pool are created by the operating system according to its current load level.

8. A thread management device, characterized in that, include: Processor and Application Programming Interface (API); The API is used to obtain at least one piece of first information from the application, the first information being used to indicate the first task to be performed by the application; The processor is configured to assign the at least one first task to a corresponding first task queue, wherein the first task queue includes: a serial task queue, a parallel task queue, and / or a task queue determined according to the content of the first task. The processor is further configured to allocate idle threads from a first thread pool to a first target task queue in the first task queue according to the type of the first task queue. The idle threads are created in advance by the processor according to the current load level of the operating system itself. The first target task queue is a task queue for which threads can be allocated, determined by the processor according to the priority of the first task queue and the task type corresponding to the idle threads in the first thread pool. Wherein, when the first target task queue includes a serial task queue, the processor allocates an idle thread from the first thread pool to the serial task queue; When the first target task queue includes a parallel task queue, the processor allocates n idle threads from the first thread pool to the parallel task queue according to the number of tasks in the parallel task queue, where the maximum value of n is the number of tasks included in the parallel task queue. The processor is further configured to: when the first task queue includes a second target task queue and the first thread pool does not include a thread for executing tasks in the second target task queue, create and allocate a corresponding thread for the second target task queue; or if the application does not submit the first information of the tasks in the second target task queue to the API, support the application in creating a corresponding thread for the second target task queue. Wherein, the second target task queue is a first task queue with a higher priority than the first priority, and / or, the second target task queue includes target tasks.

9. The apparatus according to claim 8, characterized in that, The processor is further configured to, after at least one task in the first target task queue is completed, reclaim the thread allocated to the first target task queue to the first thread pool, or schedule the thread allocated to the target task queue to another task queue, or destroy the thread allocated to the first target task queue.

10. The apparatus according to claim 8, characterized in that, The processor is configured to determine the priority of the first task queue based on the second information of the at least one first task submitted by the application; And / or, The processor is configured to determine the priority of the first task queue based on third information of the application, wherein the third information includes at least one of the following: the application's running platform, whether the application is currently visible, whether the application's functions are currently perceptible, and the application's application frequency; And / or, The processor is used to determine the priority of the first task queue based on the type of tasks included in the first task queue; And / or, The processor is used to determine the priority of the first task queue based on the waiting time of the first task queue.

11. The apparatus according to claim 10, characterized in that, When the third information includes the running platform of the application, the processor is used to determine that the priority of the first task queue of the first application is higher than the priority of the first task queue of the second application, the running platform of the first application is the foreground, and the running platform of the second application is the background. When the third information includes whether the application is currently visible, the processor is used to determine that the priority of the first task queue of the third application is higher than the priority of the first task queue of the fourth application, the third application is currently visible, and the second application is currently not visible; When the third information includes whether the function of the application is currently perceptible, the processor is used to determine that the priority of the first task queue of the fifth application is higher than the priority of the first task queue of the sixth application, the function of the fifth application is currently perceptible, and the function of the sixth application is currently not perceptible. When the third information includes the application frequency of the application, the processor determines that the priority of the first task queue of the seventh application is higher than the priority of the first task queue of the eighth application, and the application frequency of the seventh application is higher than the application frequency of the eighth application.

12. The apparatus according to claim 8, characterized in that, The processor is also configured to determine at least one first application whose application frequency is higher than a first threshold during a first time period. Identify the target thread whose frequency of application of the first application exceeds the second threshold during the first time period; Based on the current load level of the operating system, determine the number of target threads that can be supported, and generate a corresponding number of target threads, which are located in the first thread pool.

13. The apparatus according to any one of claims 8 to 12, characterized in that, The load level of the operating system is determined by at least one of the following parameters: the idle ratio of the processor running the operating system, the number of currently created threads, the memory usage of the processor, and the read / write activity of the memory of the electronic device on which the operating system is installed.

14. The apparatus according to any one of claims 8 to 12, characterized in that, The processor is also configured to assign at least one second task to be executed to a corresponding second task queue. Determine the priority of the second task queue; Based on the priority of the second task queue, idle threads included in the second thread pool are allocated to the second task queue. The idle threads included in the second thread pool are created by the operating system based on its current load level.

15. A terminal device, characterized in that, include: At least one processor and memory, The memory is used to store program instructions; The processor is configured to call and execute program instructions stored in the memory to cause the terminal device to perform the thread management method according to any one of claims 1-7.

16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the thread management method as described in any one of claims 1-7.