Thread management method and terminal equipment

By introducing thread management methods in the operating system of the terminal device, it is processed according to the task type scheduling thread, and the problem of resource waste caused by thread management has been solved, and the system service efficiency is improved.

CN119376907APending Publication Date: 2025-01-28HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310938861.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-27
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

In the prior art, the management method of threads or thread pools in the operating system of the terminal device is likely to lead to waste of resources and affect system service efficiency.

Method used

Provide a thread management method through the application frame layer of the operating system, detect instructions and generate tasks, and schedules to appropriate thread or thread pool treatment according to the type and corresponding relationships to manage the creation and distribution of threads.

Benefits of technology

Reduce the waste of system resources, improve the processing efficiency and scheduling efficiency of system services, and avoid thread redundancy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119376907A_ABST
    Figure CN119376907A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a thread management method and terminal equipment, provides a new management mode for threads or thread pools in an operating system of the terminal equipment, and can reduce the waste of system resources and improve the efficiency of system services. In the method, an application program framework layer of an operating system of the terminal equipment can provide a capability of generating a thread management task according to a service demand of a service side, so that the capability of directly creating a thread for a system service by the service side can be shielded, and the service side and an operating system side are isolated; therefore, uncontrolled thread creation at the service side can be avoided. By providing the centralized scheduling capability of the threads in the application program framework layer, the threads in the operating system can be managed, so that the waste of system resources such as memory and scheduling can be reduced, and the efficiency of system service can be guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to a thread management method and a terminal device. Background Art

[0002] At present, in the terminal operating system, system services are generally provided by a process, and threads or thread pools within the process are created and managed by various businesses according to business needs. For example, when there is a new business demand, the business creates a new thread or thread pool according to the new business demand. Based on the current operating system's management of threads, it is very easy to cause the wild growth of threads or thread pools, resulting in waste of system resources such as memory and scheduling, and thus affecting the efficiency of system services. Summary of the invention

[0003] The present application provides a thread management method and a terminal device, providing a new management method for threads or thread pools in an operating system of a terminal device, which can reduce the waste of system resources and improve the efficiency of system services.

[0004] In the first aspect, an embodiment of the present application provides a thread management method. The method can be applied to the application framework layer of the operating system of a terminal device, and the method includes: detecting a first instruction, generating a first task in response to the first instruction, wherein the first instruction is used to indicate a first business content that needs to be processed by the operating system, and the first task includes the first business content and a task type determined based on the first business content; scheduling the first task to a first thread or a first thread pool for processing according to the task type and a first correspondence of the first task; wherein the first correspondence is used to indicate the correspondence between the task type and the thread or thread pool.

[0005] Through this method, in the application framework layer of the operating system, the corresponding relationship between the processing requirements of the business and the threads can be managed, so as to avoid the waste of resources such as memory caused by the business side directly connecting to the threads in the operating system. Therefore, this method can manage threads from the operating system side, avoid thread redundancy in the operating system, and improve the processing efficiency and scheduling efficiency of system services.

[0006] When the application framework layer executes scheduling the first task to the first thread or the first thread pool for processing according to the task type and the first corresponding relationship of the first task, there may be multiple implementation methods, for example, including but not limited to the following implementation methods:

[0007] Method A: Determine at least one thread or thread pool corresponding to the task type of the first task based on the task type of the first task and the first corresponding relationship; when the task type of the first task corresponds to a thread or thread pool, the first task can be directly assigned to the thread or thread pool for processing, for example, the thread is the first thread, or the thread pool is the first thread pool; when the task type of the first task corresponds to at least two threads or thread pools, the first thread or the first thread pool can be selected from the at least two threads or thread pools to process the task.

[0008] Method B: According to the task type of the first task and the first corresponding relationship, determine at least one thread or thread pool corresponding to the task type of the first task; then, it is also possible to determine that the first task is associated with the first thread or the first thread pool in combination with the stored association relationship between the task and the thread, and thus assign the first task to the first thread or the first thread pool for processing. Among them, after the application framework layer schedules a thread or thread pool for a task each time, it can store the association relationship between the task and the thread or thread pool, so that the application framework layer can preferentially assign repeated tasks to the same thread or thread pool for processing, thereby improving task processing efficiency. It can be understood that in method B, the first task can be understood as a repeated task, and in method A, the first task can be understood as an initial task.

[0009] In some possible embodiments, the method also includes: detecting a second instruction, generating a second task in response to the second instruction, the second instruction being used to indicate a second business content that needs to be processed by the operating system, the second task including the second business content and a task type determined based on the second business content; scheduling the second task to the first thread or the first thread pool for processing based on the task type of the second task and the first correspondence; wherein the second task has the same task type as the first task.

[0010] Through this embodiment, it can be seen that the business processing requirements of different business parties can also be assigned to the same thread for processing according to the task type corresponding to the business processing requirements. Therefore, this method can manage threads from the operating system side, avoid thread redundancy in the operating system, and improve the processing efficiency and scheduling efficiency of system services.

[0011] In some possible embodiments, the method is specifically applied to a task scheduling framework included in the application framework layer; the detecting the first instruction includes: detecting the first instruction through a task adding interface provided by the task scheduling framework; wherein the first instruction comes from other system services included in the application framework layer except the task scheduling framework, or from the application layer of the operating system. It can be understood that the task scheduling framework can be understood as a system service provided by the application layer.

[0012] In this embodiment, the task scheduling framework set in the application framework layer can be used to manage threads from the operating system side. In addition, the task scheduling framework can receive not only instructions from the application layer, but also instructions from other system services included in the application framework layer, so that tasks for allocating threads can be generated according to the instructions. Therefore, through the thread management of the operating system, the waste of resources such as memory caused by the business side directly connecting to the threads in the operating system can be avoided.

[0013] In some possible embodiments, before scheduling the first task to the first thread or the first thread pool for processing, the method further includes but is not limited to determining the following conditions:

[0014] Condition 1: Determine that no task is being processed by the first thread or the first thread pool; or

[0015] Condition 2: It is determined that the first thread or the first thread pool has a task being processed, and the first thread or the first thread pool does not belong to the main thread, and the main thread is a resident thread corresponding to the task type corresponding to the first task; or

[0016] Condition 3: determining that the first thread or the first thread pool has a task being processed, and the first thread or the first thread pool belongs to the main thread, and the task being processed is a related task of the first task; or

[0017] Condition 4: Determine that the first thread or the first thread pool has a task being processed, and the first thread or the first thread pool belongs to the main thread, and the task being processed is not related to the first task, and there is no idle thread, and the conditions for creating a new thread are not met.

