CN111666136A - Thread processing method and device, electronic equipment and storage medium - Google Patents

Thread processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN111666136A
CN111666136A CN202010334773.9A CN202010334773A CN111666136A CN 111666136 A CN111666136 A CN 111666136A CN 202010334773 A CN202010334773 A CN 202010334773A CN 111666136 A CN111666136 A CN 111666136A
Authority
CN
China
Prior art keywords
thread
sub
cpu
priority
child
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010334773.9A
Other languages
Chinese (zh)
Inventor
苟亚明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202010334773.9A priority Critical patent/CN111666136A/en
Publication of CN111666136A publication Critical patent/CN111666136A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Telephone Function (AREA)

Abstract

The embodiment of the invention provides a thread processing method and device, electronic equipment and a storage medium. The thread processing method comprises the following steps: acquiring the priority of running sub-threads and the scheduling frequency of the sub-threads to a CPU (central processing unit) in an application program in a background running state; and executing communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU. In the embodiment of the invention, the scheduling of the sub thread to the CPU is controlled by controlling the communication between the sub thread and the CPU, namely the consumption of the application program to the memory of the mobile terminal is controlled.

Description

Thread processing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a method and an apparatus for processing a thread, an electronic device, and a storage medium.
Background
With the rapid development of internet technology, more and more applications are applied to mobile terminals, and the functions of the applications are more and more abundant. The user can acquire various information through the application, such as watching a video, listening to music, and the like through the application.
In the running process of the application program, a plurality of threads are run, and each thread controls the hardware device to execute corresponding operations through a scheduling CPU (central processing Unit). During the process of scheduling the CPU to execute the corresponding operation, the threads generate a large amount of data, and the data is cached in the memory, thereby causing the application program to consume the memory of the mobile terminal during the process of running the threads.
Disclosure of Invention
The embodiment of the invention aims to provide a thread processing method, a thread processing device, electronic equipment and a storage medium, so as to control the consumption of an application program on a mobile terminal memory. The specific technical scheme is as follows:
in a first aspect of the present invention, there is provided a thread processing method, including:
acquiring the priority of running sub-threads and the scheduling frequency of the sub-threads to a CPU (central processing unit) in an application program in a background running state;
and executing communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the priority of the sub-thread is lower than a preset first priority threshold, closing the sub-thread.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, closing the sub-thread.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the priority of the sub-thread is lower than a preset first priority threshold and the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, closing the sub-thread.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the priority of the sub-thread is higher than a preset second priority threshold, keeping the sub-thread resident.
In a second aspect of the present invention, there is also provided a thread processing apparatus including:
the device comprises an acquisition module, a scheduling module and a processing module, wherein the acquisition module is used for acquiring the priority of a running sub-thread and the scheduling frequency of the sub-thread to a CPU (central processing unit) in an application program in a background running state;
and the execution module is used for executing the communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
Optionally, the execution module includes: and the first closing unit is used for closing the sub-thread when the priority of the sub-thread is lower than a preset first priority threshold.
Optionally, the execution module includes: and the second closing unit is used for closing the sub-thread when the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread.
Optionally, the execution module includes: and the third closing unit is used for closing the sub-thread when the priority of the sub-thread is lower than a preset first priority threshold and the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread.
Optionally, the execution module includes: and the holding unit is used for holding the sub-thread to be resident when the priority of the sub-thread is higher than a preset second priority threshold.
In another aspect of the present invention, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus; a memory for storing a computer program; and a processor for implementing any of the above-described thread processing methods when executing the program stored in the memory.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which when run on a computer, cause the computer to execute any of the thread processing methods described above.
In yet another aspect of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the thread processing methods described above.
According to the thread processing method, the thread processing device, the electronic equipment and the storage medium, the priority of the sub-thread which is running in the application program in the background running state and the scheduling frequency of the sub-thread to the CPU are obtained; and executing communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU. Therefore, in the embodiment of the invention, for the sub-thread running in the application program in the background running state, according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU, the communication between the sub-thread and the CPU can be controlled, so that the scheduling of the sub-thread to the CPU is controlled, that is, the consumption of the application program to the memory of the mobile terminal is controlled. For example, part of the sub-threads can be closed according to the priority of the sub-threads and/or the scheduling frequency of the CPU, and the closed sub-threads do not schedule the CPU, so that data is not generated to occupy a memory, and memory consumption of the mobile terminal can be reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1 is a schematic diagram of communication between an application and a CPU in an embodiment of the present invention.
Fig. 2 is a schematic diagram of memory ratio of an application according to an embodiment of the present invention.
Fig. 3 is a flowchart illustrating steps of a thread processing method according to an embodiment of the present invention.
FIG. 4 is a flowchart illustrating another thread processing method according to an embodiment of the present invention.
Fig. 5 is a schematic diagram of an internal operating principle of RunLoop in the embodiment of the present invention.
Fig. 6 is a schematic diagram of a pattern included in RunLoop according to an embodiment of the present invention.
Fig. 7 is a flowchart of a thread processing method according to an embodiment of the present invention.
Fig. 8 is a block diagram of a thread processing apparatus according to an embodiment of the present invention.
Fig. 9 is a block diagram of another thread processing apparatus according to an embodiment of the present invention.
Fig. 10 is a block diagram of an electronic device in an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention.
Referring to fig. 1, a schematic diagram of communication between an application and a CPU in an embodiment of the present invention is shown. As shown in fig. 1, when an application is installed, the application is loaded into the memory. When the application program is running, the read-write interaction between the CPU and the memory is frequent, and when the application program loaded into the memory executes a code instruction, the CPU can be scheduled to control hardware equipment, such as display, sound, Bluetooth, positioning, background activity and the like of the hardware equipment. The method includes the steps that a large number of threads are created in the running process of an application program, a CPU is scheduled to call corresponding operations of the threads in the running process of the threads, so that hardware equipment is controlled to execute corresponding operations, the operations generate a large amount of data (such as intermediate variables and the like), and the data are cached in the hardware equipment, so that a large amount of memory is occupied. For example, a user copies and pastes a text in an application program, and then enters the program to trigger a popup, wherein some resources in the popup, such as pictures and characters, are cached in a memory.
Referring to fig. 2, a memory ratio diagram of an application program in the embodiment of the present invention is shown. As shown in fig. 2, each application occupies a certain proportion of memory according to the usage of the application, and many applications are used less but have a larger memory. Because the frequency of the application program for scheduling the CPU is high, the generated cache content is more, if the CPU is not effectively managed, a lot of useless memory is occupied, and when the memory is occupied more, the use of the application program by a user is influenced.
The embodiment of the invention considers the problem of manufacturers and communication specifications on a hardware level, and common application program developers can not optimize the problem, so the optimization of the hardware level is not considered; in the software level, although the mobile terminal provides an upper API (Application Programming Interface) for memory management, the memory management of the Application program requires a developer to implement a set of mechanism by himself, and the Application program does not form a general development specification at present, so the optimization in this respect is not considered. The threads of the application include a main thread and a sub-thread. The embodiment of the invention provides that the running sub-thread of the application program after entering the background is managed, and the communication between the sub-thread and the CPU is controlled according to the priority of the sub-thread running at the background and/or the scheduling frequency of the sub-thread to the CPU, so that the consumption of the application program to the memory of the mobile terminal is controlled. .
In the embodiment of the present invention, the mobile terminal may be a mobile phone, a tablet computer, a wearable device, and the like, and the operating system of the mobile terminal may be an Android (Android) system, an iOS system, and the like, which is not limited in this embodiment of the present invention.
In the following, the thread processing method is described in detail with reference to various embodiments.
Fig. 3 is a flowchart illustrating steps of a thread processing method according to an embodiment of the present invention. The thread processing method of the embodiment of the invention can be applied to the memory management module of the mobile terminal.
As shown in fig. 3, the thread processing method in the embodiment of the present invention may include the following steps:
step 301, acquiring the priority of a running sub-thread and the scheduling frequency of the sub-thread to the CPU in an application program in a background running state.
When an application program runs, a plurality of threads are created, including a main thread and a sub-thread. And respectively scheduling the CPU in each thread to call the operation corresponding to the thread, and correspondingly controlling the hardware equipment by executing the operation.
For an application, the server may set the priority of each sub-thread after the application enters the background according to the user information of the application, such as the age, the use habit, and the like of the user. For example, when music is played in the background, the priority of sub-threads such as downloading and positioning can be reduced. In the embodiment of the invention, the priority of each sub-thread after the application program enters the background can be acquired from the server at any applicable time, and the acquired priority is locally stored. For example, the information may be obtained when the application program is started, or obtained in a process that the application program runs in the foreground, or obtained when the application program is about to enter a background running state, or obtained when communication between the sub-thread and the CPU needs to be executed according to the priority of the sub-thread, and the like, which is not limited in this embodiment of the present invention.
When the application program is about to enter the background, some sub-threads may be automatically closed (such as the sub-thread for controlling the popup window, etc.), and some sub-threads may continue to run in the background. Therefore, the currently running sub-threads can be acquired when the application program enters the background, and the currently running sub-threads are the sub-threads which can continue to run after the application program enters the background. When the sub-thread of the application program in the background running state needs to be controlled, the priority of the running sub-thread in the application program in the background running state and the scheduling frequency of the sub-thread to the CPU can be acquired.
And 302, executing communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
In the embodiment of the invention, aiming at the sub-thread running in the application program in the background running state, the communication between the sub-thread and the CPU can be controlled according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU, so that the scheduling of the sub-thread to the CPU is controlled, namely the consumption of the application program to the memory of the mobile terminal is controlled. For example, part of the sub-threads can be closed according to the priority of the sub-threads and/or the scheduling frequency of the sub-threads to the CPU, and the closed sub-threads do not schedule the CPU, so that data is not generated to occupy a memory, and memory consumption of the mobile terminal can be reduced.
FIG. 4 is a flowchart illustrating another thread processing method according to an embodiment of the present invention.
As shown in fig. 4, the thread processing method in the embodiment of the present invention may include the following steps:
step 401, acquiring the priority of a running sub-thread and the scheduling frequency of the sub-thread to the CPU in an application program in a background running state.
The application program comprises a plurality of service modules, such as a popup module, a download module, a play module and the like. Each service module can run a plurality of sub-threads, for example, the popup module can run a window attribute setting sub-thread, a window display time setting sub-thread, and the like. In the header file of each service module of the application program, a sub-thread which runs after the application program enters the background can be recorded. Therefore, the sub-thread which runs after the application program enters the background can be obtained from the header file of each service module locally.
And aiming at the sub-thread running in the application program in the background running state, acquiring the priority of the sub-thread and the scheduling frequency of the sub-thread on the CPU.
For the priorities of the sub-threads, in an implementation manner, the priorities of the sub-threads in the background running state of the application program can be obtained from the server in advance and stored locally, and based on the fact that the priorities can be updated by research and development personnel, the latest priorities can be obtained from the server regularly and the locally stored priorities are updated. The priority of the running child thread in the application in the background running state can be obtained locally. In another implementation, the priority of the sub-thread running in the application program in the background running state can be acquired from the server.
Aiming at the scheduling frequency of the CPU by the sub-thread, whether the sub-thread schedules the CPU can be monitored in real time, and the scheduling frequency is further determined. Each thread may have a thread object that is created when the thread is first acquired and destroyed when the thread is finished. The thread object may manage the thread, for example, the thread object may cyclically listen for a trigger event that triggers the thread to schedule the CPU, and when the trigger event is listened to, the thread may be triggered to schedule the CPU. The trigger event may include Port, Source, Selector, Timer, and other events. The Source events may include Source0 and Source1, Source0 may represent UI (User Interface) operational events, and Source1 may represent inter-Port based inter-thread communication events. Thus, it may be monitored whether a triggering event occurs that triggers the child thread to schedule the CPU, and if the triggering event occurs, it is determined that the child thread schedules the CPU.
And 402, closing part of the sub-threads according to the priority of the sub-threads and/or the scheduling frequency of the sub-threads to the CPU.
When the application program is started, a main thread is created, and after the main thread is created, a thread object corresponding to the main thread is created. Since the application cannot receive the user's UI operations while running in the background, the thread object does not hear the UI operation events, but the application can invoke the application programming interface to simulate these events, and the UI operation events typically occur in the main thread. Therefore, in an optional implementation manner, the occurrence of the UI operation event in the thread object of the main thread can be prohibited, so that the application program is prevented from internally calling events such as touch, slide, and pinch while running in the background, the operation triggered by the UI operation event is avoided from being called, and the consumption of memory by data generated by calling the operation is reduced.
In an alternative implementation, for a sub-thread with a lower priority, the lower priority indicates a low importance, and the sub-thread is closed with less influence on the use of the user, so that the sub-thread can be selected to be closed. For example, when music is played in the background, the priority of the sub-thread such as downloading and positioning is low. In the embodiment of the present invention, a first priority threshold may be preset, and when the priority of a sub-thread is lower than the first priority threshold, the importance of the sub-thread may be considered to be lower. Therefore, the embodiment of the present invention may close the child thread when the priority of the child thread is lower than the preset first priority threshold. For the specific value of the first priority threshold, a person skilled in the art may set any applicable value according to practical experience, and the embodiment of the present invention is not limited thereto. For example, the first priority threshold may be set to 3, 5, 6, 8, etc.
In an optional implementation manner, for a sub-thread with a high scheduling frequency for the CPU, since the scheduling frequency for the CPU is high, the memory consumption of data generated by the sub-thread is high, and the sub-thread may be selectively turned off. In the embodiment of the invention, the frequency threshold corresponding to each sub-thread can be preset, and when the scheduling frequency of the sub-thread to the CPU reaches the corresponding frequency threshold, the scheduling frequency of the sub-thread to the CPU can be considered to be higher. Therefore, in the embodiment of the present invention, when the scheduling frequency of the sub-thread to the CPU reaches the preset frequency threshold corresponding to the sub-thread, the sub-thread may be closed. For the specific value of the frequency threshold, a person skilled in the art may set any applicable value according to practical experience, and the embodiment of the present invention is not limited thereto.
In an alternative implementation, the priority of the sub-thread and the scheduling frequency of the sub-thread to the CPU may be considered at the same time, and the sub-thread to be closed may be selected. Therefore, in the embodiment of the present invention, when the priority of the sub-thread is lower than a preset first priority threshold, and the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, the sub-thread may be closed.
And step 403, keeping a part of sub threads resident according to the priority of the sub threads.
For a child thread with a higher priority, a higher priority indicates a higher importance, and the child thread can be kept resident because it has a greater influence on the use of the user after the child thread is finished. In the embodiment of the present invention, a second priority threshold may be preset, and when the priority of a sub-thread is higher than the second priority threshold, the importance of the sub-thread may be considered to be higher. Therefore, the embodiment of the present invention may keep the child thread resident when the priority of the child thread is higher than the preset second priority threshold. In implementation, the residency of the sub-threads can be maintained by periodically injecting trigger events and the like for the sub-threads with the priority higher than the preset second priority threshold. Through the mode, the influence on the use of the user after the sub-thread is finished can be avoided, and the user experience is improved. For the specific value of the second priority threshold, a person skilled in the art may set any suitable value according to practical experience, and the embodiment of the present invention is not limited thereto.
Next, a mobile terminal of the iOS system will be described as an example.
In iOS development, the underlying event handling mechanisms are typically maintained by RunLoop in the Core Foundation framework (the Core Foundation framework is a set of C language interfaces that provide basic data management and service functions for iOS applications), each thread having a RunLoop object. Referring to fig. 5, a schematic diagram of an internal operating principle of RunLoop in the embodiment of the present invention is shown. As shown in fig. 5, the internal implementation of the RunLoop object is a loop, and whether a trigger event is generated outside is continuously detected, the RunLoop object under one thread may monitor trigger events such as a Port (e.g., handlePort operation in fig. 5), a Source (e.g., cuetomSrc custom Source in fig. 5), a Selector (e.g., mySelector selection in fig. 5), and a Timer (Timer started). In the circulation process, when receiving Input sources or Timer sources, the RunLoop object gives the corresponding processing party to process, and the Input sources include Port inputs, Custom inputs and the like.
The RunLoop object has various modes in the bottom layer for distinguishing events. Referring to fig. 6, a schematic diagram of a mode included in RunLoop in the embodiment of the present invention is shown. As shown in fig. 6, each RunLoop object corresponds to a thread (e.g., p _ thread). The RunLoop object comprises a plurality of modes, and each Mode comprises a plurality of sources, an Observer and a Timer. The RunLoop object only executes a task under one Mode currently, if the Mode needs to be switched, the RunLoop object needs to be exited, and then one Mode is appointed to enter again, so that the RunLoop object is mainly used for separating Source, Timer and Observer in different groups and enabling the Source, the Timer and the Observer to be not influenced mutually.
The ability of a RunLoop object to handle triggering events is exploited to control thread scheduling CPUs. Referring to fig. 7, a flowchart of a thread processing method in an embodiment of the present invention is shown. As shown in fig. 7, the thread processing method may include the following processes:
1. the application starts.
2. And acquiring each service module. For example, information related to the moudlet _ A, Moudle _ B, Moudle _ C is obtained.
3. And judging whether each service module is injected into the thread list. The embodiment of the invention can provide the thread list for storing the sub-threads which run after the application program enters the background. If each service module has injected its child thread running after the application enters the background into the thread list, process 6 is executed, if there are still service modules that have not been injected, process 4 is executed.
4. And acquiring a sub-thread of the service module running in the background from a header file of the un-injected service module.
5. And injecting the acquired sub-thread into a thread list.
6. And acquiring the priority of each sub-thread in the thread list, and generating the global dictionary according to the priority sequence.
7. The application enters the background.
8. And acquiring the RunLoop object of the sub-thread with higher priority. The higher priority may mean that the priority is higher than the preset second priority threshold.
9. And injecting a self-defined trigger event (such as a source event and the like) or switching the Mode to ensure that the RunLoop object of the sub-thread with higher priority survives.
10. And judging whether the RunLoop object of the sub-thread with lower priority and/or higher scheduling frequency to the CPU runs or not. If so, perform process 11; if not, process 13 is performed. The lower priority may mean that the priority is lower than the preset first priority threshold, and the higher scheduling frequency of the CPU may mean that the scheduling frequency of the CPU reaches the preset frequency threshold corresponding to the sub thread.
11. And detecting whether the RunLoop object of the sub-thread with lower priority and/or higher scheduling frequency of the CPU calls the Source0/Source1/Timer frequently. If so, perform process 12; if not, process 13 is performed.
12. The RunLoop object of the child thread is stopped. For example, in the process of using video software, after an application program enters a background, a user does not want to occupy more memory, and then the RunLoop object for the function is stopped playing.
13. And keeping the background program running.
The embodiment of the invention can reduce the data volume generated by the running sub-thread in the application program in the background running state, and reduce the memory consumption of the mobile terminal. For example, when entering the background, the information-based service module performs page refreshing, and if it is detected that the priority of the sub-thread corresponding to the service module is low, the page refreshing is stopped or the refreshing frequency is reduced, so that the occupation of the cache generated when the page is refreshed and the picture is loaded on the memory is reduced. For another example, the embedded point statistics may perform object creation and send a request, when entering the background, the behavior operation of the user may be recorded, and then the request is sent, and if the priority of the sub-thread is low, creation and destruction of the dotting object may be avoided. For another example, when playing a video in the background, the user enters the background to switch to play the picture quality, so that the memory required for loading each frame of picture is reduced, and the user enters the foreground to switch to the previous picture quality.
Fig. 8 is a block diagram of a thread processing apparatus according to an embodiment of the present invention.
As shown in fig. 8, the thread processing apparatus in the embodiment of the present invention may include the following modules:
an obtaining module 801, configured to obtain, in an application program in a background running state, a priority of a running child thread and a scheduling frequency of the child thread to a CPU.
And the execution module 802 is configured to execute communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
In the embodiment of the invention, aiming at the sub-thread running in the application program in the background running state, the communication between the sub-thread and the CPU can be controlled according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU, so that the scheduling of the sub-thread to the CPU is controlled, namely the consumption of the application program to the memory of the mobile terminal is controlled.
Fig. 9 is a block diagram of another thread processing apparatus according to an embodiment of the present invention.
As shown in fig. 9, the thread processing apparatus in the embodiment of the present invention may include the following modules:
an obtaining module 901, configured to obtain, in an application program in a background running state, a priority of a running child thread and a scheduling frequency of the child thread to a CPU.
And the executing module 902 is configured to execute communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
Optionally, the executing module 902 includes: a first closing unit 9021, configured to close the sub-thread when the priority of the sub-thread is lower than a preset first priority threshold.
Optionally, the executing module 902 includes: and a second closing unit 9022, configured to close the sub-thread when the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread.
Optionally, the executing module 902 includes: a third closing unit 9023, configured to close the sub-thread when the priority of the sub-thread is lower than a preset first priority threshold and a scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread.
Optionally, the executing module 902 includes: a holding unit 9024, configured to hold the child thread as resident when the priority of the child thread is higher than a preset second priority threshold.
The embodiment of the invention can reduce the data volume generated by the running sub-thread in the application program in the background running state, and reduce the memory consumption of the mobile terminal.
The embodiment of the present invention further provides an electronic device, as shown in fig. 10, including a processor 1001, a communication interface 1002, a memory 1003 and a communication bus 1004, where the processor 1001, the communication interface 1002 and the memory 1003 complete mutual communication through the communication bus 1004.
A memory 1003 for storing a computer program;
the processor 1001 is configured to implement the following steps when executing the program stored in the memory 1003:
acquiring the priority of running sub-threads and the scheduling frequency of the sub-threads to a CPU (central processing unit) in an application program in a background running state;
and executing communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the priority of the sub-thread is lower than a preset first priority threshold, closing the sub-thread.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, closing the sub-thread.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the priority of the sub-thread is lower than a preset first priority threshold and the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, closing the sub-thread.
Optionally, the performing, according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU, communication between the child thread and the CPU includes: and when the priority of the sub-thread is higher than a preset second priority threshold, keeping the sub-thread resident.
The communication bus mentioned in the above terminal may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the terminal and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
In yet another embodiment of the present invention, a computer-readable storage medium is further provided, which has instructions stored therein, and when the instructions are executed on a computer, the instructions cause the computer to execute the thread processing method described in any one of the above embodiments.
In yet another embodiment, the present invention further provides a computer program product containing instructions which, when run on a computer, cause the computer to perform the thread processing method described in any of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (8)

