Thread management method and terminal device
By introducing the task scheduling framework in the application frame layer of the operating system, according to the corresponding relationship between the task type and the thread or thread pool, the intelligent scheduling and management of threads solves the problem of inconsistent management in the existing technology. Improving the utilization of system resource utilization and processing efficiency.
Patent Information
- Application Number
- PCT/CN2024/095808
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-07-27
- Filing Date
- 2024-05-28
- Publication Date
- 2025-01-30
AI Technical Summary
In existing operating systems, threads or thread pool management is not effective enough, resulting in waste of resources and reduced system efficiency.
By introducing the task scheduling framework in the application frame layer of the operating system, the intelligent scheduling and management of the thread is realized according to the corresponding relationship between the task type and the thread or thread pool, and the thread in the operating system is directly contacting the operating system.
Effectively reduce the waste of system resources, improve the processing efficiency and scheduling efficiency of system services, and avoid thread redundancy and resource occupation.
Smart Images

Figure CN2024095808_30012025_PF_FP_ABST
Abstract
Description
A thread management method and terminal device
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of the People's Republic of China on July 27, 2023, with application number 202310938861.3 and invention name "A thread management method and terminal device", the entire contents of which are incorporated by reference into this application. Technical Field
[0003] The present application relates to the field of terminal technology, and in particular to a thread management method and a terminal device. Background Art
[0004] Currently, in terminal operating systems, system services are typically provided by a single process, while threads or thread pools within that process are created and managed independently by various businesses based on their needs. For example, when a new business requirement arises, the business creates a new thread or thread pool based on it. Due to the current operating system's thread management method, it is very easy for threads or thread pools to grow unchecked, resulting in a waste of system resources such as memory and scheduling, and thus affecting the efficiency of system services.
[0005] Summary of the Invention
[0006] The present application provides a thread management method and a terminal device, providing a new management method for threads or thread pools in the operating system of the terminal device, which can reduce the waste of system resources and improve the efficiency of system services.
[0007] 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 of the first task and a first correspondence; wherein the first correspondence is used to indicate the correspondence between the task type and the thread or thread pool.
[0008] This method manages the correspondence between business processing requirements and threads within the operating system's application framework layer, thereby avoiding the waste of resources such as memory that would otherwise be caused by direct business-side integration with threads within the operating system. Therefore, this method enables thread management from the operating system side, avoiding thread redundancy within the operating system and improving the processing and scheduling efficiency of system services.
[0009] When the application framework layer schedules the first task to the first thread or the first thread pool for processing according to the task type and the first correspondence of the first task, there may be multiple implementations, for example, including but not limited to the following implementations:
[0010] Method A: Determine at least one thread or thread pool corresponding to the task type of the first task based on 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.
[0011] Method B: Determine at least one thread or thread pool corresponding to the task type of the first task based on the first corresponding relationship; then, the stored association relationship between tasks and threads can be combined to determine that the first task is associated with the first thread or the first thread pool, thereby assigning the first task to the first thread or the first thread pool for processing. In which, after the application framework layer schedules a thread or thread pool for each task, 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, while in method A, the first task can be understood as the first task.
[0012] In some possible embodiments, the method further includes: detecting a second instruction, 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; scheduling the second task to the first thread or the first thread pool for processing according to the task type of the second task and the first correspondence; wherein the second task has the same task type as the first task.
[0013] This example demonstrates that the business processing requirements of different business parties can be assigned to the same thread for processing based on the task types corresponding to those requirements. Therefore, this method enables thread management from the operating system side, avoiding thread redundancy within the operating system and improving the processing and scheduling efficiency of system services.
[0014] In some possible embodiments, the method is specifically applied to a task scheduling framework included in the application framework layer; detecting the first instruction includes detecting the first instruction via a task addition interface provided by the task scheduling framework; wherein the first instruction comes from another system service included in the application framework layer other than the task scheduling framework, or from the application layer of the operating system. It is understood that the task scheduling framework can be understood as a system service provided by the application layer.
[0015] In this embodiment, thread management can be achieved from the operating system side through the task scheduling framework provided in the application framework layer. Furthermore, the task scheduling framework can receive instructions not only from the application layer but also from other system services included in the application framework layer, thereby generating tasks for thread allocation based on these instructions. Therefore, through the operating system's thread management, the waste of resources such as memory caused by the business side directly interfacing with threads in the operating system can be avoided.
[0016] 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:
[0017] Condition 1: Determine that no task is being processed by the first thread or the first thread pool; or
[0018] Condition 2: It is determined that the first thread or the first thread pool is processing a task, and the first thread or the first thread pool is not a main thread, and the main thread is a resident thread corresponding to the task type corresponding to the first task; or
[0019] Condition 3: It is determined that the first thread or the first thread pool is processing a task, 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
[0020] 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.
[0021] Optionally, when the first task is a first-time task, the above-described content may be used to determine whether the first thread or the first thread pool can be allocated to process the first task. It is understood that the above-described content may be combined with the content described in Method A to implement thread allocation. Alternatively, when the first task is a recurring task, the above-described content may be used to determine whether a new thread needs to be scheduled for the first task. It is understood that the above-described content may be combined with the content described in Method B to implement thread reallocation.
[0022] In this embodiment, the application framework layer of the operating system allocates threads to tasks. It can allocate a thread or thread pool to a first task based on one or more factors, such as the thread's task processing status, whether the thread is the main thread, the relevance of the task processed by the main thread to the first task, the task processing status of other threads in the operating system, and the number of threads in the operating system. When allocating threads to tasks, the application framework layer can prioritize assigning threads to the main thread or to idle threads. This can improve the thread's task processing efficiency and ensure system processing efficiency in the operating system.
[0023] 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, 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 of method B, and since 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.
[0024] In this embodiment, the application framework layer of the operating system can not only allocate threads to tasks based on task types, but also schedule 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.
[0025] 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, 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 understood 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 description of method B. However, in scenarios where the first thread or the first thread pool is busy or processing tasks unrelated to the first task, the application framework layer can also implement flexible thread scheduling for the first task, thereby ensuring task processing efficiency. It is understood that when the task being processed by the first thread or the first thread pool is related to the first task, the task 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 between the first task and the first thread or the first thread pool, when scheduling other threads for the first task, the association between the first task and the thread can be updated, that is, the stored association between the first task and the second thread can be updated.
[0026] In this embodiment, the application framework layer of the operating system can not only allocate threads to tasks based on task types, but also schedule 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.
[0027] 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.
[0028] In some possible embodiments, after scheduling the first task to the second thread for processing, 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.
[0029] 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 that are executed in batches, to the same thread for processing. In this way, the efficiency of thread processing of tasks can be improved.
[0030] 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 is no idle thread and determining that the conditions for creating a new thread are met, scheduling the first task to the newly created second thread.
[0031] In this embodiment, the application framework layer of the operating system can not only schedule tasks to other threads, but also implement dynamic management of threads, thereby balancing the relationship between the number of threads in the operating system and task processing efficiency.
[0032] 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.
[0033] In this embodiment, the application framework layer of the operating system can implement dynamic thread expansion processing at the task type level. This not only prevents the uncontrolled growth of threads and the waste of system resources such as memory and scheduling, but also ensures task processing efficiency by timely expanding the thread capacity of each task type.
[0034] In some possible embodiments, 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 by a Wireless Fidelity (Wi-Fi) service, and the first task is a Wi-Fi management task.
[0035] In some possible embodiments, the task type is I / O intensive or CPU intensive.
[0036] 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 the method executed by the terminal device in any possible design in the first aspect above.
[0037] In a third aspect, an embodiment of the present application further provides a terminal device, which includes modules / units for executing the method in any possible design of the first aspect. These modules / units can be implemented by hardware, or corresponding software can be implemented by hardware.
[0038] In some embodiments, the terminal device may include a processing module. The processing module may be configured to detect a first instruction and generate a first task in response to the first instruction, wherein the first instruction indicates 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; the processing module may also be configured to schedule the first task to be processed by a first thread or a first thread pool based on the task type of the first task and a first correspondence; wherein the first correspondence indicates a correspondence between a task type and a thread or a thread pool.
[0039] In a fourth aspect, a computer-readable storage medium is provided, which stores a computer program (also referred to as code or instructions) which, when run on a computer, enables the computer to execute the method in any possible design of the first aspect above.
[0040] In a fifth aspect, a computer program product is provided, which includes: a computer program (also referred to as code, or instructions), which, when executed, enables a computer to execute a method in any one of the possible designs of the first aspect.
[0041] In the sixth aspect, a graphical user interface on a terminal device is also provided, which terminal device has a display screen, one or more memories, and one or more processors, wherein the one or more processors are used to execute one or more computer programs stored in the one or more memories, and the graphical user interface includes a graphical user interface displayed when the terminal device executes any possible implementation method of the first aspect of the embodiment of the present application.
[0042] 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 their possible methods for designing a terminal device to execute.
[0043] In an eighth aspect, the present application further provides a chip system, comprising a processor for supporting a computer device in implementing any of the above aspects and methods executed by a terminal device thereof. In one possible design, the chip system further comprises a memory for storing programs and data necessary for the computer device. The chip system may be composed of a chip alone, or may include a chip and other discrete components.
[0044] 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 this application, please refer to the beneficial effects of any possible design in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] FIG1 is a block diagram of a software system architecture of a terminal device provided in an embodiment of the present application;
[0046] FIG2 is a schematic diagram of a hardware architecture of a terminal device provided in an embodiment of the present application;
[0047] FIG3 is a diagram of an application framework applicable to a thread management method provided in an embodiment of the present application;
[0048] FIG4a is a diagram showing a possible correspondence relationship between task instances and thread instances provided in an embodiment of the present application;
[0049] FIG4 b is another possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application;
[0050] FIG5 is a flow chart of a thread management method provided in an embodiment of the present application;
[0051] FIG6 is a diagram of another application framework applicable to a thread management method provided in an embodiment of the present application;
[0052] FIG7 is another possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application;
[0053] FIG8 is another flowchart of a thread management method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0055] First, the technical terms that may be involved in the embodiments of this application are explained:
[0056] (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.
[0057] The system consists of a collection of processes. Operating system processes execute system code, and user processes execute user code.
[0058] Each process is assigned a process identifier (PID) to facilitate identification and tracking of the process.
[0059] It is understood that the program itself is not a process, but an executable file stored on disk.
[0060] (2) Thread: An independently executable unit within a process that shares the process's address space but each saves the state required for runtime (i.e., context).
[0061] Based on 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.
[0062] A process is an independent execution unit in an operating system, and a thread is an execution unit within a process. For modern operating systems, the relationship between them is one-to-many.
[0063] The embodiments of the present application can be applied to the field of terminal technology, and specifically 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 microservice 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.
[0064] Figure 1 is a block diagram of the software system architecture of a terminal device provided in an embodiment of the present application. As shown in Figure 1, the software system architecture of the terminal device can be a layered architecture. For example, the software can be divided into several layers, each with 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.
[0065] The application layer can include a series of application packages. As shown in Figure 1, the application layer can include camera, settings, skin modules, user interface (UI), third-party applications, etc. Among them, third-party applications can include wireless local area network (WLAN), music, call, Bluetooth, video, memo, and information.
[0066] In one possible implementation, applications can be developed using Java by calling the application programming interface (API) provided by the application framework layer. Developers can use the application framework layer to interact with the underlying OS layers (e.g., the hardware layer, kernel layer, etc.) to develop their own applications. The application framework layer primarily comprises a series of services and management systems for the OS. Currently, developers of various system services (also understood as the business side) use independent threads to create system service threads and auxiliary function threads. The business side can independently create system service threads and auxiliary function threads using the API provided by the application framework layer, while the OS does not exercise any control over 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 threads created by the business side to persist during runtime. Furthermore, as the number of system services increases, the number of threads in the OS will continue to increase, leading to memory usage, increased lock contention, and potentially reduced thread processing efficiency in the OS.
[0067] Furthermore, in current thread management methods, threads created by the business side lack resource attributes. This means that the OS cannot distinguish whether a thread corresponds to a central processing unit (CPU)-intensive resource or an input / output (I / O)-intensive resource. Therefore, even if the OS can manage threads, it cannot perform targeted optimization based on the thread's resource attributes.
[0068] The application framework layer provides an application programming interface and programming framework for applications in the application layer. The application framework layer includes some predefined functions. As shown in Figure 1, the application framework layer can include the activity manager, window manager, content provider, view system, telephony manager, resource manager, notification manager, etc.
[0069] 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.
[0070] The window manager manages windowed applications. It can determine the display size, determine whether a status bar is present, lock the screen, and take screenshots. Content providers store and retrieve data and make it accessible to applications. This data can include video, images, audio, incoming and outgoing calls, browsing history and bookmarks, and phone books.
[0071] The view system includes visual controls, such as those for displaying text and images. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0072] The phone manager is used to provide communication functions for terminal devices, such as call status management (including answering, hanging up, etc.).
[0073] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0074] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically, without requiring user interaction. For example, the Notification Manager can be used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include displaying text messages in the status bar, emitting alert sounds, vibrating the device, or flashing indicator lights.
[0075] The runtime includes the core library and the virtual machine. The runtime is responsible for the scheduling and management of the OS.
[0076] The core library consists of two parts: one containing the Java language's callable functions and the other containing the OS's core libraries. The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.
[0077] The system library can include multiple functional modules, such as a surface manager, a media framework, a 3D graphics processing library (such as OpenGL ES), and a 2D graphics engine (such as SGL).
[0078] The surface manager is used to manage the display subsystem and provide the fusion of two-dimensional and 3D layers for multiple applications.
[0079] The media framework supports playback and recording of a variety of common audio and video formats, as well as static image files. The media framework can support a variety of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0080] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0081] A 2D graphics engine is a drawing engine for 2D drawings.
[0082] 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.
[0083] The kernel layer is the layer between hardware and software. The kernel layer includes at least display driver, camera driver, audio driver, and sensor driver.
[0084] The hardware layer can include various sensors, such as accelerometers, gravity sensors, touch sensors, etc.
[0085] Typically, a terminal device can run multiple applications simultaneously. In simpler cases, one application corresponds to one process, while in more complex cases, one application can correspond to multiple processes. Each process has a process ID.
[0086] In light of this, embodiments of the present application provide a thread management method. This method provides a solution for managing threads from the operating system (OS). This method allows the OS to isolate the business side from the OS side, thereby preventing uncontrolled thread creation on the business side. This reduces thread redundancy within the OS, minimizes waste of system resources such as memory and scheduling, and improves thread processing and scheduling efficiency.
[0087] In addition, this method can also consider the resource types required by the system services, and distribute them 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.
[0088] The embodiments of the present application can be applied to terminal devices equipped with an OS, such as mobile phones, PCs, tablet computers, wearable devices (e.g., watches, bracelets, etc.), in-vehicle 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 understood that the embodiments of the present application do not impose any restrictions on the specific type of terminal device.
[0089] The terminal devices to which the embodiments of the present application can be applied include, but are not limited to, 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).
[0090] Figure 2 shows a schematic diagram of the hardware structure of a possible terminal device. Among them, the terminal device 200 includes components such as 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 the hardware structure of the terminal device 200 shown in Figure 2 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 shown, may combine two or more components, or may have different component configurations. The various components shown in Figure 2 can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.
[0091] The following is a detailed introduction to the various components of the terminal device 200 in conjunction with FIG2 :
[0092] The RF circuit 210 can be used to receive and transmit data during communications or calls. Specifically, after receiving downlink data from the base station, the RF circuit 210 sends it to the processor 230 for processing. Furthermore, the RF circuit 210 sends uplink data to the base station. Typically, 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, and the like.
[0093] In addition, the RF circuit 210 can also communicate with other devices via a wireless communication network. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communications (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.
[0094] The terminal device 200 can also implement communication services and interact with other terminal devices. Therefore, the terminal device 200 needs to have a data transmission function, that is, the terminal device 200 needs to include a communication module. Although Figure 2 shows communication modules such as the RF circuit 210, the Wi-Fi module 290, and the communication interface 280, it is understandable that the terminal device 200 contains at least one of the above components or other communication modules for implementing communication (such as a Bluetooth module) for data transmission.
[0095] 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 (not shown in 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 (not shown in 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 (not shown in Figure 2).
[0096] Wi-Fi technology is a short-range wireless transmission technology. The terminal device 200 can connect to an access point (AP) via the Wi-Fi module 290 to access the data network. The Wi-Fi module 290 can be used to receive and send data during the communication process.
[0097] The terminal device 200 can be physically connected to other devices via the communication interface 280. Optionally, the communication interface 280 is connected to the communication interface of the other device via a cable to achieve data transmission between the terminal device 200 and the other device.
[0098] 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., each corresponding software program or module).
[0099] 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 device.
[0100] The input unit 250 may be used to receive user input for editing operations on various types of data objects, such as numbers or characters, and to generate key signal inputs related to 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.
[0101] Among them, the touch panel 251, also known as a touch screen, can collect the user's 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.
[0102] 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.
[0103] The display unit 260 can be used to display information content input by the user or information content provided to the user, as well as 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 can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.
[0104] The processor 230 is the control center of the terminal device 200. It connects various components using various interfaces and lines. By running or executing software programs and / or modules stored in the memory 240 and calling data stored in the memory 240, it executes various functions of the terminal device 200 and processes data, 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 service side to create system service-related threads on its own can be blocked, 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 relationship between tasks and threads can be managed, as well as threads can be created and destroyed through the application framework layer. For another example, an API can be provided to the service side to specify the type of task, so that resource allocation strategies can be optimized based on the task type.
[0105] The terminal device 200 also includes a power supply 220 (such as a battery) for powering various components. Optionally, the power supply 220 can be logically connected to the processor 230 through a power management system, thereby managing charging, discharging, and power consumption through the power management system.
[0106] As shown in Figure 2, 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 for 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.
[0107] Although not shown, the terminal device 200 may further include a camera, at least one sensor, etc., which will not be described in detail here. 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.
[0108] 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.
[0109] 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 order.
[0110] It should be understood that the software system architecture of the terminal device can be as shown in Figure 1, and the hardware structure can be as shown in Figure 2, wherein 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.
[0111] In order to facilitate understanding of a thread management method provided by the present application, the implementation process of the method provided by the present application is introduced below in combination with the contents shown in Figures 3, 4a, 4b to 7.
[0112] Figure 3 is a diagram of an application framework applicable to a thread management method provided in an embodiment of the present application. The application framework layer shown in Figure 3 may include one or more parts for implementing different functions. For example, the application framework layer may include a task scheduling framework and a business party 1 related to the embodiment of the present application as shown in Figure 3; wherein, the business party 1 may be, for example, a resource manager, a power management service, or other system services, and the present application does not limit the business party 1. It can be understood that the task scheduling framework can also be understood as a system service that the application framework layer can provide. The task scheduling framework may, for example, include but is not limited to the following modules: a task management module, a thread scheduling module, and an expansion and contraction policy management module.
[0113] (1) Business Party 1, for example, can be various system services included in the application framework layer. For example, 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 addition 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.
[0114] In some possible embodiments, tasks may include, but are not limited to, power management tasks, Wi-Fi management tasks, and encryption management tasks. Taking the power management task as an example, scenarios in which system service instructions triggered by the power management service may include, but are not limited to, the following scenarios: a mobile phone triggering the activation or deactivation of power saving mode based on the battery level, or a mobile phone triggering a notification message based on the battery level, such as a notification message indicating that the battery has been charged to 80% or fully charged. For example, business party 1 may be a power management system service (also referred to as the "power management service" in this embodiment of the application). Upon receiving a service processing request from the application layer, the service content is sent to the task scheduling framework layer. Taking the Wi-Fi management task as an example, scenarios in which system service instructions triggered by the Wi-Fi service are included, but are not limited to, the following scenarios: a mobile phone triggering the connection to the Wi-Fi service in response to a user's network access operation. For example, business party 1 may be a Wi-Fi system service (also referred to as the "Wi-Fi service" in this embodiment of the application). Upon receiving a service processing request from the application layer, the service content is sent to the task scheduling framework layer. Taking the encryption management task as an example, scenarios where system service instructions triggered by the encryption system service might include, but are not limited to, the need for various applications to encrypt strings. Furthermore, task types can be categorized as CPU-intensive or I / O-intensive. CPU-intensive tasks include encryption management and Wi-Fi management, while I / O-intensive tasks include file downloads.
[0115] 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. This allows the OS side to 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 waste of system resources, and thereby improve the processing efficiency and scheduling efficiency of system services.
[0116] (2) A task management module, which can be used to provide task-related APIs, such as a task adding interface. 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 be used to complete the management of the correspondence between task types and threads; as well as 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. In the following embodiments, threads and thread pools can be used interchangeably.
[0117] In some possible embodiments, FIG4a is a possible correspondence diagram of task instances and thread instances provided in an embodiment of the present application. Task instance 1, task instance 2, and task instance 3 in FIG4a can be used to represent tasks of the same type. The task management module can, based on the task type, enable task instance 1, task instance 2, and task instance 3 to run on the same thread instance. 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 that can be used to process task instance 1, task instance 2, and task instance 3 in the OS, the processing tasks of task instance 1, task instance 2, and task instance 3 can be directly assigned to the thread instance for processing. As can be seen from FIG4a, 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.
[0118] Among them, the task instance is an instance based on the task template runtime; the thread instance is an instance based on the thread template runtime; among them, a thread instance can be implemented by a single thread, or 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.
[0119] In an embodiment of the present application, different task types may correspond to 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.
[0120] (3) Thread scheduling module, which can be used to schedule tasks to different types of threads or thread pools.
[0121] In other possible embodiments, Figure 4b is another possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application. Task instance 1, task instance 2, and task instance 3 in Figure 4b 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 instance, and perform expansion management on the thread instance; wherein expansion can be understood as creating a new thread. It is understood that after 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, compared to Figure 4a, Figure 4b shows that the OS can expand the thread instance. By adding thread instance 2, the processing efficiency and scheduling efficiency of the thread for task instances can be improved, and the throughput rate of thread instances in the OS for processing task instances can be improved. It is understood that after processing task instance 3, the thread scheduling module can promptly instruct the expansion and contraction policy management module to destroy thread instance 2 to implement thread contraction processing, thereby timely releasing system resources such as memory and scheduling. Among them, shrinking can be understood as destroying some idle threads.
[0122] 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 optimizing resource allocation strategies based on different task types, improving thread processing efficiency and resource utilization, and further improving OS response latency, throughput, and other indicators for tasks.
[0123] (4) The expansion and contraction policy management module can be used to manage the expansion and contraction of the threads running the task execution.
[0124] It can be understood that the thread scheduling module can be used to issue 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 there are task instances that need to be processed for all the established threads corresponding to the task type of the current task, 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 an expansion policy can be issued. 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.
[0125] The main thread can be understood as the thread primarily responsible for the task type assigned to it. It can be set to remain resident so that the main thread can respond to tasks in a timely manner. Slave threads other than the main thread can be recycled when they are idle, thereby avoiding the occupation and waste of system resources. It is understood that an OS can include one or more main threads.
[0126] Based on the embodiments described in Figures 3 to 4b, the method provided by the embodiments of the present application can determine the correspondence between tasks and threads based on factors such as task type, thread execution status, and whether the task is a repetitive task, thereby implementing thread scheduling. The following describes the method provided by the present application through an embodiment.
[0127] In a possible embodiment, FIG5 is a flow chart of a thread management method provided by an embodiment of the present application. The flow can be applied to a terminal device and may include the following steps:
[0128] 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 can be a task that needs to be processed and is created by the business party based on 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 can, for example, be other system services included in the application framework layer except the task scheduling framework. In another possible embodiment, the first task can also be a task that needs to be processed and is created based on an instruction from the application layer; wherein, the application layer can 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 can implement the allocation of threads or thread pools.
[0129] 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 can be given priority.
[0130] 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 and the thread of the task. 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 directly assigns it to the thread for processing.
[0131] If the judgment in step 501 is yes, the execution may proceed to step 502. If the judgment in step 501 is no, the execution may proceed to step 511. It is 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 assigned to the first thread for processing. When the first thread has a task to process, further judgment may be performed.
[0132] 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 scaling policy management module.
[0133] 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.
[0134] Step 503: Determine whether the task processed by the main thread is the first task distribution. If it is determined to be yes, proceed to step 511; if it is determined to be no, proceed to step 504.
[0135] 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 not related to the first task, it can be reallocated to other threads for processing.
[0136] Based on the processing of steps 502 and 503, the first task and its associated tasks can be processed by the same thread, thereby ensuring the efficiency of the thread's processing of 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.
[0137] 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.
[0138] Step 504: Determine whether there are other idle threads. If yes, proceed to step 509; if no, proceed to step 505.
[0139] 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.
[0140] Step 505: Determine whether the capacity expansion conditions are met; wherein the capacity expansion conditions can also be understood as the conditions for creating a new thread. If the judgment is yes, then proceed to step 506; if the judgment is no, then proceed to step 511.
[0141] Step 506: Add a second thread.
[0142] Step 507: Update the thread corresponding to the first task.
[0143] 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, thereby achieving dynamic thread scheduling.
[0144] In a possible embodiment, based on assigning a first thread to the first task in step 501, after the task scheduling framework assigns 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.
[0145] Step 509: Update the thread corresponding to the first task.
[0146] 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, thereby realizing thread scheduling.
[0147] 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.
[0148] Step 511: Distribute to the first thread. It is understood that the first thread may be a thread selected based on the task type of the first task. When the first thread meets the processing conditions for processing the first task, the first thread may process the first task. When the first thread does not meet the processing conditions for processing the first task, the second thread or the third thread may be scheduled to process the first task.
[0149] Step 512: Determine and process the reduction.
[0150] In some possible embodiments, the thread scheduling module detects the existence of idle threads in the OS based on the task instances to be processed and the task instances being processed, and then reclaims the idle threads.
[0151] In other possible embodiments, one or more main threads may be reserved for each task type, while idle threads other than the main thread may be reclaimed; the number of retained main threads may vary for different task types. It will be appreciated that when an idle slave thread is reclaimed, one or more tasks corresponding to the slave thread may be updated to be associated with the main thread corresponding to the slave thread.
[0152] In another possible embodiment, Figure 6 is another application framework diagram applicable to a thread management method provided in an embodiment of the present application. Compared with the application framework layer shown in Figure 3, the application framework layer shown in Figure 6 may not include an expansion and contraction policy management module. The application framework layer shown in Figure 6 can be applicable to application scenarios with small changes in throughput, and the terminal device can implement thread management through static allocation without the need for expansion or contraction processing. It can be understood that the implementation method of scheduling threads for tasks in this scenario can refer to the content described in Figure 5 except for steps 505 to 508. It can be implemented by assigning a first thread to the task, or scheduling it to an idle third thread, so that thread management can be achieved. The specific implementation process will not be repeated here.
[0153] Exemplary application scenarios with minimal throughput variation include, but are not limited to, large-screen processing scenarios. These scenarios primarily play audio and video content, so threads in the large-screen operating system are primarily dedicated to decoding audio and video data, without requiring CPU-intensive tasks. In one possible embodiment, the large-screen operating system can reserve multiple threads for decoding tasks to ensure efficient processing.
[0154] For example, Figure 7 is another possible correspondence diagram between task instances and thread instances provided in an embodiment of the present application. Task type 1-instance 1, task type 1-instance 2, and task type 1-instance 3 in Figure 7 can run on thread instance 1, and task type 2-instance 1 and task type 2-instance 2 in Figure 7 can 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 dispatch task type 1-instance 1 to thread instance 1 for processing; in response to the task processing request of task type 1-instance 2, task type 1-instance 2 can be dispatched to thread instance 1 for processing; in response to the task processing request of task type 1-instance 3, task type 1-instance 3 can be dispatched to thread instance 1 for processing. And, in response to the task processing request of task type 2-instance 1, the OS can dispatch task type 2-instance 1 to thread instance 2 for processing; in response to the task processing request of task type 2-instance 2, task type 2-instance 2 can be dispatched to thread instance 2 for processing.
[0155] In this way, static thread allocation management within the operating system avoids the implementation and runtime scheduling costs associated with dynamic scaling. Furthermore, the operating system can retain a corresponding thread instance for each task type, ensuring that each task type has a corresponding thread capable of handling it, avoiding the thread redundancy problem caused by creating a new thread for each task.
[0156] In another possible implementation, FIG8 is another flow diagram of a thread management method provided in an embodiment of the present application. This flow can be applied to the application framework layer of the operating system of the terminal device and may include the following steps:
[0157] 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. Exemplarily, the first instruction may be, for example, an instruction sent by business party 1 as shown in FIG3 , or may be, for example, an instruction sent by the application layer. It is understandable that the 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.
[0158] Step 802: Based on the task type and the first correspondence between the first task and the task, dispatch the first task to a first thread or a first thread pool for processing; wherein the first correspondence indicates the correspondence between the task type and the thread or thread pool. For example, the thread can be assigned to the first task using the process shown in FIG5 , which is not further described here.
[0159] 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. For example, steps 501 and 512 executed by the terminal device in the embodiment shown in Figure 5 are executed. Alternatively, steps 801 and 802 executed by the terminal device in the embodiment shown in Figure 8 are executed.
[0160] Based on the above embodiments, the present application further provides a terminal device, comprising at least one processor and at least one memory, wherein the at least one memory stores computer program instructions. When the terminal device is running, the at least one processor performs the functions performed by the terminal device in each method described in the embodiments of the present application. For example, steps 501 and 512 performed by the terminal device in the embodiment shown in FIG5 are performed. Alternatively, steps 801 and 802 performed by the terminal device in the embodiment shown in FIG8 are performed.
[0161] Based on the above embodiments, the present application also provides a computer program product, which includes: a computer program (also called code, or instructions), which, when executed, enables a computer to execute the methods described in the embodiments of the present application.
[0162] 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.
[0163] 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 various methods described in the embodiments of the present application.
[0164] Based on the above embodiments, the present application provides a chip system, which includes a processor for supporting a computer device to implement the various methods described in the embodiments of the present application. In one possible design, the chip system also includes a memory, which is used to store the necessary programs and data for 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, system, or computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take 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 code.
[0165] 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 produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the function specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0166] 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 operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0167] 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 computer-implemented processing, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0168] Obviously, those skilled in the art may make various modifications and variations to this application without departing from the scope of protection of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is 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 there is no condition for creating a new thread.
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 line Processing or first thread pool 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.
Citation Information
Patent Citations
Thread pool management method and device
CN105760234A
Multi-thread task processing method and device and storage medium
CN109582455A
Thread management method and device
CN113535251A
Thread pool management for multiple applications
US20210208944A1