[0018] Optionally, when the first task is a first task, it can be determined based on the above introduction whether the first thread or the first thread pool can be allocated to process the first task. It is understandable that the above introduction can be combined with the introduction of method A to achieve thread allocation. Alternatively, when the first task is a repeated task, it can be determined based on the above introduction whether a new thread needs to be scheduled for the first task. It is understandable that the above introduction can be combined with the introduction of method B to achieve thread reallocation.

[0019] In this embodiment, the application framework layer of the operating system allocates threads to tasks, and can allocate threads or thread pools to the first task based on one or more factors such as the processing status of the thread on the task, whether the thread is the main thread, the relevance of the task processed by the main thread to the first task, the processing status of other threads in the operating system on the task, and the number of threads in the operating system; wherein, when the application framework layer allocates threads to tasks, it can give priority to the main thread, or give priority to the idle thread, etc. In this way, the processing efficiency of the thread on the task can be improved, and the system processing efficiency in the operating system can be guaranteed.

[0020] In some possible embodiments, when the operating system includes multiple threads, the method further includes: when the first thread or the first thread pool is processing the third task, scheduling the first task to be processed by the second thread; wherein the second thread is an idle thread or a newly added thread. It is understandable that when the first task is a repetitive task, the first thread or the first thread pool is assigned to the first task based on the introduction content of method B, and because the first thread or the first thread pool is in a busy state, the application framework layer can also implement flexible thread scheduling for the first task, thereby ensuring the processing efficiency of the task. In addition, based on the application framework layer storing the association relationship between the first task and the first thread or the first thread pool, when scheduling other threads for the first task, the association relationship between the first task and the thread can be updated, that is, the association relationship stored as the first task and the second thread can be updated.

[0021] In this embodiment, the application framework layer of the operating system can not only implement task allocation threads based on task types, but also implement task scheduling of other threads based on the idle and busy states of threads. In this way, the overall processing efficiency of threads in the operating system for tasks can be guaranteed, and balanced distribution of tasks can be achieved.

[0022] In some possible embodiments, when the operating system includes multiple threads, the method further includes: when the first thread or the first thread pool is processing a third task, and the first thread or the first thread pool is the main thread corresponding to the task type of the first task, and the third task is unrelated to the first task, the first task is scheduled to be processed by the second thread; wherein the second thread is an idle thread or a newly added thread. It can be understood that when the first task is a repeated task, the first thread or the first thread pool is assigned to the first task based on the introduction of mode B, and because the first thread or the first thread pool is in a busy state and is processing tasks unrelated to the first task, the application framework layer can also implement flexible thread scheduling for the first task, thereby ensuring the processing efficiency of the task; it can be understood that when the task being processed by the first thread or the first thread pool is related to the first task, it can still be processed by the first thread or the first thread pool to ensure processing efficiency. In addition, based on the application framework layer storing the association relationship between the first task and the first thread or the first thread pool, when scheduling other threads for the first task, the association relationship between the first task and the thread can be updated, that is, the updated storage is the association relationship between the first task and the second thread.

[0023] In this embodiment, the application framework layer of the operating system can not only implement task allocation threads based on task types, but also implement task scheduling of other threads based on the idle and busy states of threads. In this way, the overall processing efficiency of threads in the operating system for tasks can be guaranteed, and balanced distribution of tasks can be achieved.

[0024] In some possible embodiments, after scheduling the first task to the first thread or the first thread pool for processing, the method further includes: storing the association relationship between the first task and the first thread or the first thread pool. Based on this embodiment, the method further includes: detecting a third instruction, generating a fourth task in response to the third instruction, the third instruction being used to indicate a third business content that needs to be processed by the operating system, the task identifier of the fourth task being the same as the task identifier of the first task, the fourth task including the third business content and a task type determined based on the third business content; scheduling the fourth task to the first thread or the first thread pool for processing according to the task type of the fourth task, the first corresponding relationship, and the association relationship.

[0025] In some possible embodiments, after scheduling the first task to be processed by the second thread, the method further includes: updating the stored association relationship between the first task and the first thread or the first thread pool to an association relationship between the first task and the second thread.

[0026] In this embodiment, by storing and updating the association between tasks and threads, it is possible to facilitate the configuration of tasks that need to be executed again, such as periodic tasks and tasks executed in batches, to the same thread for processing. In this way, the processing efficiency of threads for tasks can be improved.

[0027] In some possible embodiments, scheduling the first task to the second thread for processing includes: determining that there is at least one idle thread, scheduling the first task to any one of the at least one idle thread, and the second thread is any one of the at least one idle thread; or, determining that there are no idle threads and determining that the conditions for creating a new thread are met, scheduling the first task to the newly created second thread.

[0028] In this embodiment, the application framework layer of the operating system can not only schedule tasks to other threads, but also realize dynamic management of threads, thereby balancing the relationship between the number of threads in the operating system and the task processing efficiency.

[0029] In some possible embodiments, the conditions for creating a new thread include: the conditions for creating a new thread include: all the established threads corresponding to the task type of the first task included in the application framework layer have tasks to be processed, and the number of the established threads is less than the thread number threshold corresponding to the task type of the first task.

[0030] In this embodiment, the application framework layer of the operating system can realize dynamic expansion processing of threads at the task type level. In this way, not only can the wild growth of threads be avoided, which leads to waste of system resources such as memory and scheduling, but also the processing efficiency of tasks can be guaranteed by timely expansion of threads of each task type.

[0031] In some possible embodiments, the first instruction is a system service instruction triggered based on a power management service, and the first task is a power management task; or, the first instruction is a system service instruction triggered based on a Wireless Fidelity Wi-Fi service, and the first task is a Wi-Fi management task.

[0032] In some possible embodiments, the task type is I / O intensive or CPU intensive.

[0033] In a second aspect, an embodiment of the present application further provides a terminal device, comprising a memory and one or more processors; wherein the memory is used to store computer program code, and the computer program code comprises computer instructions; when the computer instructions are executed by the processor, the terminal device executes a method executed by the terminal device in any possible design in the first aspect above.

[0034] In a third aspect, an embodiment of the present application further provides a terminal device, which includes a module / unit for executing the method in any possible design of the first aspect. These modules / units can be implemented by hardware, or by executing corresponding software implementations by hardware.

[0035] In some embodiments, the terminal device may include a processing module. The processing module may be used to detect a first instruction, and generate a first task in response to the first instruction, wherein the first instruction is used to indicate a first business content that needs to be processed by the operating system, and the first task includes the first business content and a task type determined based on the first business content; and may also be used to schedule the first task to be processed by a first thread or a first thread pool according to the task type of the first task and a first corresponding relationship; wherein the first corresponding relationship is used to indicate the corresponding relationship between the task type and the thread or thread pool.

[0036] In a fourth aspect, a computer-readable storage medium is provided, which stores a computer program (also referred to as code or instruction) which, when executed on a computer, enables the computer to execute a method in any possible design of the first aspect.

[0037] In a fifth aspect, a computer program product is provided, which includes: a computer program (also referred to as code, or instruction), which, when executed, enables a computer to execute a method in any possible design of the first aspect.

[0038] In the sixth aspect, a graphical user interface on a terminal device is also provided, the terminal device having a display screen, one or more memories, and one or more processors, the one or more processors being used to execute one or more computer programs stored in the one or more memories, the graphical user interface including the graphical user interface displayed when the terminal device executes any possible implementation method of the first aspect of the embodiment of the present application.

[0039] In a seventh aspect, the present application also provides a chip, which is used to read a computer program stored in a memory and execute any of the above aspects and possible methods designed to be executed by a terminal device.

[0040] In an eighth aspect, the present application further provides a chip system, which includes a processor for supporting a computer device to implement any of the above aspects and methods for execution of each possible design terminal device. In one possible design, the chip system also includes a memory, which is used to store programs and data necessary for the computer device. The chip system can be composed of a chip, or it can include a chip and other discrete devices.

[0041] It should be noted that for the beneficial effects of the various designs of the terminal devices provided in the second to eighth aspects of the embodiments of the present application, please refer to the beneficial effects of any possible design in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A software system architecture block diagram of a terminal device provided in an embodiment of the present application;

[0043] Figure 2 A schematic diagram of a hardware architecture of a terminal device provided in an embodiment of the present application;

[0044] Figure 3 An application framework diagram applicable to a thread management method provided in an embodiment of the present application;

[0045] Figure 4a A possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application;

[0046] Figure 4b Another possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application;

[0047] Figure 5 A flowchart of a thread management method provided in an embodiment of the present application;

[0048] Figure 6 Another application framework diagram applicable to a thread management method provided in an embodiment of the present application;

[0049] Figure 7 A diagram showing another possible correspondence relationship between task instances and thread instances provided in an embodiment of the present application;

[0050] Figure 8 Another flowchart of a thread management method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0052] First, the technical terms that may be involved in the embodiments of the present application are explained:

[0053] (1) Process (process, job, task): The basic unit of resource allocation by the operating system, which contains information such as program code, data, and execution status. Generally, when a program is started, the operating system will create a process for the program.

[0054] The system consists of a collection of processes, operating system processes execute system code, and user processes execute user code.

[0055] Each process is assigned a process identifier (PID) to facilitate identification and tracking of the process.

[0056] It is understood that the program itself is not a process, but an executable file stored on disk.

[0057] (2) Thread: An independently executable unit within a process that shares the address space of the process but each stores the state required for runtime (i.e., context).

[0058] According to the number of threads, processes can be divided into traditional (early) single-threaded processes and multi-threaded processes. Multi-threaded processes allow multiple tasks to be executed at the same time.

[0059] A process is an independent execution unit in an operating system, and a thread is an execution unit in a process. For modern operating systems, the relationship between them is one-to-many.

[0060] The embodiments of the present application can be applied to the field of terminal technology, and specifically can be applied to the operating system (OS) of the terminal. The OS involved in the embodiments of the present application is the most basic system software running on the terminal device. The software system of the terminal device can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. The embodiments of the present application take an OS adopting a layered architecture as an example to illustrate the software system architecture of the terminal device.

[0061] Figure 1 A software system architecture block diagram of a terminal device provided in an embodiment of the present application. Figure 1 As shown, the software system architecture of the terminal device can be a layered architecture, for example, the software can be divided into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the OS is divided into five layers, from top to bottom, namely, the application layer, the application framework layer (framework, FWK), the runtime and system library, the kernel layer, and the hardware layer.

[0062] The application layer can include a series of application packages. Figure 1 As shown, the application layer may include camera, settings, skin module, user interface (UI), third-party applications, etc. Among them, the third-party applications may include wireless local area network (WLAN), music, call, Bluetooth, video, memo, information, etc.

[0063] In a possible implementation, the application can be developed using the Java language and completed by calling the application programming interface (API) provided by the application framework layer. Developers can interact with the bottom layer of the OS (such as the hardware layer, the kernel layer, etc.) through the application framework layer to develop their own applications. The application framework layer is mainly a series of services and management systems for the OS. At present, the developers of various system services (which can also be understood as the business side) use independent threads to create system service threads and subsidiary function threads; which can also be understood as. The business side can complete the creation of system service threads and subsidiary function threads by itself through the API provided by the application framework layer, and the OS side will not perform any control on the system service threads or service function threads created by the business layer. Therefore, the thread management method currently used in the OS may cause problems that the threads created by the business side always exist during operation, and as the number of system services increases, the number of threads in the OS will continue to increase, resulting in memory usage, increased lock contention probability, and may lead to reduced thread processing efficiency in the OS.

[0064] In addition, in the current thread management method, the threads created by the business side do not have resource attributes; it can also be understood that the OS cannot distinguish whether the threads correspond to central processing unit (CPU) intensive resources or input / output (I / O) intensive resources. In this way, even if the OS can manage threads, it cannot perform targeted optimization based on the resource attributes of the threads.

[0065] The application framework layer provides application programming interfaces and programming frameworks for applications in the application layer. The application framework layer includes some predefined functions. Figure 1 As shown, the application framework layer may include an activity manager, a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0066] The activity manager is used to manage the life cycle of each application and provide common navigation back functions, providing an interactive interface for all program windows.

[0067] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make the data accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0068] The view system includes visual controls, such as controls for displaying text and controls for displaying images. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0069] The phone manager is used to provide communication functions for terminal devices, such as the management of call status (including answering, hanging up, etc.).

[0070] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0071] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, the terminal device vibrates, the indicator light flashes, etc.

[0072] The runtime includes the core library and the virtual machine. The runtime is responsible for the scheduling and management of the OS.

[0073] The core library consists of two parts: one is the function that the Java language needs to call, and the other is the core library of the OS. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0074] The system library may include multiple functional modules, such as a surface manager, a media framework, a 3D graphics processing library (such as OpenGL ES), a 2D graphics engine (such as SGL), etc.