1. A method for processing a thread, comprising:
acquiring the priority of running sub-threads and the scheduling frequency of the sub-threads to a CPU (central processing unit) in an application program in a background running state;
and executing communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
2. The method according to claim 1, wherein the performing communication between the child thread and the CPU according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU comprises:
and when the priority of the sub-thread is lower than a preset first priority threshold, closing the sub-thread.
3. The method according to claim 1, wherein the performing communication between the child thread and the CPU according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU comprises:
and when the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, closing the sub-thread.
4. The method according to claim 1, wherein the performing communication between the child thread and the CPU according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU comprises:
and when the priority of the sub-thread is lower than a preset first priority threshold and the scheduling frequency of the sub-thread to the CPU reaches a preset frequency threshold corresponding to the sub-thread, closing the sub-thread.
5. The method according to claim 1, wherein the performing communication between the child thread and the CPU according to the priority of the child thread and/or the scheduling frequency of the child thread to the CPU comprises:
and when the priority of the sub-thread is higher than a preset second priority threshold, keeping the sub-thread resident.
6. A thread processing apparatus, comprising:
the device comprises an acquisition module, a scheduling module and a processing module, wherein the acquisition module is used for acquiring the priority of a running sub-thread and the scheduling frequency of the sub-thread to a CPU (central processing unit) in an application program in a background running state;
and the execution module is used for executing the communication between the sub-thread and the CPU according to the priority of the sub-thread and/or the scheduling frequency of the sub-thread to the CPU.
7. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method of any one of claims 1 to 5 when executing a program stored in a memory.
8. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN202010334773.9A 2020-04-24 2020-04-24 Thread processing method and device, electronic equipment and storage medium Pending CN111666136A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010334773.9A CN111666136A (en) 2020-04-24 2020-04-24 Thread processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010334773.9A CN111666136A (en) 2020-04-24 2020-04-24 Thread processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN111666136A true CN111666136A (en) 2020-09-15

