CN117707755A - Thread identifier distribution method, electronic equipment and storage medium - Google Patents

Thread identifier distribution method, electronic equipment and storage medium Download PDF

Info

Publication number
CN117707755A
CN117707755A CN202310851575.3A CN202310851575A CN117707755A CN 117707755 A CN117707755 A CN 117707755A CN 202310851575 A CN202310851575 A CN 202310851575A CN 117707755 A CN117707755 A CN 117707755A
Authority
CN
China
Prior art keywords
thread
identification
target
key
identifier
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
CN202310851575.3A
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.)
Honor Device Co Ltd
Original Assignee
Honor Device 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 Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202310851575.3A priority Critical patent/CN117707755A/en
Publication of CN117707755A publication Critical patent/CN117707755A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a thread identifier distribution method, electronic equipment and a storage medium, relates to the field of thread scheduling, and can distribute fixed thread identifiers for key threads. The method is applied to the electronic equipment and specifically comprises the following steps: when a target thread is created, determining thread information of the target thread; determining a thread detection result based on the thread information of the target thread; the thread detection result is used for indicating that the target thread is a critical thread, or the thread detection result is used for indicating that the target thread is not a critical thread; under the condition that the thread detection result is used for indicating that the target thread is a key thread, determining a first thread identification of the target thread based on thread information of the target thread and key thread identification allocation data; the key thread identification allocation data comprises thread information of a plurality of key threads and identification allocation data; the identifier allocation data is used for indicating the electronic equipment to allocate a fixed thread identifier for the key thread; the creation of the target thread is completed based on the first thread identification.

Description

Thread identifier distribution method, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of charging control, and in particular, to a thread identifier allocation method, an electronic device, and a storage medium.
Background
With the rapid development of electronic equipment technology, electronic equipment such as mobile phones and the like are increasingly called as indispensable use tools. In the process that the user uses the electronic device, some key scenes (such as a game scene, a video playing scene, a voice call scene and the like) which are important for the user need to have good enough fluency (particularly, the fluency of the system) of the electronic device, so that the use experience of the user is ensured. In order to ensure the fluency of the electronic device in the key scene, a specific optimization strategy needs to be implemented based on the available resources and the use requirements of the current electronic device. The optimization policy may specifically be a setting (specifically may be an adjustment) of priority (e.g., priority of execution and priority of use of resources, etc.) or affinity (referring to an occupied configuration of processor resources of an electronic device) to a critical thread (e.g., a surfaceflinger thread strongly dependent on execution of a game picture in a game scene) that has a strong dependency on the critical scene. The setting of the priority or affinity of the critical thread is based on the thread identification (thread identity document, TID) of the critical thread. Based on this, accurate acquisition of thread identification of critical threads is a primary focus of optimization strategies of electronic devices for fluency.
Disclosure of Invention
In the related art, since the electronic device is running, the thread identifier allocated to the same thread by the electronic device may be different for each time the thread runs. Therefore, for a certain critical thread, it takes a long time to acquire the thread identification of the critical thread each time, and the acquisition efficiency is slow.
In view of the above technical problems, embodiments of the present application provide a thread identifier allocation method, an electronic device, and a storage medium, which can allocate a fixed thread identifier to a specific critical thread, so that the thread identifier of the critical thread can be accurately and quickly obtained when the critical thread identifier needs to be obtained later.
In order to achieve the above purpose, the embodiments of the present application adopt the following technical solutions:
in a first aspect, the present application provides a thread identifier allocation method, which is applied to an electronic device. The method comprises the following steps: when the electronic equipment creates a target thread, determining thread information of the target thread; the thread information comprises a thread name and a process name of a process to which the thread information belongs; the electronic equipment determines a thread detection result based on the thread information of the target thread; the thread detection result is used for indicating that the target thread is a critical thread, or the thread detection result is used for indicating that the target thread is not a critical thread; under the condition that the thread detection result is used for indicating that the target thread is a key thread, the electronic equipment determines a first thread identification of the target thread based on thread information of the target thread and key thread identification allocation data; the key thread identification allocation data comprises thread information of a plurality of key threads and identification allocation data; the identifier allocation data is used for indicating the electronic equipment to allocate a fixed thread identifier for the key thread; the electronic device completes creation of the target thread based on the first thread identification.
Based on the technical scheme provided by the embodiment of the application, the data can be allocated based on the pre-configured key thread identification, and the key thread can be allocated with a fixed thread identification when being created each time. The key thread identifier allocation data may be used to guide allocation of the thread identifier of the key thread, and fix the thread identifier of the allocated key thread. In this way, according to the technical scheme, the fixed thread identifier can be allocated to the specific key thread based on the pre-configured key thread identifier allocation data, so that when the key thread identifier needs to be acquired by the subsequent electronic equipment, the thread identifier of the key thread can be accurately and rapidly acquired, and the acquisition efficiency of the thread identifier of the key thread is improved. And furthermore, an optimization strategy aiming at improving the smoothness of the system based on the thread identification of the key thread is smoothly implemented, and the use experience of a user is improved.
In one possible design manner of the first aspect, the determining, by the electronic device, a thread detection result based on thread information of the target thread includes: the electronic device determines a thread detection result based on the thread information of the target thread and the thread information of the plurality of key threads in the key thread identification allocation data.
Therefore, the thread detection result of whether the target thread is the key thread can be accurately determined by utilizing the pre-configured key thread identification allocation data.
In one possible design manner of the first aspect, the determining, by the electronic device, a thread detection result based on the thread information of the target thread and the thread information of the plurality of critical threads in the critical thread identification allocation data includes: if the thread information of the first key thread is the same as the thread information of the target thread in the thread information of the plurality of key threads in the key thread identification allocation data, the thread detection result is used for indicating that the target thread is the key thread; if the thread information of any one of the key threads does not exist in the thread information of the plurality of key threads in the key thread identification allocation data and the thread information of the target thread are the same, the thread detection result is used for indicating that the target thread is not the key thread.
Based on the implementation scheme, whether the target thread is a key thread can be accurately determined, and a basis is provided for the execution of the subsequent threads.
In one possible design manner of the first aspect, the identifier allocation data includes a key identifier allocation range of a process to which each of the plurality of key threads belongs, where the key identifier allocation range is used to indicate a range of thread identifiers available to the key thread under the process; the electronic device determines a first thread identification of the target thread based on thread information and key thread identification allocation data of the target thread, including: under the condition that the thread identification of the target thread does not exist in the key thread identification allocation data, the electronic equipment determines the thread identification to be allocated in the key identification allocation range corresponding to the target thread from the identification allocation data; and the electronic equipment module determines a first thread identification of the target thread from all the thread identifications to be allocated according to a preset rule.
Based on the technical scheme, the electronic device can allocate a fixed thread identifier for the target thread of the key thread based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data, and the thread identifier is embodied in specific data (namely, the key thread identifier allocation data). Thus, when the thread identification of a certain key thread is needed at any time later, the thread identification of the key thread can be obtained from the key thread identification allocation data, so that the operation (such as optimizing strategy) which needs to be implemented based on the thread identification of the key thread can be smoothly implemented.
In one possible design manner of the first aspect, the preset rule includes: and taking the smallest numerical value in all the thread identifications to be allocated as a first thread identification.
In one possible design manner of the first aspect, after the electronic device module determines the first thread identifier of the target thread from all the thread identifiers to be allocated according to the preset rule, the method further includes: the electronic device adds the corresponding relation between the key thread corresponding to the target thread and the first thread identifier in the key thread identifier allocation data.
Therefore, the data can be conveniently and quickly obtained from the key thread identification distribution when the thread identification of a certain key thread needs to be acquired later.
In a possible design of the first aspect, the identification allocation data includes a thread identification of each of the plurality of critical threads; the electronic device determines a first thread identification of the target thread based on thread information and key thread identification allocation data of the target thread, including: the electronic device determines, based on the thread information of the target thread, a thread identification identifying a key thread whose thread information in the allocation data is identical to that of the target thread as a first thread identification of the target thread.
Based on the technical scheme, the electronic equipment can allocate a fixed thread identifier for the target thread of the key thread based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data, and the thread identifier is fixedly existing in the key thread identifier allocation data. Thus, when the subsequent electronic device needs the thread identification of a certain key thread at any time, the thread identification of the key thread can be obtained from the key thread identification allocation data, so that the operation (such as optimizing strategy) which needs to be implemented based on the thread identification of the key thread can be smoothly implemented.
In a possible design manner of the first aspect, the identifier allocation data includes a thread identifier of each of the plurality of critical threads, and in a case that the thread detection result is used to indicate that the target thread is a critical thread, the method further includes: the electronic device determines an expected thread identification of the target thread based on thread information and key thread identification allocation data of the target thread; the electronic device determines the expected thread identification as a first thread identification of the target thread; the electronic device completes creation of the target thread based on the first thread identification.
Based on the technical scheme, the data can be allocated based on the pre-configured key thread identification, and the fixed thread identification can be allocated to the key thread more accurately and safely when the key thread is created each time. The key thread identifier allocation data may be used to guide allocation of the thread identifier of the key thread, and fix the thread identifier of the allocated key thread. In this way, according to the technical scheme, the fixed thread identifier can be allocated to the specific key thread based on the pre-configured key thread identifier allocation data, so that when the key thread identifier needs to be acquired by the subsequent mobile phone, the thread identifier of the key thread can be accurately and rapidly acquired, and the acquisition efficiency of the thread identifier of the key thread is improved. And furthermore, an optimization strategy aiming at improving the smoothness of the system based on the thread identification of the key thread is smoothly implemented, and the use experience of a user is improved.
In one possible design manner of the first aspect, after the electronic device determines the desired thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data, the method further includes: the electronic equipment checks the thread information of the target thread and the expected thread identification of the target thread based on the key thread identification allocation data to obtain a check result; the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as key thread data, or the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as non-key thread data; in the case that the verification result is used to indicate the thread information of the target thread and the expected thread identification of the target thread as the critical thread data, the electronic device determines the expected thread identification as the first thread identification of the target thread.
In practice, the thread creation and the allocation of the thread identifier are completed by different modules or services, and the thread creation module responsible for the thread creation has a greater opening degree of the thread creation module than the thread identifier allocation module responsible for the allocation of the thread identifier, and is more easily operated maliciously. Therefore, there may be a situation that the expected thread identification of the target thread determined by the thread creation module after determining that the target thread is the critical thread is not obtained from the critical thread identification allocation data but is directly modified maliciously, or if the target thread itself is a critical thread, the thread creation module is maliciously operated to obtain a thread identification from the critical thread identification allocation data at will, and sends the thread identification to the thread identification allocation module as the expected thread identification to request allocation. In these cases, if the thread identifier allocation module directly allocates the desired thread identifier to the target thread, there may be an error situation that the target thread that is not a critical thread uses the thread identifier that should be allocated to the critical thread or allocates a random thread identifier (not belonging to the thread identifier in the critical thread identifier allocation data) to the target thread that is a critical thread, so that the thread identifier allocation is confused, and some critical threads cannot be allocated to the appropriate fixed thread identifiers. Based on this, after determining the desired thread identification, the thread identification allocation module should verify the thread information of the target thread and the desired thread identification based on the critical thread identification allocation data, and if the verification is successful, the desired thread identification is taken as the first thread identification of the target thread. If the verification is unsuccessful, the target thread should be identified as a normal thread, and then a second thread identifier may be allocated to the target thread according to the existing thread identifier allocation logic.
Therefore, based on the technical scheme, the fixed thread identification can be allocated for the key thread more safely and accurately.
In a possible design manner of the first aspect, in a case that the thread detection result is used to indicate that the target thread is not a critical thread, the method further includes: and the electronic equipment determines a second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data according to a default allocation rule.
Based on the technical scheme, the electronic equipment can normally allocate thread identification for the thread of the non-critical thread.
In one possible design of the first aspect, the default allocation rule includes: and determining the thread identifier with the minimum value as a second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data.
In a second aspect, the present application provides an electronic device that includes a thread creation module and a thread identification assignment module. The thread creation module is used for determining thread information of a target thread when the target thread is created; the thread information comprises a thread name and a process name of a process to which the thread information belongs; the thread creation module is also used for determining a thread detection result based on the thread information of the target thread; the thread detection result is used for indicating that the target thread is a critical thread, or the thread detection result is used for indicating that the target thread is not a critical thread; the thread identification allocation module is used for determining a first thread identification of the target thread based on the thread information of the target thread and the key thread identification allocation data determined by the thread creation module under the condition that the thread detection result determined by the thread creation module is used for indicating that the target thread is a key thread; the key thread identification allocation data comprises thread information of a plurality of key threads and identification allocation data; the identifier allocation data is used for indicating the electronic equipment to allocate a fixed thread identifier for the key thread; the thread creation module is further configured to complete creation of the target thread based on the first thread identification determined by the thread identification allocation module.
In one possible design manner of the second aspect, the thread creation module is specifically configured to: and determining a thread detection result based on the thread information of the target thread and the thread information of a plurality of key threads in the key thread identification allocation data.
In one possible design manner of the second aspect, the thread creation module is specifically configured to: if the thread information of the first key thread is the same as the thread information of the target thread in the thread information of the plurality of key threads in the key thread identification allocation data, the thread detection result is used for indicating that the target thread is the key thread; if the thread information of any one of the key threads does not exist in the thread information of the plurality of key threads in the key thread identification allocation data and the thread information of the target thread are the same, the thread detection result is used for indicating that the target thread is not the key thread.
In one possible design manner of the second aspect, the identifier allocation data includes a key identifier allocation range of a process to which each of the plurality of key threads belongs, where the key identifier allocation range is used to indicate a range of thread identifiers available to the key thread under the process; the thread identifier allocation module is specifically configured to: under the condition that the thread identification of the target thread does not exist in the key thread identification allocation data, determining the thread identification to be allocated in the key identification allocation range corresponding to the target thread from the identification allocation data; and determining the first thread identification of the target thread from all the thread identifications to be allocated according to a preset rule.
In one possible design manner of the second aspect, the preset rule includes: and taking the smallest numerical value in all the thread identifications to be allocated as a first thread identification.
In one possible design manner of the second aspect, the thread identifier allocation module is further configured to add, in the critical thread identifier allocation data, a correspondence between a critical thread corresponding to the target thread and the first thread identifier.
In one possible design of the second aspect, the identification allocation data includes a thread identification of each of the plurality of critical threads; the thread identifier allocation module is specifically configured to: the electronic device determines, based on the thread information of the target thread, a thread identification identifying a key thread whose thread information in the allocation data is identical to that of the target thread as a first thread identification of the target thread.
In one possible design manner of the second aspect, the identifier allocation data includes a thread identifier of each of the plurality of critical threads, and the thread creation module is further configured to determine, when the thread detection result is used to indicate that the target thread is a critical thread, an expected thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data; the thread identifier allocation module is further configured to determine the desired thread identifier determined by the thread creation module as a first thread identifier of the target thread; the thread creation module is further configured to complete creation of the target thread based on the first thread identification determined by the thread identification allocation module.
In one possible design manner of the second aspect, after the thread creation module determines the expected thread identifier of the target thread, the thread identifier allocation module is further configured to verify the thread information of the target thread and the expected thread identifier of the target thread based on the critical thread identifier allocation data, so as to obtain a verification result; the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as key thread data, or the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as non-key thread data; in the case that the verification result is used to indicate the thread information of the target thread and the expected thread identification of the target thread as critical thread data, the thread identification allocation module is further used to determine the expected thread identification as the first thread identification of the target thread.
In one possible design manner of the second aspect, when the thread detection result is used to indicate that the target thread is not a critical thread, the thread identifier allocation module is further configured to determine, according to a default allocation rule, a second thread identifier of the target thread from among the thread identifiers other than all the thread identifiers corresponding to the critical thread identifier allocation data.
In one possible design of the second aspect, the default allocation rule includes: and determining the thread identifier with the minimum value as a second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data.
In a third aspect, the present application provides an electronic device, comprising: a memory and one or more processors; the memory is coupled with the processor; wherein the memory has stored therein computer program code comprising computer instructions which, when executed by the processor, cause the electronic device to perform the thread identification allocation method as provided in the first aspect and any one of its possible designs.
In a fourth aspect, the present application provides a computer readable storage medium comprising computer instructions which, when run on an electronic device, cause the electronic device to perform a thread identification allocation method as provided in the first aspect and any one of its possible designs.
In a fifth aspect, the present application provides a computer program product comprising executable instructions which, when run on an electronic device, cause the electronic device to perform the thread identification allocation method as provided in the first aspect and any one of its possible designs.
In a sixth aspect, there is provided an apparatus (e.g. the apparatus may be a system-on-a-chip) comprising a processor for supporting an electronic device to implement the functionality referred to in the second aspect above. In one possible design, the apparatus further includes a memory for storing program instructions and data necessary for the electronic device. When the device is a chip system, the device can be formed by a chip, and can also comprise the chip and other discrete devices.
It may be appreciated that the advantages achieved by the technical solutions provided in the second aspect to the sixth aspect may refer to the advantages in any one of the possible designs of the first aspect, and are not described herein.
Drawings
Fig. 1 is a schematic diagram of a thread identifier allocation method according to an embodiment of the present application;
fig. 2 is a schematic hardware architecture of an electronic device according to an embodiment of the present application;
fig. 3 is a schematic software architecture of an electronic device according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a thread identification allocation method according to an embodiment of the present application;
FIG. 5 is a schematic diagram II of a thread identifier allocation method according to an embodiment of the present application;
FIG. 6 is a schematic diagram III of a thread identification allocation method according to an embodiment of the present application;
fig. 7 is a flowchart of a thread identifier allocation method according to an embodiment of the present application;
fig. 8 is a flowchart fifth of a thread identifier allocation method provided in an embodiment of the present application;
fig. 9 is a flowchart sixth of a thread identifier allocation method provided in an embodiment of the present application;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application;
fig. 11 is a schematic structural diagram of a chip system according to an embodiment of the present application.
Detailed Description
The terminology used in the following embodiments of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms as well, unless the context clearly indicates to the contrary. It should also be understood that "/" means or, e.g., A/B may represent A or B; the text "and/or" is merely an association relation describing the associated object, and indicates that three relations may exist, for example, a and/or B may indicate: a exists alone, A and B exist together, and B exists alone.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly understand that the embodiments described herein may be combined with other embodiments.
The terms "first", "second" in the following embodiments of the present application are used for descriptive purposes only and are not to be construed as implying or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature, and in the description of embodiments of the present application, unless otherwise indicated, the meaning of "a plurality" is two or more.
In order to facilitate the clear description of the technical solutions of the embodiments of the present application, the following simply describes some terms and techniques related to the embodiments of the present application:
kernel Node (Kernel Node): in a computer system, reference is made to a data structure or entity in the operating system kernel that represents and manages system resources such as devices, file systems, processes, etc. Each core Node has a unique identifier, called Node number (Node ID) or Handle, through which the Node can be accessed and operated.
In Linux systems, kernel nodes are typically presented to user space programs using a virtual file system (Virtual File System) so that they can interact with the nodes as if they were operating on a common file. This mode is called a Device File (Device File) or a Special File (Special File). For example, nodes under the/dev directory represent various devices such as disks, serial ports, printers, etc.
By interacting with the kernel node, a user space program (referring to a user space program refers to an application running in a computer system with user rights) can achieve access and control of the underlying resources. For device nodes, the device may be operated using read and write operations; for the file system node, file reading and writing and directory operation can be performed; and for the process node, the process state or the operations such as sending signals can be read.
In embodiments of the present application, the kernel node may be configured to store information (including thread names and thread identification TIDs) for all threads in the electronic device.
Currently, some key scenes (such as a start scene, a sliding scene, a game scene, a video playing scene, a voice call scene and the like) important for users need to have enough fluency (specifically, system fluency) of the electronic device, so that the use experience of the users is ensured. To achieve this, electronic devices are required to implement specific optimization strategies. The optimization policy may specifically be a setting (specifically may be an adjustment) of priority (e.g., priority of running and priority of using resources, etc.) or affinity (referring to an occupied configuration of processor resources of an electronic device) of a critical thread (e.g., a launcher thread with strong dependency on a desktop display in a startup scenario of the electronic device, a surfacefringer thread with strong dependency on running of a game screen in a game scenario, etc.) that has strong dependency on a critical scenario based on available resources and usage requirements of the electronic device. The setting of the priority or affinity of the critical thread is based on the thread identification (thread identity document, TID) of the critical thread. Based on this, accurate acquisition of thread identification of critical threads is a primary focus of optimization strategies of electronic devices for fluency.
In the prior art solution, since the TID allocated to each thread is different when each thread is newly built or runs, the thread identifier of the existing critical thread may be obtained as shown in the following table 1:
TABLE 1 thread identification scheme and limited cases
In the method, for the mode of identifying and acquiring the corresponding thread identification of the key thread by time limit through traversing the information in the kernel node (including the thread name and the thread identification), because more thread information is stored in the kernel node, the time consumption for identifying and acquiring the TI D of the key thread is longer. And once a thread is restarted, the thread identification of the thread needs to be searched again from the kernel node, which is more time-consuming.
For the mode of identifying the key thread and acquiring TI D when the thread is created or operated, the time of the thread creation or operation is uncontrollable, and the key thread identification and TI D acquisition cannot be completed conveniently. In addition, if the TI D is not normally allocated after a certain thread is restarted, the TI D cannot be quickly acquired. For example, there may be several cases where TI D is not normally allocated after a certain thread is restarted:
in the first case, when a thread is terminated, its resources (e.g., TI D and other status information) may take some time to be completely cleaned. If the same thread is started again before the cleaning process has been completed, it may result in the new thread not obtaining a new TI D, but continuing to use the TI D that has been previously disabled.
In the second case, if the thread management mechanism itself has a problem, such as a new TI D is not properly allocated at the time of thread restart, it may cause the TI D to fail to issue normally.
Third, in a multithreading environment, TI D allocation confusion may result when a thread is restarted if the creation and destruction of the thread is not properly synchronized. For example, multiple threads simultaneously restart and compete for new TI Ds, which may occur in case of allocation conflicts or duplicate allocations.
In the above cases, the restart of the thread may cause the TI D to be not allocated normally, and the TI D of the corresponding thread cannot be acquired accurately later.
Regarding the manner in which the critical thread is identified and the TI D is acquired when the thread renames, if there are too many threads to be identified, it takes a long time to identify the critical thread and acquire the TI D. The thread renaming specifically means that after thread creation is completed, the reference of the current thread is obtained through a corresponding API or method, and the name of the thread is changed through setting a name attribute, namely, the setting of the thread name is completed.
It can be seen that in the existing method for acquiring the thread identifier of the key thread, the method for acquiring the thread identifier of the key thread consumes longer time and has low acquisition efficiency.
In order to solve the above-mentioned problem, the embodiments of the present application provide a simplest implementation manner of thread identifier allocation, that is, in the process of performing thread creation on a critical thread by directly hard coding the thread identifier of the critical thread through a programming means (which may be referred to as variable writing death), so that the thread identifier of each critical thread is fixed during the use process of an electronic device. And when the thread identification of a certain key thread needs to be acquired later, the thread identification of any key thread can be quickly and accurately determined, and the acquisition efficiency is high.
However, in this thread identifier allocation method, the developer of each application program or operating system can only specify the correspondence between the key thread and the thread identifier in the thread that will be established in the program developed by the developer, and cannot specify the correspondence between the key program and the thread identifier in other application programs. That is, in this technical solution, the electronic device does not have overall information for the critical threads, and the thread identifier of each critical thread cannot be clarified. In this way, if there are more critical threads in the electronic device, because there is no specific overall data to indicate which thread identifications are occupied, it may cause that a fixed thread identification preset by a certain critical thread is occupied by a normal thread or other critical threads, resulting in disordered thread identification allocation and difficult maintenance. Therefore, even if the thread identifier of a certain key thread is obtained quickly and subsequently, the priority or affinity set by using the thread identifier may be considered as the priority or affinity of other common threads, so that the optimization policy made by the electronic device for guaranteeing the fluency cannot play a role.
Based on this, referring to fig. 1, the present application further provides a thread identifier allocation method, which can allocate a fixed thread identifier to a critical thread each time it is created, based on pre-configured critical thread identifier allocation data. The key thread identifier allocation data may be used to guide allocation of the thread identifier of the key thread, and fix the thread identifier of the allocated key thread. In this way, according to the technical scheme, the fixed thread identifier can be allocated to the specific key thread based on the pre-configured key thread identifier allocation data, so that the thread identifier of the key thread can be accurately and rapidly acquired when the key thread identifier is required to be acquired later, and the acquisition efficiency of the thread identifier of the key thread is improved. In addition, because the key thread identification allocation data capable of reflecting the thread identifications of all the key threads exists, the defects that the thread identification allocation is disordered and the maintenance is difficult due to the fact that the thread identifications are allocated to the key threads when the key threads are created in a hard coding mode are avoided.
The data identifier obtaining method provided in the embodiment of the present application is described below with reference to the accompanying drawings.
The data acquisition method provided by the embodiment of the application can be applied to electronic equipment. The embodiment of the application mainly introduces a thread allocation process when the thread is established in the running process of the electronic equipment.
In the present application, the electronic device may be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (augmented reality, AR)/Virtual Reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (personal digital assistant, PDA), or a device that uses a multi-battery serial system to supply electric energy, and the specific type of the electronic device is not limited in the embodiments of the present application.
Take the example of the electronic device being a cell phone. Fig. 2 shows a schematic structural diagram of the electronic device provided by the application.
Referring to fig. 2, the electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charge management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a display 193, a subscriber identity module (subscriber identification module, SIM) card interface 194, a camera 195, and the like. The sensor module 180 may include, among other things, a pressure sensor, a gyroscope sensor, a barometric sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
The processor 110 may include one or more processing units, such as: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and/or a neural network processor (neural-network processing unit, NPU), etc. Wherein the different processing units may be separate devices or may be integrated in one or more processors.
The controller may be a neural hub and command center of the electronic device. The controller can generate operation control signals according to the instruction operation codes and the time sequence signals to finish the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system. In the embodiment of the application, the memory may store thread identifier allocation data.
In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (subscriber identity module, SIM) interface, and/or a universal serial bus (universal serial bus, USB) interface, among others.
The charge management module 140 is configured to receive a charge input from a power supply device (e.g., a charger, notebook power, etc.). The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charge management module 140 may receive a charging input of a wired charger through the USB interface 130. In some wireless charging embodiments, the charge management module 140 may receive wireless charging input through a wireless charging coil of the electronic device.
The charging management module 140 may also supply power to the electronic device through the power management module 141 while charging the battery 142. The battery 142 may specifically be a plurality of batteries connected in series. The power management module 141 is used for connecting the battery 142, the charge management module 140 and the processor 110.
The power management module 141 is used for connecting the battery 141, and the charge management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140 and provides power to the processor 110, the internal memory 121, the display 193, the camera 195, the wireless communication module 160, and the like. The power management module 141 may also be configured to monitor parameters such as battery voltage, current, battery cycle number, battery state of health (leakage, impedance), etc. In other embodiments, the power management module 141 may also be provided in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may also be disposed in the same device, for example, the power management module 141 and the charging management module 140 may be different functional modules in the same chip.
The external memory interface 120 may be used to connect external non-volatile memory to enable expansion of the memory capabilities of the electronic device. The external nonvolatile memory communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and video are stored in an external nonvolatile memory.
The internal memory 121 may include one or more random access memories (random access memory, RAM) and one or more non-volatile memories (NVM). The random access memory may be read directly from and written to by the processor 110, may be used to store executable programs (e.g., machine instructions) for an operating system or other on-the-fly programs, may also be used to store data for users and applications, and the like. The nonvolatile memory may store executable programs, store data of users and applications, and the like, and may be loaded into the random access memory in advance for the processor 110 to directly read and write.
Touch sensors, also known as "touch devices". The touch sensor may be disposed on the display screen 193, and the touch sensor and the display screen 193 form a touch screen, which is also called a "touch screen". The touch sensor is used to monitor touch operations acting on or near it. The touch sensor may communicate the monitored touch operation to the application processor to determine the touch event type. Visual output related to the touch operation may be provided through the display 193. In other embodiments, the touch sensor may also be disposed on a surface of the electronic device other than where the display 193 is located.
The pressure sensor is used for sensing a pressure signal and can convert the pressure signal into an electric signal. In some embodiments, the pressure sensor may be provided on the display 193. Pressure sensors are of many kinds, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. When a touch operation is applied to the display screen 193, the electronic apparatus monitors the intensity of the touch operation according to the pressure sensor. The electronic device may also calculate the location of the touch based on the monitoring signal of the pressure sensor. In some embodiments, touch operations that act on the same touch location, but at different touch operation strengths, may correspond to different operation instructions. For example: and executing an instruction for checking the short message when the touch operation with the touch operation intensity smaller than the first pressure threshold acts on the short message application icon. And executing an instruction for newly creating the short message when the touch operation with the touch operation intensity being greater than or equal to the first pressure threshold acts on the short message application icon.
The electronic device implements display functions through a GPU, a display screen 193, an application processor, and the like. The GPU is a microprocessor for image editing, and is connected to the display 193 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
The electronic device may implement photographing functions through an ISP, a camera 195, a video codec, a GPU, a display screen 193, an application processor, and the like.
The ISP is used to process the data fed back by the camera 195. For example, when photographing, the shutter is opened, light is transmitted to the camera photosensitive element through the lens, the optical signal is converted into an electric signal, and the camera photosensitive element transmits the electric signal to the ISP for processing and is converted into an image visible to naked eyes. ISP can also perform algorithm optimization on noise and brightness of the image. The ISP can also optimize parameters such as exposure, color temperature and the like of a shooting scene. In some embodiments, the ISP may be located in the camera 195. The camera 195 is used to capture still images or video. In some embodiments, the electronic device may include 1 or N cameras, N being a positive integer greater than 1. The camera 195 may be a front camera or a rear camera.
The digital signal processor is used for processing digital signals, and can process other digital signals besides digital image signals. For example, when the electronic device selects a frequency bin, the digital signal processor is used to fourier transform the frequency bin energy, and so on.
The display 193 is used to display images, videos, and the like. The display 193 includes a display panel. The display panel may employ a liquid crystal display (liquid crystal display, LCD), an organic light-emitting diode (OLED), an active-matrixorganic light emitting diode (AMOLED), a flexible light-emitting diode (flex), a mini, a Micro-OLED, a quantum dot light-emitting diode (quantum dot light emitting diodes, QLED), or the like. In some embodiments, the electronic device may include 1 or N display screens 193, N being a positive integer greater than 1.
In embodiments of the present application, the display 193 may be used to display an interface (e.g., a camera preview interface, a video preview interface, a film preview interface, etc.) of an electronic device and display images captured from any one or more cameras 195 in the interface.
The wireless communication function of the electronic device may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, a modem, a baseband processor, and the like.
The antennas 1 and 2 are used for transmitting and receiving electromagnetic wave signals. Each antenna in the electronic device may be used to cover a single or multiple communication bands. Different antennas may also be multiplexed to improve the utilization of the antennas.
The mobile communication module 150 may provide a solution for wireless communication including 2G/3G/4G/5G, etc. applied on an electronic device. The mobile communication module 150 may receive electromagnetic waves from the antenna 1, perform processes such as filtering, amplifying, and the like on the received electromagnetic waves, and transmit the processed electromagnetic waves to the modem processor for demodulation. The mobile communication module 150 can amplify the signal modulated by the modem processor, and convert the signal into electromagnetic waves through the antenna 1 to radiate. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be disposed in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be provided in the same device as at least some of the modules of the processor 110.
The modem processor may include a modulator and a demodulator. The modulator is used for modulating the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used for demodulating the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low frequency baseband signal to the baseband processor for processing. The low frequency baseband signal is processed by the baseband processor and then transferred to the application processor. The application processor outputs sound signals through an audio device (not limited to the speaker 170A, the receiver 170B, etc.), or displays images or videos through the display screen 193. In some embodiments, the modem processor may be a stand-alone device. In other embodiments, the modem processor may be provided in the same device as the mobile communication module 150 or other functional module, independent of the processor 110.
The wireless communication module 160 may provide solutions for wireless communication including wireless local area network (wireless local area networks, WLAN) (e.g., wireless fidelity (wireless fidelity, wi-Fi) network), bluetooth (BT), global navigation satellite system (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field wireless communication technology (near field communication, NFC), infrared technology (IR), etc. for application on an electronic device. The wireless communication module 160 may be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the electromagnetic wave signals, filters the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive a signal to be transmitted from the processor 110, frequency modulate it, amplify it, and convert it to electromagnetic waves for radiation via the antenna 2.
The SIM card interface 194 is used to connect to a SIM card. The SIM card may be inserted into the SIM card interface 194, or removed from the SIM card interface 194 to effect contact and separation with the electronic device. The electronic device may support one or more SIM card interfaces. The SIM card interface 194 may support a Nano SIM card, micro SIM card, etc. The same SIM card interface 194 may be used to insert multiple cards simultaneously. The SIM card interface 194 may also be compatible with external memory cards. The electronic equipment interacts with the network through the SIM card, so that the functions of communication, data communication and the like are realized. One SIM card corresponds to one subscriber number.
It should be understood that the connection relationship between the modules illustrated in the embodiments of the present invention is only illustrative, and does not limit the structure of the electronic device. In other embodiments of the present application, the electronic device may also use different interfacing manners in the foregoing embodiments, or a combination of multiple interfacing manners.
It will be understood, of course, that the above illustration of fig. 2 is merely exemplary of the case where the electronic device is in the form of a cellular phone. If the electronic device is a tablet computer, a handheld computer, a PC, a PDA, a wearable device (e.g., a smart watch, a smart bracelet), etc., the electronic device may include fewer structures than those shown in fig. 2, or may include more structures than those shown in fig. 2, which is not limited herein.
It will be appreciated that, in general, implementation of electronic device functions requires hardware support and software coordination. The software system of the electronic device may employ a layered architecture, an event driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. Embodiments of the present application are in a layered architectureThe system is an example illustrating the software architecture of an electronic device.
Fig. 3 is a schematic diagram of a layered architecture of a software system of an electronic device according to an embodiment of the present application. The layered architecture divides the software into several layers, each with distinct roles and branches. The layers communicate with each other through a software interface (e.g., API).
In some examples, referring to fig. 3, in the embodiment of the present application, the software of the electronic device is divided into five layers, namely, an application layer, a framework layer (or referred to as an application framework layer), a system library and android run time (HAL layer (hardware abstraction layer), a hardware abstraction layer) and a driver layer (or referred to as a kernel layer) from top to bottom.
The application layer may include a series of applications, among others. As shown in fig. 3, the application layer may include camera, gallery, calendar, map, WLAN, bluetooth, music, video, short message, call, contact, live, etc. Applications (APP). The call application and the contact person can be preset in the factory of the electronic equipment, and can also be a third party application for user call provided by the application market.
A thread creation module (not shown) may be included in each application in the application layer, and may complete the creation of threads as needed during the running of the application. In the embodiment of the application, when a certain thread needs to be established, the thread creation module determines a good thread name based on development logic in advance of a developer, and determines whether the thread is a key thread or a common thread based on the thread name and the process name of the process to which the thread belongs. If the thread is a common thread, creating the thread according to the existing flow and distributing a thread identifier; if the thread is a critical thread, an identifier allocation request (carrying the thread name of the critical thread and the process name of the process to which the critical thread belongs) may be generated based on the thread name of the critical thread and the process name of the process to which the critical thread belongs, and sent to the thread identifier allocation module, so that the thread identifier allocation module allocates a final thread identifier for the critical thread based on the identifier allocation request. The thread creation module may then complete the creation of the critical thread based on the final thread identification. Of course, when a thread needs to be created, the thread creation module included in the application program in practice is mainly used for generating a request for creating the thread based on the requirement of the application program and the final thread identifier distributed by the thread distribution module. The function or method that created the thread to the operating system kernel (specifically, the value framework layer) may then be sent to a thread creation request (this process may also be referred to as calling the function or method that created the thread) to cause the function that created the thread to complete the creation of the thread.
Of course, the thread creation module provided in the embodiment of the present application may also be a function or a method (may be a type of API for performing thread creation) that is located in the framework layer and actually completes thread creation, and when a thread needs to be created, different application programs all call the thread creation module to complete thread creation.
The framework layer provides an application programming interface (application programming interface, API) and programming framework for application programs of the application layer. The application framework layer includes a number of predefined functions. For example, the application framework layer may include an activity manager, a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc., which embodiments of the present application do not impose any limitations.
The window manager is used for managing window programs. The window manager can acquire the size of the display screen, judge whether a status bar exists, lock the screen, intercept the screen and the like. The content provider is used to store and retrieve data and make such data accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phonebooks, etc. The view system includes visual controls, such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, a display interface including a text message notification icon may include a view displaying text and a view displaying a picture. The telephony manager is for providing communication functions of the electronic device. For example, the telephony manager may manage the call state (including initiate, connect, hang-up, etc.) of the call application. The resource manager provides various resources for the application program, such as localization strings, icons, pictures, layout files, video files, and the like. The notification manager allows the application to display notification information in a status bar, can be used to communicate notification type messages, can automatically disappear after a short dwell, and does not require user interaction. Such as notification manager is used to inform that the download is complete, message alerts, etc. The notification manager may also be a notification in the form of a chart or scroll bar text that appears on the system top status bar, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in a status bar, a prompt tone is emitted, the electronic device vibrates, and an indicator light blinks, etc.
In an embodiment of the present application, a thread identifier allocation service (or referred to as a thread identifier allocation module) may be included in the framework layer. The thread identifier allocation service may allocate a final thread identifier to the critical thread according to a specific rule based on pre-configured critical thread identifier allocation data after receiving the identifier allocation request sent by the thread creation module. The thread identification assignment service then sends the final thread identification to the thread creation module to cause the thread creation module to complete creation of the critical thread based on the final thread identification.
In the prior art, the thread identifier allocation rule of the thread identifier allocation service to the thread may be to use a specific function to add 1 to the maximum value of the used thread identifiers as the thread identifier of the thread to be allocated with the thread identifier currently. The specific logic code may be as follows:
where tid is a private member variable that stores the unique Identifier (ID) of the thread. the wiredseqnumber is a static long integer variable that is used to record thread sequence numbers. It is defined as private and decorated with synchronization keys to ensure thread ID uniqueness in a multi-threaded environment. next thread ID () is a static synchronization method for generating the next line ID. Within the method, the threaddseqnumber is first self-incremented and then returned to its value, so that each time the method is called, a different increment ID is returned. By using the synchronization key for modification, it can be ensured that only one thread can execute the method simultaneously in a multi-threaded environment.
The above code fragments are mainly used to assign each thread an independent and unique ID. By calling the nextThreadId () method, a new thread ID can be obtained and assigned to the tid member variable for identifying the unique identity of the current thread.
In the embodiment of the application, the improvement of the thread identification allocation service mainly lies in the change of 'private static synchronized long nexThreadId ()', so that the thread identification allocation module realizes the purpose of allocating fixed thread identifications to key threads.
In the embodiment of the application, the thread identifier allocation scheme provided by the embodiment of the application can be completed by cooperation between the thread creation module and the thread identifier allocation service (or the thread identifier allocation module).
The system library may include a plurality of functional modules. For example: surface manager (surface manager), media library (Media Libraries), openGL ES, SGL, etc. The surface manager is used to manage the display subsystem and provides a fusion of 2D and 3D layers for multiple applications. Media libraries support a variety of commonly used audio, video format playback and recording, still image files, and the like. The media library may support a variety of audio video encoding formats, such as: MPEG4, h.264, MP3, AAC, AMR, JPG, PNG, etc. OpenGL ES is used to implement three-dimensional graphics drawing, image rendering, compositing, and layer processing, among others. SGL is the drawing engine for 2D drawing.
Android runtime (android run) includes a core library and an ART virtual machine. android run is responsible for scheduling and management of android systems. The core library consists of two parts: one part is a function which needs to be called by java language, and the other part is a core library of android. The application layer and the application framework layer run in an ART virtual machine. The ART virtual machine executes java files of the application program layer and the application program framework layer into binary files. The ART virtual machine is used for executing the functions of object life cycle management, stack management, thread management, security and exception management, garbage collection and the like.
The HAL layer is an interface layer between the operating system kernel and the hardware circuitry that aims at abstracting the hardware. The hardware interface details of a specific platform are hidden, a virtual hardware platform is provided for an operating system, so that the operating system has hardware independence, and can be transplanted on various platforms. The HAL layer provides a standard interface to display device hardware functionality to a higher level Java API framework (i.e., framework layer). The HAL layer contains a plurality of library modules, each of which implements an interface for a particular type of hardware component, such as: an audio HAL module, a blue HAL Bluetooth module, a camera HAL module, and a sensors HAL sensor module (or called Isensor service).
The kernel layer is a layer between hardware and software. The inner core layer at least comprises display drive, camera drive, audio drive, sensor drive, battery drive and the like, and the application is not limited.
Based on the above hardware architecture and software architecture, an electronic device is taken as an example of a mobile phone, and in conjunction with fig. 4, a thread identifier allocation method provided in an embodiment of the present application is described. Referring to fig. 4, the thread identifier allocation method provided in the embodiment of the present application may include S401 to S410:
s401, when a target thread is created, a thread creation module of the mobile phone determines thread information of the target thread.
Wherein the thread information includes: a thread name and a process name of the process to which the thread belongs.
In the embodiment of the application, the thread creation module may create the target thread at any feasible time. For example, after the game application is started, in order to better show a smooth game interface to the user, the thread creation module is triggered to create a thread, i.e. a surfaceflinger. Of course, in practice, when any process or service in any application program or operating system needs to execute a certain target service, if a target thread corresponding to the target service is not running or created, the thread creation module will create the target thread, so that the target service can be executed smoothly.
The technical scheme provided by the application aims to fix the thread identifications of all the key threads, and is convenient to quickly and accurately acquire the thread identifications of the key threads when an optimization strategy for improving the system flow is required to be implemented according to the thread identifications of the key threads. Based on this, when any thread is created, the thread creation module in the present application may first determine whether the thread is a critical thread based on the thread name of the thread, and then implement the subsequent operation of allocating the thread identifier if the thread is determined to be the critical thread. In practice, a process may include multiple threads, and different threads may include threads with the same thread name. The same thread in two different processes may be a critical thread and a non-critical thread.
Therefore, in order to more accurately determine whether the target thread is a critical thread, it is necessary to determine the process name in addition to the thread name when creating the target thread.
In addition, in the embodiment of the present application, when the target thread is a critical thread, the thread information of the target thread is referred to allocate a thread identifier to the target thread, so in order to ensure that the thread identifier allocated to the target thread according to the thread information can be used to distinguish the same thread (i.e. the thread with the same thread name) under different processes, the thread name and the process name of the target thread should be determined when the thread is created.
In the embodiment of the application, the key thread can be determined by analyzing the user usage data, and in some key scenes with high requirements of users on the system fluency of the mobile phone, the key threads correspond to the services closely related to the key scenes. For example, the surfaceflinger thread closely related to the game picture fluency program in the key scene of the game scene is the key thread. In practice, the determination of the critical threads needs to be determined according to the actual user requirements, and the number and the types of the critical threads are not particularly limited in the application.
The process name of the process to which the thread to be created belongs in the thread creation module in the prior art can be directly determined (the process is established before the thread creation, so all information of the process can be directly acquired in any feasible way), and the thread name does not exist. Normally, a thread renaming function capable of setting a thread device name sets a name (i.e., thread name) for a created thread only after the thread is created. In the embodiment of the present application, in order to make the thread name of the critical thread directly available at the time of creation, there may be two implementations:
In a first implementation manner, when developing each application program, a developer can adjust the function of the thread creation module through programming under the condition that the creation time of all the key threads of the application program in the running process (for example, the thread name of the thread which is created when the process A needs to execute the task A is A, and the thread is the key process) is defined, so that the thread creation module can directly determine the thread name of the key thread when the key thread corresponding to the application program is created.
In a second implementation manner, the developer can also adjust the function of the thread creation module through programming under the condition that the creation time of all threads in the running process of the application program is clear, so that the thread creation module can directly determine the thread name of each thread corresponding to the application program when creating the thread.
Of course, the second implementation requires more work by the developer than the first implementation, and the code of the application changes more.
Thus, the thread creation module can successfully obtain the thread name of the target thread when the target thread is created.
After the thread creation module of the mobile phone acquires the thread information of the target thread, whether the target thread is a key thread or not can be judged based on the thread information, and a thread detection result is obtained. That is, S402 is executed, where the thread detection result may be used to indicate that the target thread is the target thread, or the thread detection result may be used to indicate that the target thread is not the target thread.
Based on the thread detection result, it can be determined whether to execute the subsequent process of setting the fixed TID for the critical thread.
S402, the thread creation module of the mobile phone judges whether the target thread is a key thread or not based on the thread information of the target thread.
In one implementation manner, the mobile phone may store an association relationship between a plurality of key threads and a plurality of thread information, and the thread creation module may determine whether the target thread is a key thread based on the thread information of the target thread and the association relationship. Specifically, if the thread information of a certain critical thread exists in the association relationship and the thread information of the target thread is the same, the target thread can be determined to be the critical thread. If the thread information of the certain key thread does not exist in the association relation and the thread information of the target thread is the same, the target thread can be determined not to be the key thread.
In this embodiment of the present application, the association information may be all key threads and corresponding thread information of most application programs that may be used by the user may be collected by a mobile phone manufacturer in any feasible manner before the mobile phone leaves the factory, so that statistical summary is obtained.
In some embodiments, the association may allocate data for pre-configured and stored critical thread identifications. The critical thread identification allocation data includes thread information for a plurality of critical threads. At this time, S402 may specifically be: the thread creation module of the mobile phone determines a thread detection result based on the thread information of the target thread and the thread information of a plurality of key threads in the key thread identification allocation data. Specifically, if the thread information of a certain critical thread (for example, the first critical program) in the critical thread identification allocation data is the same as the thread information of the target thread, the thread detection result is used to indicate that the target thread is determined to be the critical thread. If the thread information of any one of the critical threads does not exist in the critical thread identification allocation data is the same as the thread information of the target thread, the thread detection result is used for indicating that the target thread is not the critical thread.
Under the condition that the thread creation module of the mobile phone determines that the target thread is a key thread, the thread identifier allocation module of the subsequent mobile phone needs to allocate a corresponding first thread identifier for the target thread based on pre-configured key thread identifier allocation data, namely executing subsequent S403-S407.
Under the condition that the thread creation module of the mobile phone determines that the target thread is a key thread, the thread identifier allocation module of the subsequent mobile phone can allocate a first thread identifier for the target thread according to the existing thread identifier allocation logic, namely, execute subsequent S408-S410.
It should be noted that, in practice, the judging step of S402 may not exist, and the thread creation module of the mobile phone may directly execute S403 when determining that the target thread is a critical thread based on the thread information of the target thread; if it is determined that the target thread is not a critical thread based on the thread information of the target thread, S408 may be executed. This is not particularly limited in this application.
S403, the thread creation module of the mobile phone sends an identification allocation request to the thread identification allocation module.
The identifier allocation request carries thread information of the target thread, and is used for requesting to allocate a thread identifier for the target thread.
S404, the thread identification allocation module of the mobile phone receives an identification allocation request from the thread creation module.
S405, a thread identification allocation module of the mobile phone determines a first thread identification of a target thread based on thread information of the target thread in the identification allocation request and the key thread identification allocation data.
In the embodiment of the application, the key thread identification allocation data may further include identification allocation data in addition to thread information of a plurality of key threads. The identifier allocation data may be used to instruct the mobile phone to allocate a fixed thread identifier to the critical thread, or the identifier allocation data may be used to instruct the mobile phone to allocate a fixed thread identifier to the critical thread.
In the embodiment of the present application, the implementation manner of determining the first thread identifier of the target thread by the thread identifier allocation module of the mobile phone based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data may include the following two types:
in a first possible implementation, the identification allocation data included in the critical thread identification allocation data may include a critical identification allocation scope of a process to which each critical thread belongs. The thread identifier allocation module of the mobile phone can allocate an identifier for the target thread based on a key identifier range which can be allocated by a process to which the target thread belongs in the key thread identifier allocation data. In this embodiment of the present application, the key identifier allocation scope specifically refers to a scope of thread identifiers that are available to the key threads under the process. For example, if the key identifier allocation range under a process is 1000-1999, then the thread identifier of the key thread under that process may be 1000-1999. In some embodiments, the key identification allocation scope may be identified with a key process number segment. Specifically, if the key identifier allocation range is 1000-1999, the key process number segment may be 100 or any other feasible value. By way of example, the critical thread identification allocation data may be as shown in Table 2 below.
TABLE 2 Critical TI D Allocation Table
In order to facilitate the subsequent mobile phone to obtain smoothly when the thread identification of the key thread needs to be inquired. When the target thread is a critical thread, the thread identifier allocation module may store the first thread identifier in the critical thread identifier allocation data after allocating the first thread identifier to the target thread, and establish an association relationship between the critical thread corresponding to the target thread and the first thread identifier in the critical thread identifier allocation data to update the critical thread identifier allocation data. For example, as shown in table 2, a storage location capable of storing a thread identifier of each critical thread may be reserved in advance in a critical TID allocation table corresponding to the pre-configured critical thread identifier allocation data. After each time the thread identifier allocation module allocates a thread identifier to a certain critical thread, a corresponding thread identifier can be placed at a position where the thread identifier of the critical thread is placed in the table, so as to update a table corresponding to the critical thread identifier allocation data. For example, if the thread identifier allocating module allocates a thread identifier of 10001 for a surfaceflinger thread under a surfaceflinger process, the thread identifier allocating module may allocate data for the critical thread identifier after updating based on the thread identifier may be as shown in table 3 below.
TABLE 3 Critical TID Allocation Table
The thread identifier of the critical thread, i.e. the surfacefringer under the surfacefringer, is set to 10001, and the other critical threads which are not allocated with the thread identifier do not have corresponding thread identifiers.
Therefore, the subsequent mobile phone can conveniently and quickly find the thread identification of the key thread from the key thread identification allocation data.
In the implementation manner, the thread identifier allocation module can analyze the key thread identifier allocation data stored in advance in the mobile phone in the starting process of the mobile phone, so that the thread name of the key thread which can be directly used for processing subsequently, the process name of the process to which the key thread belongs and the key identifier allocation range of each process are obtained.
Based on the foregoing, in some embodiments, referring to fig. 5 in conjunction with fig. 4, S405 may specifically include S501-S504:
s501, a thread identification distribution module of the mobile phone judges whether the thread identification of the target thread exists in the key thread identification distribution data or not based on the thread information of the target thread in the identification distribution request.
Specifically, the thread identifier allocation module may first determine whether the thread information of a certain critical thread exists in the critical thread identifier allocation data and the thread information of the target thread are the same.
If the key thread with the same thread information as the target thread exists, judging whether the thread identification of the key thread exists in the key thread identification allocation data. If the thread identification of the key thread exists, determining that the thread identification of the target thread exists in the key thread identification allocation data. And then, the first thread identifier can be allocated to the target thread based on the key identifier allocation range corresponding to the target thread in the key thread identifier allocation data and the available thread identifiers to be allocated in the key identifier allocation range corresponding to the target thread. I.e. S502 and S503 are performed.
If the critical thread which is the same as the thread information of the target thread does not exist, the thread creation module can be considered to determine that the target thread is the critical thread, and the judgment result is wrong or the identification allocation request sent by the thread creation module can be tampered. At this time, the target thread may be considered abnormal, and may be determined as a normal thread in order to prevent the thread identification available to the critical process from being illegally occupied. The thread identifier allocation module may then allocate the first thread identifier to the target thread according to the existing thread identifier allocation logic, i.e., execute the subsequent S408-S410.
In the embodiment of the present application, step S501 may also be referred to as a thread checking mechanism, which may prevent a thread that is uncertain whether to assign a thread that should be assigned to a critical thread to a thread, so as to avoid a thread identifier assignment error.
It should be noted that, in practice, the judging step of S501 may not exist, and the thread identifier allocation module of the mobile phone may directly execute S502 when determining that the thread identifier of the target thread exists in the key thread identifier allocation data based on the thread information of the target thread in the identifier allocation request; if it is determined that the thread identification of the target thread does not exist in the critical thread identification allocation data based on the thread information of the target thread in the identification allocation request, S408 may be executed. This is not particularly limited in this application.
S502, a thread identification distribution module of the mobile phone determines the thread identification to be distributed in the key identification distribution range corresponding to the target thread from the identification distribution data in the key thread identification distribution data based on the process name of the process to which the target thread belongs in the identification distribution request.
Where the thread identification to be assigned refers to a thread identification that is not assigned to any critical thread.
Specifically, the thread identifier allocation module may determine, as the key identifier allocation range corresponding to the target thread, the key identifier allocation range of a process having the same process name as the process name of the process to which the target thread belongs in the key thread identifier allocation data. For example, taking the key thread identifier allocation data as the content shown in table 2 as an example, if the process name of the process to which the target thread belongs is surfaceflinger, the key identifier allocation range corresponding to the target thread is 1000-1999.
The assigned thread identifications of other key threads in the key identification assignment range corresponding to the target thread can be directly determined from the key thread identification assignment data, and the other thread identifications in the key identification assignment range are to-be-assigned thread identifications.
It should be noted that, under the condition that the thread identifier allocation module of the mobile phone allocates the thread identifier for the target thread determined as the critical thread for the first time, the thread identifier of the target thread does not exist in the critical thread identifier allocation data, and all the thread identifiers in the critical identifier allocation range corresponding to the target thread are the thread identifiers to be allocated.
S503, a thread identifier distribution module of the mobile phone determines a first thread identifier of a target thread from all thread identifiers to be distributed according to a preset rule.
In one possible implementation, the preset rule may be to use the smallest value of all the thread identifiers to be allocated as the first thread identifier of the target thread. That is, the preset rules may be such that the identifications in the key identification allocation scope of each process in the key identification allocation scope are allocated thread identifications from small to large in the order in which each key process first appears. Of course, the preset rule may be any other feasible implementation in practice, which is not specifically limited in this application.
In order to ensure that the subsequent thread identification of a certain critical thread can be obtained conveniently and quickly from the critical thread identification allocation data when the thread identification of the certain critical thread needs to be obtained, the critical thread identification allocation data should be updated in time after the first thread identification is determined for the target thread each time, that is, S504 is executed.
S504, a thread identifier distribution module of the mobile phone adds the corresponding relation between the key thread corresponding to the target thread and the first thread identifier in the key thread identifier distribution data.
Taking the critical thread identifier allocation data shown in table 2 as an example, S502 may specifically be adding the first thread identifier to the placement location of the thread identifier of the critical thread corresponding to the target thread in the table corresponding to the critical thread identifier allocation data. For example, if the target thread is a surfacefringer thread under a surfacefringer process and the thread identifier allocated by the thread identifier allocation module is 10001, the thread identifier allocation module may be configured as shown in the above table 3 based on the updated critical thread identifier allocation data of the first thread identifier.
In the embodiment of the application, the updated key thread identifier allocation data is fixedly stored before the next update, so that the subsequent mobile phone can conveniently acquire the thread identifier of any key thread from the key thread identifier allocation data. Under the condition, after all the key threads in the key thread identifier allocation data have corresponding thread identifiers, the mobile phone only needs to inquire the key thread identifier allocation data once and then store the key thread identifier allocation data, so that the stored thread identifiers can be directly used for inquiring and acquiring no longer, and the efficiency of acquiring the thread identifiers of the key threads subsequently is improved.
In some embodiments, the mobile phone may cause the key thread identifier allocation data to be converted into an initial state, i.e. a state where no thread identifier of any thread exists, after each reboot or reboot after shutdown. In this case, the restart after each restart or shutdown of the mobile phone may be caused by a change in the first creation order of a certain critical thread, so that the thread identifier allocation module determines or allocates a thread identifier for the critical thread based on the critical thread identifier allocation data. In this case, after the mobile phone is restarted after each restart or shutdown, if the thread identifier of a certain key thread whose thread identifier has been acquired before the mobile phone is restarted or shutdown is required to be acquired, it is required to search from the key thread identifier allocation data again. This approach may be less efficient to acquire a thread identification of a critical thread than if the critical thread identification allocation data after each update were stored fixedly prior to the next update.
Based on the technical scheme corresponding to S501-S504, the mobile phone can allocate a fixed thread identifier for the target thread of the key thread based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data, and the thread identifier is embodied in specific data (i.e., the key thread identifier allocation data). Thus, when the thread identification of a certain key thread is needed at any time later, the thread identification of the key thread can be obtained from the key thread identification allocation data, so that the operation (such as optimizing strategy) which needs to be implemented based on the thread identification of the key thread can be smoothly implemented.
In a second possible implementation, the identification allocation data included in the critical thread identification allocation data may include a thread identification for each critical thread. The thread identifier of each key thread can be determined by the handset manufacturer before the handset leaves the factory and set in the key thread identifier allocation data. Illustratively, the critical thread identification allocation data at this time may be as shown in Table 4 below.
TABLE 4 Critical TID Allocation Table
Of course, in this implementation, the identifier allocation data included in the key thread identifier allocation data may also include a key identifier allocation range of a process to which each key thread belongs. For example, the critical thread identification allocation data at this time may be as shown in table 5 below.
TABLE 5 Critical TID Allocation Table
In the implementation manner, the thread identifier allocation module can analyze the key thread identifier allocation data stored in advance in the mobile phone in the starting process of the mobile phone, so as to obtain the thread names of the key threads and the process names of the processes to which the key threads belong. Then, for convenience of use, the thread identifier allocation module can splice the thread name and the process name into a character string (namely, converting the thread information of the key thread into the character string), and store the character string and the corresponding thread identifier in the memory in a key value pair mode, so that the subsequent query or call when the key thread is needed to be used is facilitated. Illustratively, taking the critical thread identification allocation data shown in table 4 as an example, the critical thread identification allocation data converted by the thread identification allocation module is shown in table 6 below.
TABLE 6 Critical thread identification assignment data
Thread information (key) of key thread Thread identification (value)
Surfaceflinger-Surfaceflinger 1000
android.launcher-android.launcher 2000
android.launcher-RenderThread 2001
system_server-system_server 3000
system_server-android.anim 3001
Third party application Process-application UI thread X000
Third party application Process-application Render thread X001
Based on the above identification, in some embodiments, referring to fig. 6 in conjunction with fig. 4, S405 may specifically include S601:
s601, a thread identification allocation module of the mobile phone determines a first thread identification of a target thread from identification allocation data in key thread identification allocation data based on thread information of the target thread in an identification allocation request.
Specifically, the thread identifier allocation module may determine, as the first thread identifier of the target thread, the thread identifier of the critical thread whose thread information is the same as that of the target thread in the thread identifier allocation data. For example, taking the content of the key thread identifier allocation data as shown in table 6 as an example, if the thread name of the target thread is system_server and the process name of the process to which the target thread belongs is system_server, the first thread identifier of the target thread is the thread identifier 3000 corresponding to the system_server-system_server.
In addition, it should be noted that, in practice, if the thread creation module determines that the target thread is a critical thread, or if the determination result that the identification allocation request sent by the thread creation module is tampered, there will be no critical thread in the critical thread identification allocation data, where the thread information is the same as the thread information of the target thread. At this time, the target thread may be considered abnormal, and may be determined as a normal thread in order to prevent the thread identification available to the critical process from being illegally occupied. The thread identifier allocation module may then allocate a second thread identifier to the target thread according to the existing thread identifier allocation logic, i.e. execute the subsequent S408-S410.
Based on the technical scheme corresponding to S601, the mobile phone can allocate a fixed thread identifier for the target thread of the key thread based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data, and the thread identifier is fixedly existing in the key thread identifier allocation data. Thus, when the thread identification of a certain key thread is needed at any time later, the thread identification of the key thread can be obtained from the key thread identification allocation data, so that the operation (such as optimizing strategy) which needs to be implemented based on the thread identification of the key thread can be smoothly implemented.
S406, the thread identification distribution module of the mobile phone sends the first thread identification to the thread creation module.
In some embodiments, the thread identifier allocation module may specifically send a thread identifier allocation response corresponding to the identifier allocation request to the thread creation module, where the thread identifier allocation response carries first indication information, where the first indication information indicates that the thread identifier of the target thread is the first thread identifier.
S407, the thread creation module of the mobile phone receives the first thread identification from the thread identification distribution module and completes the creation of the target thread based on the first thread identification.
Specifically, when the thread creation module of the mobile phone creates the target thread, the thread creation module needs to determine the first thread identifier of the target thread, and also needs to allocate corresponding thread resources (such as memory space, CPU time slices and other resources) for the target thread, so that the target thread can normally run, and the creation of the target thread is completed.
After S407, when the mobile phone (or the thread using module in the mobile phone) needs the thread identifier of a certain key thread at any time, the thread identifier of the key thread can be obtained based on the allocation data of the key thread identifier, so that the operation (such as optimizing policy) which needs to be implemented based on the thread identifier of the key thread can be implemented smoothly.
In addition, it should be noted that, in practice, the mobile phone or the thread usage module of the mobile phone needs to check the existence state of a certain critical thread before distributing data based on the critical thread identifier and acquiring the thread identifier of the certain critical thread. The thread usage module performs an optimization strategy that improves system flow based on the thread identification of the critical thread only if the critical thread's presence status is surviving (i.e., running). Therefore, when the existence state of a certain key thread is not surviving, the mobile phone or the thread using module of the mobile phone does not acquire the thread identification of the key thread. Specifically, the mobile phone or the thread using module of the mobile phone can determine the existence state of the key thread while determining the thread name of the key thread in a mode of looking at the proc/t id/comm of the kernel node.
S408, the thread identifier distribution module of the mobile phone determines a second thread identifier of the target thread in the thread identifiers except all the thread identifiers corresponding to the key thread identifier distribution data according to a default distribution rule.
For example, the default allocation rule may be a second thread identifier of the target thread, where the thread identifier with the smallest value among all the thread identifiers except for the thread identifiers corresponding to the key thread identifier allocation data is determined. Of course, any other feasible default allocation rule is also possible in practice.
It should be noted that, in the embodiment of the present application, the first thread identifier and the second thread identifier are only used as distinction between the thread identifiers in two different situations where the target thread is a critical thread and a non-critical thread, and do not represent that the target thread has two thread identifiers.
In one possible implementation manner, if the thread information of a plurality of key threads is included in the key thread identification allocation data, and the key thread identification allocation data includes an identification allocation range of a process to which each key thread belongs in the identification allocation data. The step S408 may specifically be that the thread identifier allocation rule determines, according to a default allocation rule, a second thread identifier of the target thread from among the thread identifiers outside the allocation ranges of all the key identifiers corresponding to the key thread identifier allocation data.
In another possible implementation manner, if the thread information of a plurality of critical threads is included in the critical thread identification allocation data, and the thread identification of each critical thread is included in the identification allocation data included in the critical thread identification allocation data. The step S408 may specifically be that the thread identifier allocation rule determines, according to a default allocation rule, a second thread identifier of the target thread from among the thread identifiers other than the thread identifiers of all the key identifiers corresponding to the key thread identifier allocation data.
Thus, the key thread can be ensured to have sufficient thread identifications for allocation, and the common thread can obtain the thread identifications according to the original allocation rule.
In some embodiments, in order to ensure uniformity of processing logic, the thread creation module of the mobile phone also sends an identifier allocation request to the thread identifier allocation module if it is determined that the target thread is not a critical thread, where the identifier allocation request does not carry thread information of the target thread and is only used for requesting allocation of a thread identifier. Thereafter, S408-S410 may be performed to complete the determination of the second thread identification of the target thread, and the creation of the target thread.
S409, the thread allocation module of the mobile phone sends a second thread identification to the thread creation module.
In some embodiments, the thread identifier allocation module may specifically send a thread identifier allocation response to the thread creation module, where the thread identifier allocation response carries second indication information, where the second indication information indicates that the thread identifier of the target thread is the second thread identifier.
S410, the thread creation module of the mobile phone receives the second thread identification from the thread identification distribution module and completes creation of the target thread based on the second thread identification.
The specific implementation of S410 may refer to the related expression of S407, which is not described herein.
Based on the technical scheme provided by the embodiment of the application, the data can be allocated based on the pre-configured key thread identification, and the key thread can be allocated with a fixed thread identification when being created each time. The key thread identifier allocation data may be used to guide allocation of the thread identifier of the key thread, and fix the thread identifier of the allocated key thread. In this way, according to the technical scheme, the fixed thread identifier can be allocated to the specific key thread based on the pre-configured key thread identifier allocation data, so that when the key thread identifier needs to be acquired by the subsequent mobile phone, the thread identifier of the key thread can be accurately and rapidly acquired, and the acquisition efficiency of the thread identifier of the key thread is improved. And furthermore, an optimization strategy aiming at improving the smoothness of the system based on the thread identification of the key thread is smoothly implemented, and the use experience of a user is improved.
In some embodiments, if the thread information of the plurality of critical threads is included in the critical thread identification allocation data, and the thread identification of each critical thread is included in the identification allocation data included in the critical thread identification allocation data. The thread creation module of the mobile phone may further determine, after determining the thread information of the target thread, a desired thread identification of the target thread from the critical thread identification allocation data based on the thread information of the target thread. The thread creation module may then send the desired thread identification and the thread information of the target thread to the thread identification assignment module to cause the thread identification assignment module to determine a final first thread identification of the target program based on the desired thread identification and the critical thread identification assignment data. The thread identification assignment module may then return the first thread identification to the thread creation module to cause it to complete creation of the target thread. Based on this, referring to fig. 7, another thread identifier allocation method is further provided in the embodiment of the present application, and the method may include S701-S711:
s701, when a thread creation module of the mobile phone creates a target thread, determining thread information of the target thread.
The specific implementation of S701 may refer to the relevant description of S401 in the foregoing embodiment, which is not repeated herein.
S702, a thread creation module of the mobile phone judges whether the target thread is a key thread or not based on thread information of the target thread and key thread identification allocation data.
Specifically, if the thread information of a certain critical thread in the critical thread identification allocation data is the same as the thread information of the target thread, the target thread can be determined to be the critical thread. If the thread information of the key thread which does not exist in the key thread identification allocation data is the same as the thread information of the target thread, the target thread can be determined not to be the key thread.
When the thread creation module of the mobile phone determines that the target thread is a critical thread based on the thread information of the target thread and the critical thread identifier allocation data, the thread identifier allocation module of the subsequent mobile phone may allocate a first thread identifier to the target thread based on the pre-configured critical thread identifier allocation data, i.e. execute subsequent S704 to S708.
Under the condition that the thread creation module of the mobile phone determines that the target thread is not the critical thread based on the thread information of the target thread and the critical thread identification allocation data, the thread identification allocation module of the subsequent mobile phone can allocate a second thread identification for the target thread according to the existing thread identification allocation logic, namely, the subsequent S709-S711 is executed.
It should be noted that, in practice, the judging step of S702 may not exist, and the thread creation module of the mobile phone may directly execute S703 when determining that the target thread is a critical thread based on the thread information of the target thread and the allocation data of the critical thread identifier; if it is determined that the target thread is not a critical thread based on the thread information of the target thread and the critical thread identification allocation data, S709 may be executed. This is not particularly limited in this application.
S703, a thread creation module of the mobile phone determines an expected thread identification of the target thread based on the thread information of the target thread and the key thread identification allocation data.
Specifically, the thread identifier allocation module may determine, as the desired thread identifier of the target thread, the thread identifier of the critical thread whose thread information is the same as the thread information of the target thread in the critical thread identifier allocation data. For example, taking the content of the key thread identifier allocation data as shown in table 6 as an example, if the thread name of the target thread is system_server and the process name of the process to which the target thread belongs is system_server, the desired thread identifier of the target thread is the thread identifier 3000 corresponding to the system_server-system_server.
After the thread creation module obtains the desired thread identification based on the critical thread identification allocation data, the thread identification allocation module may be directly requested to allocate the desired thread identification. That is, at this point the thread creation module may send an identification allocation request carrying the desired thread identification directly to the thread identification allocation module. After receiving the identifier allocation request, the thread identifier allocation module may directly return the first thread identifier, which determines the desired thread identifier as the target thread, to the thread creation module so that the thread creation module completes creation of the target thread.
However, the thread creation module is more open than the thread identification allocation module, and is more prone to malicious operations. Therefore, there may be a situation that the expected thread identification of the target thread determined by the thread creation module after determining that the target thread is the critical thread is not obtained from the critical thread identification allocation data but is directly modified maliciously, or if the target thread itself is a critical thread, the thread creation module is maliciously operated to obtain a thread identification from the critical thread identification allocation data at will, and sends the thread identification to the thread identification allocation module as the expected thread identification to request allocation. In these cases, if the thread identifier allocation module directly allocates the desired thread identifier to the target thread, there may be an error situation that the target thread that is not a critical thread uses the thread identifier that should be allocated to the critical thread or allocates a random thread identifier (not belonging to the thread identifier in the critical thread identifier allocation data) to the target thread that is a critical thread, so that the thread identifier allocation is confused, and some critical threads cannot be allocated to the appropriate fixed thread identifiers.
Based on this, after S703, the thread creation module sends an identification allocation request to the thread identification allocation module, where the thread information of the target thread and the desired thread identification should be carried. The thread identifier allocation module should check the thread information of the target thread and the expected thread identifier based on the key thread identifier allocation data after receiving the identifier allocation request, and if the verification is successful, send the expected thread identifier to the thread creation module as the first thread identifier. If the verification is unsuccessful, the target thread should be identified as a normal thread, and then a second thread identifier may be allocated to the target thread according to the existing thread identifier allocation logic. I.e. the following S704-S711 are performed.
S704, the thread creation module of the mobile phone sends an identification allocation request to the thread identification allocation module.
The identifier allocation request carries the thread information of the target thread and the expected thread identifier, and is used for requesting to allocate the thread identifier for the target thread.
S705, the thread identification allocation module of the mobile phone receives the identification allocation request from the thread creation module.
S706, the thread identification distribution module of the mobile phone verifies the thread information of the target thread and the expected thread identification in the identification distribution request according to the key thread identification distribution data to obtain a verification result.
The verification result is used for indicating that the thread information of the target thread and the expected thread are marked as critical thread data, or the verification result is used for indicating that the thread information of the target thread and the expected thread are marked as non-critical thread data.
Specifically, if the thread information of a certain key thread exists in the key thread identification allocation data and is the same as the thread information of the target thread, and the thread identification of the key thread is the same as the expected thread identification of the target thread, the verification result is used for indicating that the thread information of the target thread and the expected thread identification are the key thread data. At this time, the thread identifier allocation module may directly return the desired thread identifier as the first thread identifier to the thread creation module so that it completes creation of the target thread. I.e. S707 and S708 are performed.
If the thread information of the certain critical thread does not exist in the critical thread identification allocation data and the thread information of the target thread are the same, or the thread identification of the certain critical thread does not exist and the expected thread identification of the target thread are the same, the verification result is used for indicating that the thread information of the target thread and the expected thread identification are not critical thread data. At this time, the target thread may be identified as a normal thread (or not as a critical thread), and the thread identifier allocation module of the subsequent mobile phone may allocate a second thread identifier to the target thread according to the existing thread identifier allocation logic, that is, execute subsequent S709-S711.
S707, the thread identification distribution module of the mobile phone determines the expected thread identification as the first thread identification of the target thread, and sends the first thread identification to the thread creation module.
S708, the thread creation module of the mobile phone receives the first thread identification from the thread identification allocation module and completes the creation of the target thread based on the first thread identification.
Specific implementations of S707 and S708 may refer to the relevant expressions of S406 and S407 in the foregoing embodiments, which are not described herein.
S709, the thread identifier distribution module of the mobile phone determines a second thread identifier of the target thread in the thread identifiers except all the thread identifiers corresponding to the key thread identifier distribution data according to a default distribution rule.
For example, the default allocation rule may be a second thread identifier of the target thread, where the thread identifier with the smallest value among all the thread identifiers except for the thread identifiers corresponding to the key thread identifier allocation data is determined. Of course, any other feasible default allocation rule is also possible in practice.
In one possible implementation manner, if the thread information and the thread identifications of the plurality of key threads are further included in the key thread identification allocation data, a key identification allocation scope of a process to which each key thread belongs is allocated. The step S709 may specifically be that the thread identifier allocation rule determines, according to a default allocation rule, a second thread identifier of the target thread from among the thread identifiers outside the allocation range of all the key identifiers corresponding to the key thread identifier allocation data.
In another possible implementation, if the thread information and the thread identification of the plurality of critical threads are only included in the critical thread identification allocation data. The step S709 may specifically be that the thread identifier allocation rule determines, according to a default allocation rule, a second thread identifier of the target thread from among the thread identifiers other than the thread identifiers of all the key identifiers corresponding to the key thread identifier allocation data.
Thus, the key thread can be ensured to have sufficient thread identifications for allocation, and the common thread can obtain the thread identifications according to the original allocation rule.
In some embodiments, in order to ensure uniformity of processing logic, the thread creation module of the mobile phone also sends an identifier allocation request to the thread identifier allocation module if it is determined that the target thread is not a critical thread, where the identifier allocation request does not carry thread information of the target thread and is only used for requesting allocation of a thread identifier. Thereafter, S709-S711 may be performed to complete the determination of the second thread identification of the target thread, and the creation of the target thread.
S710, the thread allocation module of the mobile phone sends a second thread identification to the thread creation module.
S711, a thread creation module of the mobile phone receives a second thread identification from the thread identification allocation module and completes creation of the target thread based on the second thread identification.
The specific implementation of S710 and S711 may refer to the specific implementation of S409 and S410 in the foregoing embodiments, and will not be described herein.
Based on the technical scheme provided by the embodiment of the application, the data can be allocated based on the pre-configured key thread identification, and the fixed thread identification can be allocated to the key thread more accurately and safely when the key thread is created each time. The key thread identifier allocation data may be used to guide allocation of the thread identifier of the key thread, and fix the thread identifier of the allocated key thread. In this way, according to the technical scheme, the fixed thread identifier can be allocated to the specific key thread based on the pre-configured key thread identifier allocation data, so that when the key thread identifier needs to be acquired by the subsequent mobile phone, the thread identifier of the key thread can be accurately and rapidly acquired, and the acquisition efficiency of the thread identifier of the key thread is improved. And furthermore, an optimization strategy aiming at improving the smoothness of the system based on the thread identification of the key thread is smoothly implemented, and the use experience of a user is improved.
Taking the example that the thread information and the thread identifications of a plurality of key threads are included in the key thread identification allocation data and the key identification allocation scope of the process to which each key thread belongs (wherein the thread identification and the key identification allocation scope are the contents in the key thread identification allocation data represented by allocation data), a specific implementation process of the thread identification allocation method shown in fig. 7 in the present application is described with reference to fig. 8. Referring to fig. 8, the specific implementation procedure of the thread identifier allocation method may include:
1. Firstly, when a mobile phone starts, a thread identifier distribution module analyzes key thread identifier distribution data to acquire thread information of key threads and a key identifier distribution range of each process in the key thread information and buffer the key thread information. Specifically, the thread information of the critical thread may be cached in a key-value pair manner as shown in table 6. The thread identification assignment module may also set the maximum value tidseq of the currently assigned thread identification to 0.
2. When the thread creation module creates a thread (i.e., the target thread described above), it may first determine whether the thread to be created is a normal thread (i.e., a non-critical thread) or a critical thread based on the critical thread identification allocation data after determining the thread information (the thread name and the process name of the process to which the thread belongs) of the thread. The specific determination manner may refer to the relevant description in the foregoing embodiments, and will not be repeated herein.
When the creation of the common thread is determined, the thread creation module sends an identification allocation request which does not carry the thread information of the common thread to the thread identification allocation module. The identity allocation request is for requesting allocation of a thread identity.
When the creation of the key thread is determined, the thread creation module may determine an expected thread identifier of the key thread based on the key thread identifier allocation data, and then send an identifier allocation request carrying the thread information of the key thread and the expected thread identifier to the thread identifier allocation module. The identity allocation request is for requesting allocation of a thread identity. The specific implementation of determining the desired thread identification may refer to the relevant expressions in the foregoing embodiments.
3. When receiving the identifier allocation request from the thread creation module, the thread identifier allocation module of the mobile phone checks the content carried in the identifier allocation request.
Specifically, if the identifier allocation request is empty, it indicates that the identifier allocation request is sent by the thread creation module when the common thread is created. At this time, the thread identifier allocation module may allocate a thread identifier to the normal thread according to an existing default allocation rule. Specifically, the default allocation rule may allocate a minimum one of all the thread identifications except for the thread identifications corresponding to the key thread identification allocation data to the common thread. In particular, the thread identifier allocation module may first determine whether a maximum value +1 of the currently allocated thread identifier is within any key identifier allocation range in the key thread identifier allocation data. If, at this point, to avoid assigning thread identifications available to critical threads as normal threads, the maximum value in all critical identification allocation ranges in the critical thread identification allocation data may be determined to be the maximum value of the currently assigned thread identifications. For example, taking critical thread identification allocation data as an example, as shown in table 5, X000+1000 may be taken as t idSeq. The thread identification most assigned to the normal thread by tidseq+1 is then returned to the thread creation module.
If the identifier allocation request is not null, but the same critical thread as the thread information carried in the identifier allocation request does not exist in the critical thread identifier allocation data, or the expected thread identifier in the identifier allocation request does not exist in the critical thread identifier allocation data, the identifier allocation request can be considered as the identifier allocation request sent by the thread creation module when the common thread is created. At this time, the thread identifier may be allocated to the normal thread according to an existing default allocation rule. The specific implementation is as described in the previous paragraph.
If the identifier allocation request is not null, the key thread with the same thread information carried in the identifier allocation request exists in the key thread identifier allocation data, and the thread identifier of the key thread in the key thread identifier allocation data is the same as the expected thread identifier in the identifier allocation request, the thread creation module can be considered to be the identifier allocation request sent when the key thread is created. At this point, the desired thread identification may be used as the final thread identification assigned to the critical thread created by the thread creation module.
4. The thread creation module completes the creation of the thread based on the thread identification after receiving the thread identification from the identification allocation module.
Based on the technical scheme, the mobile phone can reasonably allocate fixed thread identifications for the key threads based on the pre-configured key thread identification allocation data when the key threads are created. When the thread identification of the key thread needs to be acquired later, the corresponding thread identification can be acquired from the key thread identification distribution data conveniently and rapidly, and the acquisition efficiency of the thread identification of the key thread is improved. And furthermore, an optimization strategy aiming at improving the smoothness of the system based on the thread identification of the key thread is smoothly implemented, and the use experience of a user is improved.
It should be noted that, in practice, critical threads that are not included in the critical thread identifier allocation data may be generated with the increase of application programs and the increase of usage scenarios of users. In order to enable all key threads to be included in the key thread identification allocation data as far as possible, when a manufacturer of the mobile phone or a developer of an application program determines that a new key thread appears, thread update information is sent to the mobile phone through an update server. The thread update information may include thread information of the newly added critical thread and/or thread identification of the newly added critical thread and/or an allocation range of the latest critical identification of the process to which the newly added critical thread belongs. After receiving the thread update information, the mobile phone can update the content in the key thread identifier allocation data by adopting any feasible mode and using the content contained in the update information, so that the key thread identifier allocation data comprises the thread information and/or the thread identifiers of all the latest key threads and/or the latest key identifier allocation range of the affiliated process.
For easy understanding, the thread identifier allocation method provided in the embodiment of the present application is described below with reference to fig. 9. As shown in fig. 9, the method may include S901 to S904:
s901, when the electronic device creates a target thread, determining thread information of the target thread.
The thread information comprises a thread name and a process name of a process to which the thread information belongs.
The specific implementation of S901 may refer to the relevant expression of S401 in the foregoing embodiment, which is not repeated herein.
S902, the electronic equipment determines a thread detection result based on the thread information of the target thread.
The thread detection result is used for indicating that the target thread is a critical thread, or the thread detection result is used for indicating that the target thread is not a critical thread.
In some possible implementations, S902 may include: the electronic device determines a thread detection result based on the thread information of the target thread and the thread information of the plurality of key threads in the key thread identification allocation data. Specifically, if the thread information of the first critical thread is the same as the thread information of the target thread in the thread information of the plurality of critical threads in the critical thread identification allocation data, the thread detection result is used for indicating that the target thread is the critical thread; if the thread information of any one of the key threads does not exist in the thread information of the plurality of key threads in the key thread identification allocation data and the thread information of the target thread are the same, the thread detection result is used for indicating that the target thread is not the key thread.
The specific implementation of S902 may refer to the relevant expression of S402 in the foregoing embodiment, which is not repeated herein.
S903, under the condition that the thread detection result is used for indicating that the target thread is a key thread, the electronic device determines a first thread identification of the target thread based on thread information of the target thread and key thread identification allocation data.
The key thread identification allocation data comprises thread information of a plurality of key threads and identification allocation data; the identification allocation data is used to instruct the electronic device to allocate a fixed thread identification for the critical thread.
The specific implementation of S903 may refer to the relevant expressions of S403 to S405 in the foregoing embodiments, which are not repeated here.
In one possible implementation, if the identifier allocation data includes a key identifier allocation range of a process to which each of the plurality of key threads belongs, the key identifier allocation range is used to indicate a range of thread identifiers available to the key thread under the process; s903 may specifically include: under the condition that the thread identification of the target thread does not exist in the key thread identification allocation data, the electronic equipment determines the thread identification to be allocated in the key identification allocation range corresponding to the target thread from the identification allocation data; and the electronic equipment module determines a first thread identification of the target thread from all the thread identifications to be allocated according to a preset rule.
By way of example, the preset rules may include: and taking the smallest numerical value in all the thread identifications to be allocated as a first thread identification.
In addition, in order to ensure that the data can be conveniently and quickly obtained from the key thread identification when the thread identification of a certain key thread needs to be acquired later. After the execution of S903, the electronic device may further increase, in the critical thread identifier allocation data, a correspondence between the critical thread corresponding to the target thread and the first thread identifier.
Specific implementation of this possible implementation may refer to the relevant expressions in S501-S504 in the foregoing embodiments, and will not be described herein.
In another possible implementation, if the identifier allocation data includes a thread identifier of each of the plurality of critical threads, S903 may specifically include: the electronic device determines, based on the thread information of the target thread, a thread identification identifying a key thread whose thread information in the allocation data is identical to that of the target thread as a first thread identification of the target thread.
For a specific implementation of this possible implementation, reference may be made to the related expression in S601 in the foregoing embodiment, which is not described herein again.
S904, the electronic device completes creation of the target thread based on the first thread identification.
The specific implementation of S904 may refer to the relevant expressions of S406-S407 in the foregoing embodiments, which are not repeated here.
Based on the technical scheme provided by the application, data can be allocated based on the pre-configured key thread identification, and a fixed thread identification can be allocated to the key thread when the key thread is created each time. The key thread identifier allocation data may be used to guide allocation of the thread identifier of the key thread, and fix the thread identifier of the allocated key thread. In this way, according to the technical scheme, the fixed thread identifier can be allocated to the specific key thread based on the pre-configured key thread identifier allocation data, so that when the key thread identifier needs to be acquired by the subsequent electronic equipment, the thread identifier of the key thread can be accurately and rapidly acquired, and the acquisition efficiency of the thread identifier of the key thread is improved. And furthermore, an optimization strategy aiming at improving the smoothness of the system based on the thread identification of the key thread is smoothly implemented, and the use experience of a user is improved.
In some embodiments, if the identifier allocation data includes a thread identifier of each of the plurality of critical threads, and the thread detection result is used to indicate that the target thread is a critical thread, the method further includes: the electronic device determines an expected thread identification of the target thread based on thread information and key thread identification allocation data of the target thread; the electronic device determines the expected thread identification as a first thread identification of the target thread; the electronic device completes creation of the target thread based on the first thread identification.
Specifically, the specific implementation and effect of the above solution may refer to the relevant expression of S703 in the foregoing embodiment, which is not described herein again.
Further, after the electronic device determines the desired thread identifier of the target thread based on the thread information of the target thread and the allocation data of the critical thread identifier, the method further includes: the electronic equipment checks the thread information of the target thread and the expected thread identification of the target thread based on the key thread identification allocation data to obtain a check result; the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as key thread data, or the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as non-key thread data; in the case that the verification result is used to indicate the thread information of the target thread and the expected thread identification of the target thread as the critical thread data, the electronic device determines the expected thread identification as the first thread identification of the target thread.
Specifically, the specific implementation and effect of the above solution may refer to the relevant descriptions of S704-S706 in the foregoing embodiments, which are not repeated herein.
In addition, in order to ensure that the electronic device can normally assign a thread identifier to a thread that is not a critical thread, if the thread detection result is used to indicate that the target thread is not a critical thread, the method further includes: and the electronic equipment determines a second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data according to a default allocation rule. Illustratively, the default allocation rules include: and determining the thread identifier with the minimum value as a second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data.
Specifically, the specific implementation and effect of the above solution may refer to the relevant expressions of S408-S410 or S709-S711 in the foregoing embodiments, which are not repeated herein.
It will be appreciated that, in order to achieve the above-mentioned functions, the electronic device includes corresponding hardware structures and/or software modules for performing the respective functions. Those of skill in the art will readily appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is implemented as hardware or computer software driven hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the embodiments of the present application.
The embodiment of the application may divide the functional modules of the electronic device according to the method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The integrated modules may be implemented in hardware or in software functional modules. It should be noted that, in the embodiment of the present invention, the division of the modules is schematic, which is merely a logic function division, and other division manners may be implemented in actual implementation.
In the case of dividing each functional module by using each corresponding function, referring to fig. 10, an embodiment of the present application provides an electronic device, which may implement the thread identifier allocation method provided in the foregoing embodiment. The electronic device may include a thread creation module 1001 and a thread identification assignment module 1002.
Specifically, the thread creation module 1001 is configured to determine thread information of a target thread when the target thread is created; the thread information comprises a thread name and a process name of a process to which the thread information belongs; the thread creation module 1001 is further configured to determine a thread detection result based on thread information of the target thread; the thread detection result is used for indicating that the target thread is a critical thread, or the thread detection result is used for indicating that the target thread is not a critical thread; the thread identifier allocation module 1002 is configured to determine, based on the thread information of the target thread and the key thread identifier allocation data determined by the thread creation module 1001, a first thread identifier of the target thread when the thread detection result determined by the thread creation module 1001 is used to indicate that the target thread is a key thread; the key thread identification allocation data comprises thread information of a plurality of key threads and identification allocation data; the identifier allocation data is used for indicating the electronic equipment to allocate a fixed thread identifier for the key thread; the thread creation module 1001 is further configured to complete creation of the target thread based on the first thread identification determined by the thread identification allocation module 1002.
Optionally, the thread creation module 1001 is specifically configured to: and determining a thread detection result based on the thread information of the target thread and the thread information of a plurality of key threads in the key thread identification allocation data.
Optionally, the thread creation module 1001 is specifically configured to: if the thread information of the first key thread is the same as the thread information of the target thread in the thread information of the plurality of key threads in the key thread identification allocation data, the thread detection result is used for indicating that the target thread is the key thread; if the thread information of any one of the key threads does not exist in the thread information of the plurality of key threads in the key thread identification allocation data and the thread information of the target thread are the same, the thread detection result is used for indicating that the target thread is not the key thread.
Optionally, the identifier allocation data includes a key identifier allocation range of a process to which each of the plurality of key threads belongs, where the key identifier allocation range is used to indicate a range of thread identifiers available to the key thread under the process; the thread identifier allocation module 1002 is specifically configured to: under the condition that the thread identification of the target thread does not exist in the key thread identification allocation data, determining the thread identification to be allocated in the key identification allocation range corresponding to the target thread from the identification allocation data; and determining the first thread identification of the target thread from all the thread identifications to be allocated according to a preset rule.
Optionally, the preset rule includes: and taking the smallest numerical value in all the thread identifications to be allocated as a first thread identification.
Optionally, the thread identifier allocation module 1002 is further configured to add, in the critical thread identifier allocation data, a correspondence between a critical thread corresponding to the target thread and the first thread identifier.
Optionally, the identification allocation data includes a thread identification of each of the plurality of critical threads; the thread identifier allocation module 1002 is specifically configured to: the electronic device determines, based on the thread information of the target thread, a thread identification identifying a key thread whose thread information in the allocation data is identical to that of the target thread as a first thread identification of the target thread.
Optionally, the identifier allocation data includes a thread identifier of each of the plurality of critical threads, and when the thread detection result is used to indicate that the target thread is a critical thread, the thread creation module 1001 is further configured to determine, based on the thread information of the target thread and the critical thread identifier allocation data, an expected thread identifier of the target thread; the thread identifier allocation module 1002 is further configured to determine the desired thread identifier determined by the thread creation module 1001 as the first thread identifier of the target thread; the thread creation module 1001 is further configured to complete creation of the target thread based on the first thread identification determined by the thread identification allocation module 1002.
Optionally, after the thread creation module 1001 determines the desired thread identifier of the target thread, the thread identifier allocation module 1002 is further configured to verify the thread information of the target thread and the desired thread identifier of the target thread based on the critical thread identifier allocation data, to obtain a verification result; the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as key thread data, or the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as non-key thread data; in the case where the verification result is used to indicate that the thread information of the target thread and the desired thread identification of the target thread are critical thread data, the thread identification allocation module 1002 is further configured to determine the desired thread identification as the first thread identification of the target thread.
Optionally, when the thread detection result is used to indicate that the target thread is not a critical thread, the thread identifier allocation module 1002 is further configured to determine, according to a default allocation rule, a second thread identifier of the target thread from the thread identifiers other than all the thread identifiers corresponding to the critical thread identifier allocation data.
Optionally, the default allocation rule includes: and determining the thread identifier with the minimum value as a second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data.
The specific manner in which the respective modules perform the operations in the electronic device in the above embodiment has been described in detail in the embodiment of the thread identification allocation method in the foregoing embodiment, and will not be specifically described herein. The related beneficial effects of the method may also refer to the related beneficial effects of the thread identifier allocation method, which are not described herein.
The embodiment of the application also provides electronic equipment, which comprises: a memory and one or more processors; the memory is coupled with the processor; wherein the memory has stored therein computer program code comprising computer instructions which, when executed by the processor, cause the electronic device to perform the thread identification allocation method as provided by the foregoing embodiments. The specific structure of the electronic device may refer to the structure of the electronic device shown in fig. 2.
The present application also provides a computer readable storage medium comprising computer instructions which, when executed on an electronic device, cause the electronic device to perform the thread identification allocation method as provided in the foregoing embodiments.
Embodiments of the present application also provide a computer program product containing executable instructions that, when run on an electronic device, cause the electronic device to perform a thread identification allocation method as provided by the foregoing embodiments.
Embodiments of the present application also provide a chip system, as shown in fig. 11, the chip system 1100 includes at least one processor 1101 and at least one interface circuit 1102. The processor 1101 and interface circuit 1102 may be interconnected by wires. For example, interface circuit 1102 may be used to receive signals from other devices (e.g., a memory of an electronic apparatus). For another example, the interface circuit 102 may be used to send signals to other devices (e.g., the processor 1101).
The interface circuit 1102 may, for example, read instructions stored in a memory and send the instructions to the processor 1101. The instructions, when executed by the processor 1101, may cause the electronic device to perform the various steps of the embodiments described above. Of course, the chip system may also include other discrete devices, which are not specifically limited in this embodiment of the present application.
It will be apparent to those skilled in the art from this description that, for convenience and brevity of description, only the above-described division of the functional modules is illustrated, and in practical application, the above-described functional allocation may be performed by different functional modules according to needs, i.e. the internal structure of the apparatus is divided into different functional modules to perform all or part of the functions described above.
In the several embodiments provided in this application, it should be understood that the disclosed apparatus/devices and methods may be implemented in other ways. For example, the apparatus/device embodiments described above are merely illustrative, e.g., the division of the modules or units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another apparatus, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and the parts displayed as units may be one physical unit or a plurality of physical units, may be located in one place, or may be distributed in a plurality of different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a readable storage medium. Based on such understanding, the technical solution of the embodiments of the present application may be essentially or a part contributing to the prior art or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium, including several instructions for causing a device (may be a single-chip microcomputer, a chip or the like) or a processor (processor) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a read-only memory (read on ly memory, ROM), a random access memory (random access memory, RAM), a magnetic disk, or an optical disk, or the like, which can store program codes.
The foregoing is merely a specific embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered in the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (13)

1. A thread identification allocation method, characterized in that it is applied to an electronic device, the method comprising:
when the electronic equipment creates a target thread, determining thread information of the target thread; the thread information comprises a thread name and a process name of a process to which the thread information belongs;
the electronic equipment determines a thread detection result based on the thread information of the target thread; the thread detection result is used for indicating that the target thread is a critical thread, or the thread detection result is used for indicating that the target thread is not a critical thread;
under the condition that the thread detection result is used for indicating that the target thread is a key thread, the electronic equipment determines a first thread identification of the target thread based on thread information of the target thread and key thread identification allocation data; the key thread identification allocation data comprises thread information of a plurality of key threads and identification allocation data; the identification allocation data is used for indicating the electronic equipment to allocate a fixed thread identification for the key thread;
the electronic device completes creation of the target thread based on the first thread identification.
2. The method of claim 1, wherein the electronic device determining a thread detection result based on thread information of the target thread comprises:
And the electronic equipment determines a thread detection result based on the thread information of the target thread and the thread information of a plurality of key threads in the key thread identification allocation data.
3. The method of claim 2, wherein the electronic device determining a thread detection result based on the thread information of the target thread and the thread information of the plurality of critical threads in the critical thread identification allocation data comprises:
if the thread information of the first key thread is the same as the thread information of the target thread in the thread information of the plurality of key threads in the key thread identification allocation data, the thread detection result is used for indicating that the target thread is the key thread;
if the thread information of any one of the plurality of key threads in the key thread identification allocation data is not the same as the thread information of the target thread, the thread detection result is used for indicating that the target thread is not the key thread.
4. A method according to any of claims 1-3, wherein the identification allocation data comprises a critical identification allocation scope of a process to which each of the plurality of critical threads belongs, the critical identification allocation scope being used to indicate a scope of thread identifications available to critical threads under the process; the electronic device determines a first thread identification of the target thread based on thread information and key thread identification allocation data of the target thread, including:
The electronic equipment determines the thread identification to be allocated in the key identification allocation range corresponding to the target thread from the identification allocation data under the condition that the thread identification of the target thread does not exist in the key thread identification allocation data;
and the electronic equipment module determines a first thread identification of the target thread from all the thread identifications to be allocated according to a preset rule.
5. The method of claim 4, wherein the preset rules comprise: and taking the smallest numerical value in all the thread identifications to be allocated as the first thread identification.
6. The method of claim 4, wherein the electronic device module, after determining the first thread identification of the target thread from all the thread identifications to be allocated according to a preset rule, further comprises:
and the electronic equipment adds the corresponding relation between the key thread corresponding to the target thread and the first thread identifier in the key thread identifier allocation data.
7. A method according to any of claims 1-3, wherein the identification allocation data comprises a thread identification of each of the plurality of critical threads; the electronic device determines a first thread identification of the target thread based on thread information and key thread identification allocation data of the target thread, including:
The electronic device determines the thread identification of the key thread with the same thread information as the thread information of the target thread as the first thread identification of the target thread based on the thread information of the target thread.
8. The method of claim 1, wherein the thread identification of each of the plurality of critical threads is included in the identification allocation data, and wherein in a case where the thread detection result is used to indicate that the target thread is a critical thread, the method further comprises:
the electronic equipment determines an expected thread identification of the target thread based on the thread information of the target thread and the key thread identification allocation data;
the electronic device determining the expected thread identification as a first thread identification of the target thread;
the electronic device completes creation of the target thread based on the first thread identification.
9. The method of claim 8, wherein the electronic device, after determining the desired thread identification for the target thread based on the thread information for the target thread and the critical thread identification allocation data, further comprises:
The electronic equipment verifies the thread information of the target thread and the expected thread identification of the target thread based on the key thread identification allocation data to obtain a verification result; the verification result is used for indicating that the thread information of the target thread and the expected thread identification of the target thread are key thread data, or the verification result is used for indicating that the thread information of the target thread and the expected thread identification of the target thread are non-key thread data;
and under the condition that the verification result is used for indicating the thread information of the target thread and the expected thread identification of the target thread as key thread data, the electronic device determines the expected thread identification as a first thread identification of the target thread.
10. The method according to any one of claims 1-9, wherein, in a case where the thread detection result is used to indicate that the target thread is not a critical thread, the electronic device determines, according to a default allocation rule, a second thread identifier of the target thread from among the thread identifiers other than all the thread identifiers corresponding to the critical thread identifier allocation data.
11. The method of claim 10, wherein the default allocation rule comprises: and determining the thread identifier with the minimum value as the second thread identifier of the target thread from the thread identifiers except all the thread identifiers corresponding to the key thread identifier allocation data.
12. An electronic device comprising a memory and one or more processors; the memory is coupled with the processor; wherein the memory has stored therein computer program code comprising computer instructions which, when executed by the processor, cause the electronic device to perform the thread identification allocation method of any of claims 1-11.
13. A computer readable storage medium comprising computer instructions which, when run on an electronic device, cause the electronic device to perform the thread identification allocation method of any one of claims 1-11.
CN202310851575.3A 2023-07-11 2023-07-11 Thread identifier distribution method, electronic equipment and storage medium Pending CN117707755A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310851575.3A CN117707755A (en) 2023-07-11 2023-07-11 Thread identifier distribution method, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310851575.3A CN117707755A (en) 2023-07-11 2023-07-11 Thread identifier distribution method, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117707755A true CN117707755A (en) 2024-03-15

Family

ID=90150328

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310851575.3A Pending CN117707755A (en) 2023-07-11 2023-07-11 Thread identifier distribution method, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117707755A (en)

Similar Documents

Publication Publication Date Title
CN112783564B (en) Method for accelerating starting of application program and electronic equipment
US10657172B2 (en) Method and apparatus for managing image metadata
WO2021185352A1 (en) Version upgrade method and related apparatus
CN109271211A (en) Method, apparatus of attending to anything else, equipment and the medium of application program
CN112817634B (en) COTA package downloading method and device
CN114741256B (en) Sensor monitoring method and device and terminal equipment
CN114096946A (en) Method and apparatus for managing applications
CN113885928B (en) Program updating method and electronic device
CN117707755A (en) Thread identifier distribution method, electronic equipment and storage medium
KR20190098516A (en) Method for managing data related to application and electronic device thereof
CN116521180B (en) Compiling optimization method, electronic equipment and storage medium
CN112711636A (en) Data synchronization method, device, equipment and medium
CN116719556B (en) System upgrading method and electronic equipment
CN117093315B (en) Upgrade content display method, electronic equipment and storage medium
CN116049097B (en) Management method of camera database file and electronic equipment
CN116701299B (en) Catalog management method and related device
CN116688494B (en) Method and electronic device for generating game prediction frame
CN117009023B (en) Method for displaying notification information and related device
CN117707563A (en) Application resource processing method and related equipment
CN116672707B (en) Method and electronic device for generating game prediction frame
CN114168115B (en) Communication system, application downloading method and device
CN116702100B (en) Authority management method and electronic equipment
WO2024032022A1 (en) Application icon visualization method and device
CN117874843A (en) Method, apparatus and computer readable storage medium for expanding protected memory space
CN116719556A (en) System upgrading method and electronic equipment

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