[0075] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0076] The media framework supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media framework can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0077] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0078] A 2D graphics engine is a drawing engine for 2D drawings.

[0079] In some embodiments, a three-dimensional graphics processing library may be used to draw a three-dimensional motion trajectory image, and a two-dimensional graphics engine may be used to draw a two-dimensional motion trajectory image.

[0080] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0081] The hardware layer can include various types of sensors, such as accelerometers, gravity sensors, touch sensors, etc.

[0082] Usually, a terminal device can run multiple applications at the same time. In simpler cases, one application can correspond to one process, and in more complex cases, one application can correspond to multiple processes. Each process has a process number (process ID).

[0083] In view of this, an embodiment of the present application provides a thread management method. In this method, a solution for managing threads from the OS side is provided. Through this method, the OS side can isolate the business side from the OS side, thereby avoiding the uncontrolled creation of threads on the business side. In this way, the redundancy of threads included in the OS can be reduced, the waste of system resources such as memory and scheduling can be reduced, and the processing efficiency and scheduling efficiency of threads can be improved.

[0084] In addition, in this method, the resource types required by the system services can also be considered, and distributed to different threads or thread pools for processing according to the requirements of different resource types. In addition, targeted expansion or reduction processing can be performed, thereby improving the execution efficiency and resource utilization of different task types, and improving the response delay and throughput of tasks.

[0085] The embodiments of the present application can be applied to terminal devices equipped with OS, such as mobile phones, PCs, tablet computers, wearable devices (e.g., watches, bracelets, etc.), vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), smart home devices (e.g., smart TVs, smart speakers, etc.). It is understandable that the embodiments of the present application do not impose any restrictions on the specific types of terminal devices.

[0086] The terminal device to which the embodiments of the present application can be applied includes but is not limited to a terminal device equipped with Or terminal devices of other OS. The portable terminal device may also be other portable terminal devices, such as a laptop computer (Laptop) with a touch-sensitive surface (eg, a touch panel).

[0087] Figure 2 FIG. 2 shows a possible hardware structure diagram of a terminal device. The terminal device 200 includes: a radio frequency (RF) circuit 210, a power supply 220, a processor 230, a memory 240, an input unit 250, a display unit 260, an audio circuit 270, a communication interface 280, and a wireless fidelity (Wi-Fi) module 290. Those skilled in the art will understand that Figure 2 The hardware structure of the terminal device 200 shown in the figure does not constitute a limitation on the terminal device 200. The terminal device 200 provided in the embodiment of the present application may include more or fewer components than those shown in the figure, may combine two or more components, or may have different component configurations. Figure 2 The various components shown in the drawings may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0088] Combine the following Figure 2 The components of the terminal device 200 are described in detail:

[0089] The RF circuit 210 can be used for receiving and sending data during communication or calls. In particular, after receiving downlink data from the base station, the RF circuit 210 sends it to the processor 230 for processing; in addition, the uplink data to be sent is sent to the base station. Generally, the RF circuit 210 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, etc.

[0090] In addition, the RF circuit 210 can also communicate with other devices through a wireless communication network. The wireless communication can use any communication standard or protocol, including but not limited to global system of mobile communication (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), long term evolution (LTE), email, short messaging service (SMS), etc.

[0091] The terminal device 200 can also implement communication services and interact with other terminal devices, so the terminal device 200 needs to have a data transmission function, that is, the terminal device 200 needs to include a communication module. Figure 2 Communication modules such as the RF circuit 210, the Wi-Fi module 290, and the communication interface 280 are shown, but it is understandable that at least one of the above components or other communication modules (such as a Bluetooth module) for implementing communication exist in the terminal device 200 to perform data transmission.

[0092] For example, when the terminal device 200 is a mobile phone, the terminal device 200 may include the RF circuit 210, and may also include the Wi-Fi module 290, or may include a Bluetooth module ( Figure 2 When the terminal device 200 is a computer, the terminal device 200 may include the communication interface 280, and may also include the Wi-Fi module 290, or may include a Bluetooth module ( Figure 2 When the terminal device 200 is a tablet computer, the terminal device 200 may include the Wi-Fi module, or may include a Bluetooth module ( Figure 2 not shown).

[0093] Wi-Fi technology is a short-range wireless transmission technology. The terminal device 200 can connect to an access point (AP) through the Wi-Fi module 290 to access the data network. The Wi-Fi module 290 can be used for receiving and sending data during the communication process.

[0094] The terminal device 200 can be physically connected to other devices through the communication interface 280. Optionally, the communication interface 280 is connected to the communication interface of the other device through a cable to achieve data transmission between the terminal device 200 and the other device.

[0095] The memory 240 can be used to store software programs and modules. The processor 230 executes various functional applications and data processing of the terminal device 200 by running the software programs and modules stored in the memory 240. Optionally, the memory 240 may mainly include a program storage area and a data storage area. Among them, the program storage area can store the OS (mainly including the kernel layer, system layer, application framework layer, application layer, etc., respectively corresponding to the software programs or modules).

[0096] In addition, the memory 240 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0097] The input unit 250 can be used to receive the editing operations of various types of data objects such as numbers or character information input by the user, and generate key signal input related to the user settings and function control of the terminal device 200. Optionally, the input unit 250 may include a touch panel 251 and other input devices 252.

[0098] Among them, the touch panel 251, also known as a touch screen, can collect user touch operations on or near it (for example, the user uses fingers, stylus or any other suitable objects or accessories on or near the touch panel 251) and drive the corresponding connection device according to a pre-set program.

[0099] Optionally, the other input devices 252 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc.

[0100] The display unit 260 can be used to display information content input by the user or information content provided to the user and various menus of the terminal device 200. The display unit 260 is the display system of the terminal device 200, which is used to present an interface and realize human-computer interaction. The display unit 260 may include a display panel 261. Optionally, the display panel 261 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.

[0101] The processor 230 is the control center of the terminal device 200. It connects various components using various interfaces and lines, and executes various functions and processes data of the terminal device 200 by running or executing software programs and / or modules stored in the memory 240, and calling data stored in the memory 240, thereby realizing various services based on the terminal device 200. In the embodiment of the present application, the processor 230 can be used to implement the thread management method provided in the embodiment of the present application. For example, the ability of the business side to create system service-related threads by itself can be shielded, and only an interface for creating tasks can be provided. The created tasks can be used to schedule threads for processing; for another example, the management of the relationship between tasks and threads, as well as the creation and destruction of threads can be realized through the application framework layer; for another example, an API can be provided to specify the type of task to the business side, so that the strategy optimization of resource allocation can be performed according to the task type; and so on.

[0102] The terminal device 200 also includes a power supply 220 (such as a battery) for supplying power to various components. Optionally, the power supply 220 can be logically connected to the processor 230 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.

[0103] like Figure 2 As shown, the terminal device 200 also includes an audio circuit 270, a microphone 271 and a speaker 272, which can provide an audio interface between the user and the terminal device 200. The audio circuit 270 can be used to convert audio data into a signal that can be recognized by the speaker 272, and transmit the signal to the speaker 272, which is converted into a sound signal and output by the speaker 272. The microphone 271 is used to collect external sound signals (such as the sound of a person speaking, or other sounds, etc.), and convert the collected external sound signals into signals that can be recognized by the audio circuit 270, and send them to the audio circuit 270. The audio circuit 270 can also be used to convert the signal sent by the microphone 271 into audio data, and then output the audio data to the RF circuit 210 to send it to, for example, another terminal device, or output the audio data to the memory 240 for subsequent further processing.

[0104] Although not shown, the terminal device 200 may also include a camera, at least one sensor, etc., which will not be described in detail herein. The at least one sensor may include but is not limited to a pressure sensor, an air pressure sensor, an acceleration sensor, a distance sensor, a fingerprint sensor, a touch sensor, a temperature sensor, etc.

[0105] It should be understood that in the embodiments of the present application, "at least one of the following" or similar expressions refer to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c, or a, b and c, where a, b, c can be single or multiple. "Multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship.

[0106] In addition, it should be understood that, in the description of this application, words such as "first" and "second" are only used for the purpose of distinguishing the description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying an order.

[0107] It should be understood that the software system architecture of the terminal device can be as follows Figure 1 As shown, the hardware structure can be as follows Figure 2 As shown, the software programs and / or modules corresponding to the software system architecture in the terminal device can be stored in the memory 240, and the processor 230 can run the software programs and applications stored in the memory 240 to execute the process of a thread management method provided in an embodiment of the present application.

[0108] In order to facilitate understanding of a thread management method provided by the present application, the following Figures 3 to 7 The content shown introduces the implementation process of the method provided by this application.

[0109] Figure 3 An application framework diagram applicable to a thread management method provided in an embodiment of the present application. Figure 3 The application framework layer shown may include one or more parts for implementing different functions. For example, the application framework layer may include Figure 3 The task scheduling framework and business party 1 related to the embodiment of the present application are shown; wherein, business party 1 can be, for example, a system service such as a resource manager, a power management service, etc., and the present application does not limit business party 1. It can be understood that the task scheduling framework can also be understood as a system service that can be provided by the application framework layer. Among them, the task scheduling framework can include, for example, but is not limited to the following modules: task management module, thread scheduling module, expansion and contraction strategy management module.

[0110] (1) Business party 1, for example, can be various system services included in the application framework layer. Exemplarily, business party 1 can determine the business content to be executed in response to the operation of the application layer or in response to user operations, etc. Then, the business content can be published to the task scheduling framework layer through the task adding interface provided by the task scheduling framework, so that the task scheduling framework layer can execute the task, for example, assign or schedule the corresponding thread for the task.

[0111] In some possible embodiments, tasks may include, but are not limited to: power management tasks, Wi-Fi management tasks, encryption management tasks, etc. Taking the task as a power management task as an example, the scenario of the system service instruction triggered by the power management service may be, for example, but not limited to the following scenarios: the mobile phone triggers to turn on or off the power saving mode based on the power, and the mobile phone triggers a notification message based on the power, and the notification message may be, for example, charged to 80%, fully charged, etc. Exemplarily, business party 1 may serve the power management system (also referred to as "power management service" in the embodiment of the present application), and when receiving the business processing requirements from the application layer, the business content is sent to the task scheduling framework layer. Taking the task as a Wi-Fi management task as an example, the scenario of the system service instruction triggered by the Wi-Fi service may be, for example, but not limited to the following scenarios: the mobile phone triggers the connection to the Wi-Fi service in response to the user's operation of accessing the network. Exemplarily, business party 1 may serve the Wi-Fi system (also referred to as "Wi-Fi service" in the embodiment of the present application), and when receiving the business processing requirements from the application layer, the business content is sent to the task scheduling framework layer. Taking the encryption management task as an example, the scenarios of system service instructions triggered by the encryption system service may include but are not limited to: various applications need to encrypt strings. In addition, task types can be divided into CPU-intensive tasks, I / O-intensive tasks, etc.; among them, CPU-intensive tasks can be encryption management tasks, Wi-Fi management tasks, etc., and I / O-intensive tasks can be file download tasks, etc.

[0112] In this way, the application framework layer of the OS, by providing a task adding interface to the business party 1, can shield the business side's ability to create system service-related processes, and only provide an interface for creating tasks. Thereby, the OS side can manage the relationship between tasks and threads, the creation of threads, the destruction of threads, etc. through the task scheduling framework of the application framework layer. It can be understood that through the method provided in the embodiment of the present application, the application framework layer of the OS can provide the ability to centrally schedule the threads included in the OS, thereby avoiding the business party from directly docking with the threads in the OS. Therefore, this method can implement thread control and scheduling in the OS, avoid thread redundancy in the OS, reduce the waste of system resources, and further improve the processing efficiency and scheduling efficiency of system services.

[0113] (2) A task management module, which can be used to provide task-related APIs, such as providing a task adding interface; wherein the task adding interface can be used by the business party 1 to issue instructions for processing business, and can also be used by the application layer to issue instructions for processing business. In addition, the thread scheduling capability can also be used to complete the management of the correspondence between task types and threads; and to manage task status. It should be noted that the threads or thread pools in the embodiments of the present application can be distinguished according to the business scenario, and threads and thread pools can be used interchangeably in the following embodiments.

[0114] In some possible embodiments, Figure 4a A possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application. Figure 4a Task instance 1, task instance 2 and task instance 3 in the system can be used to represent tasks of the same type. The task management module can implement task instance 1, task instance 2 and task instance 3 running on the same thread instance based on the task type. It is understandable that when there is no thread instance in the OS, or there is no thread instance that can process task instance 1, task instance 2 and task instance 3, a new thread instance can be created. Or it is understandable that when there is a thread instance in the OS that can be used to process task instance 1, task instance 2 and task instance 3, the processing tasks of task instance 1, task instance 2 and task instance 3 can be directly assigned to the thread instance for processing. Figure 4a As can be seen in the figure, a thread instance can be configured for each task type in the OS, so that the thread instance can process at least one task of a task type. In this way, multiple tasks belonging to the same task type can be processed by one thread instance, thereby avoiding thread redundancy in the OS.

[0115] Among them, a task instance is an instance based on the task template runtime; a thread instance is an instance based on the thread template runtime; among them, a thread instance can be implemented by a single thread, or can also be implemented by a thread pool (which can also be understood as a group of threads), which can be determined according to the business scenario that needs to be processed.

[0116] In the embodiment of the present application, different task types may correspond to the need to occupy different types of resources. For example, different types of resources may include but are not limited to: CPU-intensive resources, I / O-intensive resources, and short-duration small task types.

[0117] (3) The thread scheduling module can be used to schedule tasks to different types of threads or thread pools.

[0118] In some other possible embodiments, Figure 4b Another possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application. Figure 4b Task instance 1, task instance 2, and task instance 3 in can also be used to represent tasks of the same type. The thread scheduling module can comprehensively consider the processing requirements of task instance 1, task instance 2, and task instance 3, and the processing capabilities of the thread instances, and perform capacity expansion management on the thread instances; wherein, capacity expansion can be understood as creating new threads. It can be understood that after capacity expansion management, the correspondence between task instances and thread instances can be that task instance 1 and task instance 2 run on thread instance 1, while task instance 3 runs on thread instance 2. In this way, Figure 4b Compared to Figure 4a , OS can expand the thread instance. By adding thread instance 2, the processing efficiency and scheduling efficiency of the thread for the task instance can be improved, and the throughput of the thread instance in the OS for processing the task instance can be improved. It can be understood that after the task instance 3 is processed, the thread scheduling module can promptly instruct the expansion and contraction policy management module to destroy the thread instance 2 to achieve thread contraction processing, thereby releasing system resources such as memory and scheduling in a timely manner. Among them, contraction can be understood as destroying some idle threads.

[0119] Through this method, the OS can distribute tasks to different threads or thread pools for processing according to different task types; and, based on throughput considerations, expand or shrink threads, thereby achieving policy optimization in resource allocation based on different task types, improving thread processing efficiency and resource utilization, and further improving OS indicators such as response latency and throughput to tasks.

[0120] (4) A capacity expansion and contraction policy management module can be used to manage the capacity expansion and contraction of threads responsible for executing tasks.

[0121] It is understandable that the thread scheduling module can be used to send expansion policies or contraction policies to the expansion and contraction policy management module based on the threads in the OS and their processing status of tasks, and the expansion and contraction policy management module executes thread expansion processing based on the expansion policy, or executes thread contraction processing based on the contraction policy. In some possible embodiments, the thread scheduling module detects that all the established threads corresponding to the task type of the current task have task instances that need to be processed, and the number of threads that can be carried in the OS is less than the thread number threshold set for the task type, then the expansion policy can be sent. In other possible embodiments, the thread scheduling module detects that there are idle threads in the OS based on the task instances to be processed and the task instances being processed, then the idle threads can be recycled, or one or more main threads can be reserved for each task type, and idle threads other than the main threads can be recycled.

[0122] The main thread can be understood as the thread mainly responsible for the task type assigned by the task type, which can be set to remain resident so that the main thread can respond to the task in a timely manner; and the slave threads other than the main thread can be recycled when the threads are idle, thereby avoiding the occupation and waste of system resources. It is understandable that the OS can include one or more main threads.

[0123] based on Figures 3 to 4b The method provided by the embodiment of the present application can determine the correspondence between tasks and threads based on factors such as task type, thread execution state, and whether the task is a repeated task, so as to implement thread scheduling. The method provided by the present application is described below through an embodiment.

[0124] In one possible embodiment, Figure 5 A flowchart of a thread management method provided in an embodiment of the present application. The process can be applied to a terminal device and may include the following steps:

[0125] Step 501, determine whether there is a task being processed by the first thread corresponding to the first task. In one possible embodiment, the first task may be a task that needs to be processed and is created by the business party according to an event at the application layer, and in the application framework layer, the task is sent by the business party to the task scheduling framework through the task adding interface provided by the task scheduling framework to implement the allocation of threads or thread pools, so that the tasks can be processed by the allocated threads or thread pools; wherein the business party may, for example, be other system services included in the application framework layer except the task scheduling framework. In another possible embodiment, the first task may also be a task that needs to be processed and is created according to an instruction from the application layer; wherein the application layer may issue instructions for indicating business content that needs to be processed by the operating system through the task adding interface provided by the task scheduling framework, so that the task scheduling framework implements the allocation of threads or thread pools.

[0126] In an optional embodiment, the first thread corresponding to the first task can be a thread determined based on the task type of the first task. Exemplarily, the task scheduling framework can match at least one corresponding thread based on the task type of the first task; then, the first thread is selected from the at least one thread as the thread for processing the first task. It can be understood that when the OS includes a thread corresponding to the task type of the first task, the first task can be directly scheduled to this thread for processing; when the OS includes at least two threads corresponding to the task type of the first task, a thread or thread pool can be selected from the at least two threads to process the first task, for example, the main thread, or the idle thread, etc. can be selected first.

[0127] Alternatively, in another optional embodiment, when the first task is a periodic task or a repetitive task that needs to be executed multiple times, the task identifiers of the multiple created tasks can be the same. In this embodiment, after the task scheduling framework assigns a thread to the task, it can maintain the association between the task identifier of the task and the thread. Exemplarily, when the task scheduling framework assigns a thread to the first task, based on the task identifier of the first task, it finds the corresponding thread from the association between the task identifier and the thread, and then it can directly assign it to the thread for processing.

[0128] When step 501 determines yes, step 502 may be continued, and when step 501 determines no, step 511 may be continued. It can be understood that when the first thread does not have a task to process, it may indicate that the current thread has the ability to process the task, and the task may be distributed to the first thread for processing; when the first thread has a task to process, further judgment may be performed.

[0129] Step 502: Determine whether the first thread is a main thread. In some embodiments, the main thread can be set as a resident thread and is usually not recycled by the shrinking policy management module.

[0130] If the answer is yes, then step 503 may be continued to be executed. If the answer is no, then step 511 may be continued to be executed.

[0131] Step 503: Determine whether the task processed by the main thread is the first task distribution. If it is determined to be yes, then proceed to step 511; if it is determined to be no, then proceed to step 504.

[0132] It can be understood that if the task being processed by the main thread is related to the first task, it can continue to be assigned to the main thread for processing; conversely, if the task being processed by the main thread is unrelated to the first task, it can be reallocated to other threads for processing.

[0133] Based on the processing of step 502 and step 503, the first task and its associated tasks can be processed by the same thread, thereby ensuring the efficiency of the thread in processing tasks. For example, if it is determined from step 503 that the main thread is processing the associated tasks of the first task, the first task is also assigned to the first thread for processing.

[0134] The first task may be scheduled through steps 504 to 510. When it is determined through steps 501 to 503 that the first thread cannot process the first task in time, the first task may be scheduled to other threads for processing.

[0135] Step 504: Determine whether there are other idle threads. If yes, proceed to step 509; if no, proceed to step 505.

[0136] It can be understood that when there are idle threads in the OS, the first task can be assigned to the idle thread for processing to avoid thread redundancy. When there are no idle threads in the OS, capacity expansion can be considered. Through dynamic scheduling of threads, the processing efficiency of tasks can be improved.

[0137] Step 505: determine whether the expansion condition is met; wherein the expansion condition can also be understood as the condition for creating a new thread. If the determination is yes, then proceed to step 506; if the determination is no, then proceed to step 511.

[0138] Step 506: Add a second thread.

[0139] Step 507: Update the thread corresponding to the first task.

[0140] Step 508: Distribute to the second thread. It can be understood that through steps 506 to 508, thread expansion can be achieved, and the corresponding relationship between the first task and the second thread can be updated, so that dynamic thread scheduling can be achieved.

[0141] In a possible embodiment, based on allocating a first thread to the first task in step 501, after the task scheduling framework allocates a second thread to the first task in step 508, the association relationship between the task identifier and the thread of the maintenance task can be updated; it can be understood that the task identifier of the first task is associated with the first thread and updated to the task identifier of the first task is associated with the second thread.

[0142] Step 509: Update the thread corresponding to the first task.

[0143] Step 510: Distribute to the idle third thread. It can be understood that through steps 509 and 510, the corresponding relationship between the first task and the idle thread can be updated, so that thread scheduling can be achieved.

[0144] In a possible embodiment, based on allocating the first thread to the first task in step 501, after the task scheduling framework allocates the third thread to the first task in step 510, the association relationship between the task identifier and the thread of the maintenance task can be updated; it can be understood that the task identifier of the first task is associated with the first thread and updated to the task identifier of the first task is associated with the third thread.

[0145] Step 511: Distribute to the first thread. It is understood that the first thread may be a thread selected according to the task type of the first task, and when the first thread has a processing condition that can process the first task, the first thread may process the first task, and when the first thread does not have a processing condition that can process the first task, the second thread or the third thread may be scheduled to process the first task.

[0146] Step 512: Determine and process the reduction.

[0147] In some possible embodiments, the thread scheduling module detects that there are idle threads in the OS based on the task instances to be processed and the task instances being processed, and the idle threads may be recycled.

[0148] In some other possible embodiments, one or more main threads may be reserved for each task type, and idle threads other than the main thread may be recycled; wherein the number of main threads reserved for different task types may be different. It is understood that after an idle slave thread is recycled, one or more tasks corresponding to the slave thread may be updated to be associated with the main thread corresponding to the slave thread.

[0149] In another possible embodiment, Figure 6 Another application framework diagram applicable to a thread management method provided in an embodiment of the present application. Figure 6 The application framework layer shown in Figure 2 is compared to Figure 3 The application framework layer shown may not include a capacity expansion and contraction policy management module. Figure 6 The application framework layer shown can be applied to application scenarios with small throughput changes. The terminal device can manage threads through static allocation without the need for capacity expansion or contraction. It is understandable that the implementation method of task scheduling threads in this scenario can be found in Figure 5 The contents other than step 505 to step 508 are introduced in the above description, which can realize the allocation of the first thread to the task, or scheduling to the idle third thread, so as to realize the thread management. The specific implementation process will not be repeated here.

[0150] Exemplary application scenarios with small throughput changes may include, but are not limited to, large screen processing scenarios, where the large screen is mainly used to play audio and video content, so the threads in the operating system of the large screen are mainly used to process the decoding tasks of audio and video data, without CPU-intensive tasks. Based on this, in a possible embodiment, the operating system of the large screen can reserve multiple threads for the decoding task to ensure the processing efficiency of the decoding task.

[0151] For example, Figure 7 A diagram of another possible correspondence between task instances and thread instances provided in an embodiment of the present application. Figure 7 Task type 1-instance 1, task type 1-instance 2, and task type 1-instance 3 in can run on thread instance 1. Figure 7 The task type 2-instance 1 and task type 2-instance 2 in the example can be run on thread instance 2. It can be understood that in response to the task processing request of task type 1-instance 1, the OS can schedule task type 1-instance 1 to thread instance 1 for processing; in response to the task processing request of task type 1-instance 2, the OS can schedule task type 1-instance 2 to thread instance 1 for processing; in response to the task processing request of task type 1-instance 3, the OS can schedule task type 1-instance 3 to thread instance 1 for processing. Also, in response to the task processing request of task type 2-instance 1, the OS can schedule task type 2-instance 1 to thread instance 2 for processing; in response to the task processing request of task type 2-instance 2, the OS can schedule task type 2-instance 2 to thread instance 2 for processing.

[0152] In this way, the static allocation management of threads in the operating system can avoid the implementation cost and runtime scheduling cost caused by the dynamic expansion and contraction processing. In addition, in the operating system, a corresponding thread instance can be reserved for each task type, so that each task type has a corresponding thread that can handle the task, avoiding the thread redundancy problem caused by establishing a new thread for each task.

[0153] In another possible implementation, Figure 8 Another flowchart of a thread management method provided by an embodiment of the present application. The process can be applied to the application framework layer of the operating system of the terminal device, and may include the following steps:

[0154] Step 801: Detect a first instruction, and generate a first task in response to the first instruction, wherein the first instruction is used to indicate a first business content that needs to be processed by the operating system, and the first task includes the first business content and a task type determined based on the first business content. Figure 3The first task may be a task generated by a task management module in a task scheduling framework, and the task is used to allocate a thread for the business content indicated by the first instruction. The task may include the business content indicated in the first instruction, and may also include information such as the business type.

[0155] Step 802: According to the task type and the first correspondence of the first task, dispatch the first task to the first thread or the first thread pool for processing; wherein the first correspondence is used to indicate the correspondence between the task type and the thread or thread pool. Figure 5 The process shown is for allocating threads to the first task, which will not be described in detail here.

[0156] Based on the above embodiments, the present application also provides a terminal device, which includes multiple functional modules; the multiple functional modules interact with each other to implement the functions performed by the terminal device in each method described in the embodiments of the present application. The multiple functional modules can be implemented based on software, hardware, or a combination of software and hardware, and the multiple functional modules can be arbitrarily combined or divided based on the specific implementation. Figure 5 In the embodiment shown, the terminal device executes steps 501 and 512. Alternatively, if Figure 8 In the illustrated embodiment, the terminal device executes steps 801 and 802.

[0157] Based on the above embodiments, the present application further provides a terminal device, which includes at least one processor and at least one memory, wherein the at least one memory stores computer program instructions, and when the terminal device is running, the at least one processor executes the functions executed by the terminal device in each method described in the embodiments of the present application. Figure 5 In the embodiment shown, the terminal device executes steps 501 and 512. Alternatively, if Figure 8 In the illustrated embodiment, the terminal device executes steps 801 and 802.

[0158] Based on the above embodiments, the present application also provides a computer program product, which includes: a computer program (also referred to as code, or instruction), which enables a computer to execute the methods described in the embodiments of the present application when the computer program is executed.

[0159] Based on the above embodiments, the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a computer, the computer executes the methods described in the embodiments of the present application.

[0160] Based on the above embodiments, the present application further provides a chip, which is used to read a computer program stored in a memory to implement the methods described in the embodiments of the present application.

[0161] Based on the above embodiments, the present application provides a chip system, which includes a processor for supporting a computer device to implement the methods described in the embodiments of the present application. In a possible design, the chip system also includes a memory, which is used to store the necessary programs and data of the computer device. The chip system can be composed of a chip, or it can include a chip and other discrete devices. It should be understood by those skilled in the art that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0162] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 One or more processes and / or boxes Figure 1 A device that performs the functions specified in a block or multiple blocks.

[0163] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0164] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0165] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of protection of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A thread management method, characterized in that: The application framework layer of the operating system applied to terminal devices includes: detecting a first instruction, and generating a first task in response to the first instruction, wherein the first instruction is used to indicate a first business content that needs to be processed by the operating system, and the first task includes the first business content and a task type determined based on the first business content; According to the task type and the first corresponding relationship of the first task, the first task is scheduled to the first thread or the first thread pool for processing; wherein the first corresponding relationship is used to indicate the corresponding relationship between the task type and the thread or thread pool.

2. The method according to claim 1, characterized in that The method further comprises: detecting a second instruction, and generating a second task in response to the second instruction, wherein the second instruction is used to indicate a second business content that needs to be processed by the operating system, and the second task includes the second business content and a task type determined based on the second business content; According to the task type of the second task and the first corresponding relationship, the second task is scheduled to the first thread or the first thread pool for processing; wherein the task type of the second task is the same as that of the first task.

3. The method according to claim 1 or 2, characterized in that: The method is specifically applied to the task scheduling framework included in the application framework layer; The detecting the first instruction comprises: detecting the first instruction through a task adding interface provided by the task scheduling framework; The first instruction comes from other system services included in the application framework layer except the task scheduling framework, or comes from the application layer of the operating system.

4. The method according to claim 1, characterized in that: Before scheduling the first task to be processed by the first thread or the first thread pool, the method further includes: Determine that no task is being processed by the first thread or the first thread pool; or, Determine that the first thread or the first thread pool has a task being processed, and the first thread or the first thread pool does not belong to a main thread, and the main thread is a resident thread corresponding to a task type corresponding to the first task; or, Determine that the first thread or the first thread pool has a task being processed, and the first thread or the first thread pool belongs to the main thread, and the task being processed is a related task of the first task; or, Determine that the first thread or the first thread pool has a task being processed, and the first thread or the first thread pool belongs to the main thread, and the task being processed is not related to the first task, and there is no idle thread, and the conditions for creating a new thread are not met.

5. The method according to any one of claims 1 to 3, characterized in that The method further comprises: When the first thread or the first thread pool is processing the third task, the first task is scheduled to be processed by the second thread; wherein the second thread is an idle thread or a newly added thread.

6. The method according to any one of claims 1 to 3, characterized in that The method further comprises: When the first thread or the first thread pool is processing a third task, and the first thread or the first thread pool is the main thread corresponding to the task type of the first task, and the third task is unrelated to the first task, the first task is scheduled to the second thread for processing; wherein the second thread is an idle thread or a newly added thread.

7. The method according to any one of claims 1 to 6, characterized in that After scheduling the first task to the first thread or the first thread pool for processing, the method further includes: An association relationship between the first task and the first thread or the first thread pool is stored.

8. The method according to claim 7, characterized in that The method further comprises: detecting a third instruction, and generating a fourth task in response to the third instruction, wherein the third instruction is used to indicate a third business content that needs to be processed by the operating system, the task identifier of the fourth task is the same as the task identifier of the first task, and the fourth task includes the third business content and a task type determined based on the third business content; According to the task type of the fourth task, the first corresponding relationship and the associated relationship, the fourth task is scheduled to the first thread or the first thread pool for processing.

9. The method according to any one of claims 5 to 8, characterized in that The step of scheduling the first task to be processed by the second thread includes: Determine that there is at least one idle thread, schedule the first task to any one of the at least one idle thread, and the second thread is any one of the at least one idle thread; or, It is determined that there is no idle thread and that a condition for creating a new thread is met, and the first task is scheduled to the newly created second thread.

10. The method according to claim 4 or 9, characterized in that: The condition for creating a new thread includes: all the established threads corresponding to the task type of the first task included in the application framework layer have tasks to be processed, and the number of the established threads is less than a threshold value of the number of threads corresponding to the task type of the first task.

11. The method according to any one of claims 1 to 10, characterized in that The first instruction is a system service instruction triggered by a power management service, and the first task is a power management task; or The first instruction is a system service instruction triggered based on a Wireless Fidelity Wi-Fi service, and the first task is a Wi-Fi management task.

12. The method according to any one of claims 1 to 11, characterized in that The task type is input / output I / O intensive or central processing unit CPU intensive.

13. A terminal device, characterized in that: The system comprises at least one processor coupled to at least one memory, wherein the at least one processor is configured to read a computer program stored in the at least one memory to execute the method according to any one of claims 1 to 12.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the method according to any one of claims 1 to 12.

15. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 12.