Family

ID=72382977

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010334773.9A Pending CN111666136A (en) 2020-04-24 2020-04-24 Thread processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111666136A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000020323A (en) * 1998-04-27 2000-01-21 Sony Corp Device and method for scheduling and storage medium
US20100274530A1 (en) * 2009-04-28 2010-10-28 Chi Mei Communication Systems, Inc. System and method for analyzing a usage rate of a central processing unit in a mobile device
CN104850460A (en) * 2015-06-02 2015-08-19 上海斐讯数据通信技术有限公司 Service program thread management method
CN109324878A (en) * 2018-09-20 2019-02-12 郑州云海信息技术有限公司 A kind of control method and relevant device of process CPU usage

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000020323A (en) * 1998-04-27 2000-01-21 Sony Corp Device and method for scheduling and storage medium
US20100274530A1 (en) * 2009-04-28 2010-10-28 Chi Mei Communication Systems, Inc. System and method for analyzing a usage rate of a central processing unit in a mobile device
CN104850460A (en) * 2015-06-02 2015-08-19 上海斐讯数据通信技术有限公司 Service program thread management method
CN109324878A (en) * 2018-09-20 2019-02-12 郑州云海信息技术有限公司 A kind of control method and relevant device of process CPU usage

Similar Documents

Publication Publication Date Title
CN109992310B (en) Application program keep-alive method, device, computer equipment and storage medium
CN109698979B (en) Video playing method and device and electronic equipment
CA2988269C (en) Opportunistic multitasking
CN106383712B (en) Toast component implementation method and system
CN108762831A (en) Application program preloads method, apparatus, storage medium and terminal
CN113395572B (en) Video processing method and device, storage medium and electronic equipment
CN109254849B (en) Application program running method and device
US20170060654A1 (en) Providing application operational insights to users based on crowd sourced performance metrics for operational states
CN111708655A (en) Application crash processing method, device and system
CN106844026B (en) Method and system for cleaning terminal equipment process
CN111182019B (en) Cross-platform communication method and device and electronic equipment
CN111666516A (en) Page loading method and device, electronic equipment and storage medium
CN111552567A (en) Thread management method and device, electronic equipment and storage medium
WO2017162052A1 (en) Operation method and device for mobile terminal
CN115562744A (en) Application program loading method and electronic equipment
CN111666136A (en) Thread processing method and device, electronic equipment and storage medium
CN116841713A (en) Task scanning method, device, electronic equipment and storage medium
CN116244471A (en) Player instance management method and device, electronic equipment and storage medium
CN109981873B (en) Address book permission opening method and device and electronic equipment
CN113114731B (en) Task processing method, device, server and storage medium
CN113568748B (en) Application process processing method and device, storage medium and electronic equipment
CN113467854B (en) Application program starting method and device, electronic equipment and storage medium
CN113407103B (en) Music playing control method and terminal equipment
CN114461360A (en) Thread control method, thread control device, terminal and storage medium
CN113849195A (en) Application program loading method and device, storage medium and terminal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination