Thread identification allocation method, electronic device and storage medium

By allocating data with pre-configured key thread identification, fixed thread identification is assigned to the key threads of electronic devices, which solves the problem of low-efficiency in the prior art and improves system fluency and user experience.

CN117707755BActive Publication Date: 2024-11-01HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310851575.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-11
Publication Date
2024-11-01
Estimated Expiration
2043-07-11

AI Technical Summary

Technical Problem

In the prior art, electronic devices are inefficient when acquiring thread identifications for critical threads, because thread identifications may be different each time they run, resulting in inconsistent acquisition and allocation, affecting system fluency and user experience.

Method used

A thread identification allocation method is adopted to allocate data through pre-configured key thread identification, and a fixed thread identification is assigned to key thread identification when creating them, ensuring accurate and fast subsequent acquisition and improving the efficiency of thread identification acquisition.

Benefits of technology

Through fixed thread identification allocation, the implementation efficiency of system fluency optimization strategies is improved, the user experience is improved, and the problems of confusion in thread identification allocation and maintenance difficulties are avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117707755B_ABST
    Figure CN117707755B_ABST
Patent Text Reader

Abstract

The present application provides a thread identifier allocation method, an electronic device, and a storage medium, which relate to the field of thread scheduling and can allocate a fixed thread identifier to a key thread. The method is applied to an electronic device, and specifically includes: when creating a target thread, determining the thread information of the target thread; based on the thread information of the target thread, determining the thread detection result; the thread detection result is used to indicate that the target thread is a key thread, or the thread detection result is used to indicate that the target thread is not a key thread; when the thread detection result is used to indicate that the target thread is a key thread, based on the thread information of the target thread and the key thread identifier allocation data, determining the first thread identifier of the target thread; the key thread identifier allocation data includes the thread information of multiple key threads, and the identifier allocation data; the identifier allocation data is used to indicate that the electronic device allocates a fixed thread identifier to the key thread; and the creation of the target thread is completed based on the first thread identifier.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of charging control, and in particular to a thread identification allocation method, an electronic device and a storage medium. Background Art

[0002] With the rapid development of electronic equipment technology, mobile phones and other electronic devices have become more and more indispensable tools for people. In the process of users using electronic devices, some key scenes that are more important to users (such as game scenes, video playback scenes, voice call scenes, etc.) require the fluency of electronic devices (specifically, system fluency) to be good enough to ensure the user experience. In order to ensure the fluency of electronic devices in key scenes, it is necessary to implement specific optimization strategies based on the available resources and usage requirements of current electronic devices. The optimization strategy can specifically be to set the priority (such as the priority of operation and the priority of using resources, etc.) or affinity (referring to the occupation configuration of electronic device processor resources) of key threads that have a strong dependence on key scenes (such as the surfaceflinger thread that is strongly dependent on the operation of the game screen in the game scene) (specifically, it can be adjusted). The setting of the priority or affinity of the key thread needs to be based on the thread identity document (TID) of the key thread. Based on this, accurately obtaining the thread identity of the key thread is the primary focus of the optimization strategy of the electronic device for fluency. Summary of the invention

[0003] In the related art, since the thread identifier assigned by the electronic device to the same thread may be different each time the thread is run during operation, it takes a long time to obtain the thread identifier of a key thread each time, and the acquisition efficiency is low.

[0004] In response to the above technical problems, an embodiment of the present application provides a thread identifier allocation method, an electronic device and a storage medium, which can allocate a fixed thread identifier to a specific key thread, so that when the key thread identifier is needed later, the thread identifier of the key thread can be obtained accurately and quickly.

[0005] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:

[0006] In the first aspect, the present application provides a thread identifier allocation method, which is applied to an electronic device. The method includes: when creating a target thread, the electronic device determines the thread information of the target thread; the thread information includes the thread name and the process name of the process to which it belongs; the electronic device determines the thread detection result based on the thread information of the target thread; the thread detection result is used to indicate that the target thread is a critical thread, or the thread detection result is used to indicate that the target thread is not a critical thread; when the thread detection result is used to indicate that the target thread is a critical thread, the electronic device determines the first thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data; the critical thread identifier allocation data includes the thread information of multiple critical threads, and the identifier allocation data; the identifier allocation data is used to instruct the electronic device to allocate a fixed thread identifier to the critical thread; the electronic device completes the creation of the target thread based on the first thread identifier.

[0007] Based on the technical solution provided by the embodiment of the present application, it is possible to assign a fixed thread identifier to a critical thread each time it is created based on pre-configured critical thread identifier allocation data. Among them, the critical thread identifier allocation data can be used to guide the allocation of the thread identifier of the critical thread, and the thread identifier of the critical thread after allocation is fixed. In this way, since the technical solution can assign a fixed thread identifier to a specific critical thread based on the pre-configured critical thread identifier allocation data, subsequent electronic devices can accurately and quickly obtain the thread identifier of the critical thread when they need to obtain the critical thread identifier, thereby improving the efficiency of obtaining the thread identifier of the critical thread. In addition, the optimization strategy based on the thread identifier of the critical thread, which aims to improve the fluency of the system, is smoothly implemented, thereby improving the user experience.

[0008] In a possible design manner of the first aspect, the electronic device determines the thread detection result based on the thread information of the target thread, including: the electronic device determines the thread detection result based on the thread information of the target thread and the thread information of multiple key threads in the key thread identification allocation data.

[0009] In this way, the pre-configured critical thread identification allocation data can be used to accurately determine the thread detection result of whether the target thread is a critical thread.

[0010] In a possible design manner of the first aspect, the electronic device determines a thread detection result based on the thread information of the target thread and the thread information of multiple key threads in the key thread identifier allocation data, including: if, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of a first key thread is the same as the thread information of the target thread, then the thread detection result is used to indicate that the target thread is a key thread; if, among the thread information of multiple key threads in the key thread identifier allocation data, there is no key thread whose thread information is the same as the thread information of the target thread, then the thread detection result is used to indicate that the target thread is not a key thread.

[0011] Based on the above implementation scheme, it is possible to accurately determine whether the target thread is a critical thread, providing a basis for the execution of subsequent processes.

[0012] In a possible design method of the first aspect, the identifier allocation data includes a key identifier allocation range of a process to which each key thread among multiple key threads belongs, and the key identifier allocation range is used to indicate the range of thread identifiers available to the key threads under the process; the electronic device determines the first thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data, including: when the thread identifier of the target thread does not exist in the key thread identifier allocation data, the electronic device determines the to-be-allocated thread identifier in the key identifier allocation range corresponding to the target thread from the identifier allocation data; the electronic device module determines the first thread identifier of the target thread from all the to-be-allocated thread identifiers according to a preset rule.

[0013] Based on the above technical solution, the electronic device can allocate a fixed thread identifier to the target thread, which is a 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 fixed thread identifier is reflected in specific data (i.e., the key thread identifier allocation data). In this way, whenever the thread identifier of a key thread is needed, the thread identifier of the key thread can be obtained from the key thread identifier allocation data, so that operations (such as optimization strategies) that need to be implemented based on the thread identifier of the key thread can be implemented smoothly.

[0014] In a possible design manner of the first aspect, the preset rule includes: taking the one with the smallest value among all the thread identifiers to be allocated as the first thread identifier.

[0015] In a possible design of the first aspect, after the electronic device module determines the first thread identifier of the target thread from all thread identifiers to be assigned according to a preset rule, the method also includes: the electronic device adds a correspondence between the key thread corresponding to the target thread and the first thread identifier in the key thread identifier allocation data.

[0016] In this way, it can be ensured that when the thread identifier of a key thread needs to be obtained later, the data can be allocated from the key thread identifier and obtained conveniently and quickly.

[0017] In a possible design method of the first aspect, the identifier allocation data includes a thread identifier of each key thread in multiple key threads; the electronic device determines the first thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data, including: the electronic device determines the thread identifier of the key thread whose thread information in the identifier allocation data is the same as the thread information of the target thread as the first thread identifier of the target thread based on the thread information of the target thread.

[0018] Based on the above technical solution, the electronic device can allocate a fixed thread identifier to the target thread, which is a 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 fixed in the key thread identifier allocation data. In this way, when the subsequent electronic device needs the thread identifier of a key thread at any time, it can obtain the thread identifier of the key thread from the key thread identifier allocation data, so that the operations that need to be implemented based on the thread identifier of the key thread (such as optimization strategies) can be smoothly implemented.

[0019] In a possible design of the first aspect, the identifier allocation data includes a thread identifier of each key thread in multiple key threads. When the thread detection result is used to indicate that the target thread is a key thread, the method also includes: the electronic device determines the expected thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data; the electronic device determines the expected thread identifier as the first thread identifier of the target thread; and the electronic device completes the creation of the target thread based on the first thread identifier.

[0020] Based on the above technical solution, it is possible to allocate a fixed thread identifier to a key thread more accurately and safely each time the key thread is created based on the pre-configured key thread identifier allocation data. Among them, the key thread identifier allocation data can be used to guide the allocation of the thread identifier of the key thread, and the thread identifier of the key thread after allocation is fixed. In this way, since the technical solution can allocate a fixed thread identifier to a specific key thread based on the pre-configured key thread identifier allocation data, the subsequent mobile phone can accurately and quickly obtain the thread identifier of the key thread when it needs to obtain the key thread identifier, thereby improving the efficiency of obtaining the thread identifier of the key thread. In addition, the optimization strategy based on the thread identifier of the key thread is smoothly implemented to improve the user experience.

[0021] In a possible design manner of the first aspect, after the electronic device determines the expected thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data, the method also includes: the electronic device verifies the thread information of the target thread and the expected thread identifier of the target thread based on the critical thread identifier allocation data to obtain a verification result; the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, or the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are non-critical thread data; when the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, the electronic device determines the expected thread identifier as the first thread identifier of the target thread.

[0022] In practice, thread creation and thread ID allocation are completed by different modules or services, and the thread creation module responsible for thread creation is more open than the thread ID allocation module responsible for thread ID allocation, and is more susceptible to malicious operations. Therefore, it may happen that the expected thread ID of the target thread determined by the thread creation module after determining that the target thread is a critical thread is not obtained from the critical thread ID allocation data but is directly modified by malicious means, or when the target thread itself is a critical thread, the thread creation module is maliciously operated to obtain a thread ID from the critical thread ID allocation data as the expected thread ID and send it to the thread ID allocation module for allocation. In these cases, if the thread ID allocation module directly allocates the expected thread ID to the target thread, it may cause the target thread that is not a critical thread to use the thread ID that should be allocated to the critical thread or to allocate a random thread ID (not belonging to the thread ID in the critical thread ID allocation data) to the target thread that is a critical thread, resulting in confusion in thread ID allocation, and some critical threads will not be allocated to appropriate fixed thread IDs. Based on this, after determining the expected thread identifier, the thread identifier allocation module should verify the thread information of the target thread and the expected thread identifier based on the key thread identifier allocation data. If the verification is successful, the expected thread identifier is used as the first thread identifier of the target thread. If the verification is unsuccessful, the target thread should be identified as a normal thread, and then the second thread identifier can be allocated to the target thread according to the existing thread identifier allocation logic.

[0023] Therefore, based on the above technical solution, fixed thread identifiers can be assigned to key threads more safely and accurately.

[0024] In a possible design of the first aspect, when the thread detection result is used to indicate that the target thread is not a critical thread, the method also includes: the electronic device determines, according to a default allocation rule, a second thread identifier of the target thread from thread identifiers other than all thread identifiers corresponding to the critical thread identifier allocation data.

[0025] Based on the above technical solution, the electronic device can normally allocate thread identifiers to non-critical threads.

[0026] In a possible design manner of the first aspect, the default allocation rule includes: determining a thread identifier with the smallest value among all thread identifiers other than the thread identifiers corresponding to the critical thread identifier allocation data as the second thread identifier of the target thread.

[0027] In a second aspect, the present application provides an electronic device, which includes a thread creation module and a thread identifier allocation module. Wherein, the thread creation module is used to determine the thread information of the target thread when creating the target thread; the thread information includes the thread name and the process name of the process to which it belongs; the thread creation module is also used to determine the thread detection result based on the thread information of the target thread; the thread detection result is used to indicate that the target thread is a key thread, or the thread detection result is used to indicate that the target thread is not a key thread; the thread identifier allocation module is used to determine the first thread identifier of the target thread based on the thread information of the target thread determined by the thread creation module and the key thread identifier allocation data when the thread detection result determined by the thread creation module indicates that the target thread is a key thread; the key thread identifier allocation data includes the thread information of multiple key threads, and the identifier allocation data; the identifier allocation data is used to instruct the electronic device to allocate a fixed thread identifier to the key thread; the thread creation module is also used to complete the creation of the target thread based on the first thread identifier determined by the thread identifier allocation module.

[0028] In a possible design manner of the second aspect, the thread creation module is specifically used to determine the thread detection result based on the thread information of the target thread and the thread information of multiple key threads in the key thread identifier allocation data.

[0029] In a possible design method of the second aspect, the thread creation module is specifically used to: if, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of the first key thread is the same as the thread information of the target thread, then the thread detection result is used to indicate that the target thread is a key thread; if, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of any key thread is not the same as the thread information of the target thread, then the thread detection result is used to indicate that the target thread is not a key thread.

[0030] In a possible design of the second aspect, the identifier allocation data includes a key identifier allocation range of a process to which each key thread among multiple key threads belongs, and the key identifier allocation range is used to indicate the range of thread identifiers available to the key threads under the process; the thread identifier allocation module is specifically used to: when the thread identifier of the target thread does not exist in the key thread identifier allocation data, determine the to-be-allocated thread identifier in the key identifier allocation range corresponding to the target thread from the identifier allocation data; and determine the first thread identifier of the target thread from all the to-be-allocated thread identifiers according to preset rules.

[0031] In a possible design manner of the second aspect, the preset rule includes: taking the one with the smallest value among all the thread identifiers to be allocated as the first thread identifier.

[0032] In a possible design manner of the second aspect, the thread identifier allocation module is further configured to add a correspondence between a critical thread corresponding to the target thread and the first thread identifier in the critical thread identifier allocation data.

[0033] In a possible design method of the second aspect, the identifier allocation data includes the thread identifier of each key thread in multiple key threads; the thread identifier allocation module is specifically used to: the electronic device determines the thread identifier of the key thread whose thread information in the identifier allocation data is the same as the thread information of the target thread as the first thread identifier of the target thread based on the thread information of the target thread.

[0034] In a possible design manner of the second aspect, the identifier allocation data includes the thread identifier of each key thread in multiple key threads. When the thread detection result is used to indicate that the target thread is a key thread, the thread creation module is also used to determine the expected thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data; the thread identifier allocation module is also used to determine the expected thread identifier determined by the thread creation module as the first thread identifier of the target thread; the thread creation module is also used to complete the creation of the target thread based on the first thread identifier determined by the thread identifier allocation module.

[0035] In a 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 also used 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 to obtain a verification result; the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, or the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are non-critical thread data; when the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, the thread identifier allocation module is also used to determine the expected thread identifier as the first thread identifier of the target thread.

[0036] In a possible design 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 also used to determine the second thread identifier of the target thread from among all thread identifiers other than the critical thread identifier allocation data according to a default allocation rule.

[0037] In a possible design manner of the second aspect, the default allocation rule includes: determining a thread identifier with the smallest value among all thread identifiers other than the thread identifiers corresponding to the critical thread identifier allocation data as the second thread identifier of the target thread.

[0038] In a third aspect, the present application provides an electronic device, comprising: a memory and one or more processors; the memory is coupled to the processor; wherein the memory stores computer program code, the computer program code comprises computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the thread identifier allocation method provided in the first aspect and any possible design method thereof.

[0039] In a fourth aspect, the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the thread identifier allocation method provided in the first aspect and any possible design thereof.

[0040] In a fifth aspect, the present application provides a computer program product comprising executable instructions, which, when executed on an electronic device, enables the electronic device to execute the thread identifier allocation method provided in the first aspect and any possible design thereof.

[0041] In a sixth aspect, a device (for example, the device may be a chip system) is provided, the device including a processor for supporting an electronic device to implement the functions involved in the second aspect above. In one possible design, the device also includes a memory for storing program instructions and data necessary for the electronic device. When the device is a chip system, it may be composed of a chip, or may include a chip and other discrete devices.

[0042] It can be understood that the beneficial effects that can be achieved by the technical solutions provided in the second to sixth aspects provided above can refer to the beneficial effects in the first aspect and any possible design method thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 A schematic diagram of a thread identifier allocation method provided in an embodiment of the present application;

[0044] Figure 2 A schematic diagram of the hardware architecture of an electronic device provided in an embodiment of the present application;

[0045] Figure 3 A schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application;

[0046] Figure 4 A schematic diagram of the principle of a thread identifier allocation method provided in an embodiment of the present application Figure 1 ;

[0047] Figure 5 A schematic diagram of the principle of a thread identifier allocation method provided in an embodiment of the present application Figure 2 ;

[0048] Figure 6 A schematic diagram of the principle of a thread identifier allocation method provided in an embodiment of the present application Figure 3 ;

[0049] Figure 7 A schematic diagram of a thread identifier allocation method provided in an embodiment of the present application Figure 4 ;

[0050] Figure 8 A schematic diagram of a thread identifier allocation method provided in an embodiment of the present application Figure 5 ;

[0051] Fig. 9 A schematic diagram of a thread identifier allocation method provided in an embodiment of the present application Figure 6 ;

[0052] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0053] Fig.11 A schematic diagram of the structure of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments and are not intended to be limiting of the present application. As used in the specification and appended claims of the present application, the singular expressions "a", "an", "said", "above", "the" and "this" are intended to also include plural expressions, unless the context clearly indicates otherwise. It should also be understood that " / " means or, for example, A / B can mean A or B; "and / or" in the text is merely a description of an association relationship of associated objects, indicating that three relationships can exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0055] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.

[0056] The terms "first" and "second" in the following embodiments of the present application are used for descriptive purposes only and should not be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more.

[0057] In order to clearly describe the technical solutions of the embodiments of the present application, some terms and technologies involved in the embodiments of the present application are briefly introduced below:

[0058] Kernel Node: In a computer system, it refers to a data structure or entity in the kernel of the operating system, which is used to represent and manage system resources such as devices, file systems, and processes. Each kernel node has a unique identifier, called a node ID or handle, through which the node can be accessed and operated.

[0059] In Linux systems, kernel nodes are usually presented to user space programs using a virtual file system, allowing them to interact with the nodes like operating ordinary files. This mode is called a device file or special file. For example, the nodes in the / dev directory represent various devices, such as disks, serial ports, printers, etc.

[0060] By interacting with kernel nodes, user space programs (user space programs refer to applications running with user privileges in a computer system) can access and control underlying resources. For device nodes, read and write operations can be used to operate devices; for file system nodes, file read and write and directory operations can be performed; and for process nodes, operations such as reading process status or sending signals can be performed.

[0061] In an embodiment of the present application, the kernel node may be used to store information of all threads in the electronic device (including thread names and thread identifiers TIDs).

[0062] At present, in some key scenes that are important to users (such as startup scenes, sliding scenes, game scenes, video playback scenes, voice call scenes, etc.), the fluency of electronic devices (specifically, system fluency) is required to be good enough to ensure the user experience. In order to achieve this goal, electronic devices are required to implement specific optimization strategies. The optimization strategy can specifically be based on the available resources and usage requirements of electronic devices for key threads that have strong dependencies on key scenes (such as launcher threads that have strong dependencies on desktop display in the startup scene of electronic devices, surfaceflinger threads that have strong dependencies on the operation of game screens in game scenes, etc.) Priority (such as operation priority and resource usage priority, etc.) or affinity (referring to the occupation configuration of electronic device processor resources) setting (specifically, it can be adjustment). The setting of the priority or affinity of the key thread needs to be based on the thread identity document (TID) of the key thread. Based on this, accurately obtaining the thread identity of the key thread is the primary focus of the optimization strategy of the electronic device for fluency.

[0063] In the existing technical solution, since each thread is assigned a different TID each time it is created or run, the method for obtaining the thread identifier of the existing key thread can be as shown in Table 1 below:

[0064] Table 1 - Thread identification methods and restrictions

[0065]

[0066] Among them, for the method of identifying the key thread and obtaining the corresponding thread ID by traversing the information in the kernel node (including the thread name and thread ID) within a time limit, because the kernel node stores a lot of thread information, it takes a long time to identify the key thread and obtain the TI D each time. Moreover, once a thread is restarted, it is necessary to search the thread ID of the thread from the kernel node again, which is more time-consuming.

[0067] As for the method of identifying key threads and obtaining TID when threads are created or run, the timing of thread creation or running is uncontrollable, and it is not possible to easily complete the identification of key threads and obtain TID. In addition, if a thread is not normally allocated TID after restart, it will result in the inability to quickly obtain TID. For example, there are several situations in which a thread is not normally allocated TID after restart:

[0068] In the first case, when a thread terminates, its resources (such as TI D and other status information) may take some time to be completely cleaned up. If the same thread is started again before the cleanup process is completed, the new thread may not obtain a new TI D and continue to use the original invalid TI D.

[0069] In the second case, if there is a problem with the thread management mechanism itself, such as failure to correctly allocate a new TI D when the thread is restarted, the TI D may not be delivered normally.

[0070] In the third case, in a multi-threaded environment, if the creation and destruction of threads are not properly synchronized, it may cause confusion in the allocation of TI Ds when the threads are restarted. For example, if multiple threads are restarted at the same time and compete for new TI Ds, allocation conflicts or duplicate allocations may occur.

[0071] In the above-mentioned cases, the restart of the thread may cause the TID to be not allocated normally, and the TID of the corresponding thread cannot be accurately obtained subsequently.

[0072] For the method of identifying key threads and obtaining TID when renaming threads, if there are too many threads to be identified, it will take a long time to identify the key threads and obtain TID. Thread renaming specifically refers to obtaining a reference to the current thread through a corresponding API or method after the thread is created, and changing the name of the thread by setting the name attribute, that is, completing the setting of the thread name.

[0073] It can be seen that in the existing method for obtaining the thread identifier of the key thread, the way of obtaining the thread identifier of the key thread is time-consuming and has low acquisition efficiency.

[0074] In order to solve the above problems, the embodiment of the present application provides a simplest implementation method for thread ID allocation, that is, by programming, the thread ID of the key thread is directly hard-coded in the process of thread creation of the key thread (which can be called variable hard-coding), so that the thread ID of each key thread is fixed during the use of the electronic device. When the thread ID of a key thread needs to be obtained later, the thread ID of any key thread can be quickly and accurately determined, and the acquisition efficiency is high.

[0075] However, for this thread identifier allocation method, each application or operating system developer can only clarify the correspondence between the key thread and the thread identifier in the thread established in the program developed by itself, and cannot clarify the correspondence between the key programming and the thread identifier in other applications. In other words, in this technical solution, there is no overall information for key threads in the electronic device, and the thread identifier of each key thread cannot be clarified. In this way, if there are many key threads in the electronic device, since there is no specific overall data to indicate which thread identifiers have been occupied, it may cause the preset fixed thread identifier of a key thread to be occupied by ordinary threads or other key threads, resulting in confusion in thread identifier allocation and difficulty in maintenance. In this way, even if the thread identifier of a key thread is quickly obtained later, the priority or affinity set by the thread identifier may also be considered as the priority or affinity of other ordinary threads, so that the optimization strategy made by the electronic device to ensure fluency cannot play its due role.

[0076] Based on this, refer to Figure 1 As shown, the present application also provides a thread identifier allocation method, which can allocate a fixed thread identifier to a key thread each time it is created based on pre-configured key thread identifier allocation data. Among them, the key thread identifier allocation data can be used to guide the allocation of the thread identifier of the key thread, and make the thread identifier of the key thread fixed after allocation. In this way, since the present technical solution can allocate a fixed thread identifier to a specific key thread based on the pre-configured key thread identifier allocation data, the thread identifier of the key thread can be accurately and quickly obtained when the key thread identifier needs to be obtained later, thereby improving the efficiency of obtaining the thread identifier of the key thread. In addition, since there is a key thread identifier allocation data that can reflect the thread identifiers of all key threads, the aforementioned defects of confusing thread identifier allocation and difficult maintenance caused by allocating thread identifiers to key threads in a hard-coded manner when the key threads are created are also avoided.

[0077] The data identification acquisition method provided in the embodiment of the present application is described below in conjunction with the accompanying drawings.

[0078] The data acquisition method provided in the embodiment of the present application can be applied to electronic devices. The embodiment of the present application mainly introduces the thread allocation process when establishing threads during the operation of the electronic device.

[0079] In the present application, the above-mentioned electronic device can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., which adopts a multi-battery series system to supply power. The embodiments of the present application do not impose any restrictions on the specific type of the electronic device.

[0080] Take the example of a mobile phone being an electronic device. Figure 2 A schematic structural diagram of an electronic device provided by the present application is shown.

[0081] Reference Figure 2 As shown, the electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging 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 button 190, a motor 191, an indicator 192, a display screen 193, a subscriber identification module (SIM) card interface 194, and a camera 195, etc. Among them, the sensor module 180 may include a pressure sensor, a gyroscope sensor, an air pressure 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.

[0082] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0083] The controller can be the nerve center and command center of the electronic device. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0084] 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 store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. Repeated access is avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved. In the embodiment of the present application, the memory may store thread identification allocation data.

[0085] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0086] The charging management module 140 is used to receive charging input from a power supply device (e.g., a charger, a laptop power supply, etc.). The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device.

[0087] While charging the battery 142, the charging management module 140 can also power the electronic device through the power management module 141. The battery 142 can be composed of multiple batteries connected in series. The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110.

[0088] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the display screen 193, the camera 195, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as the battery voltage, current, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device, for example, the power management module 141 and the charging management module 140 can be different functional modules in the same chip.

[0089] The external memory interface 120 can be used to connect to an external non-volatile memory to expand the storage capacity of the electronic device. The external non-volatile 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 videos are stored in the external non-volatile memory.

[0090] The internal memory 121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM). The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data. The non-volatile memory can also store executable programs and store user and application data, etc., and can be loaded into the random access memory in advance for direct reading and writing by the processor 110.

[0091] A touch sensor is also called a "touch control device". The touch sensor can be arranged on the display screen 193. The touch sensor and the display screen 193 form a touch screen, also called a "touch control screen". The touch sensor is used to monitor touch operations acting on or near it. The touch sensor can pass the monitored touch operations to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 193. In other embodiments, the touch sensor can also be arranged on the surface of the electronic device, which is different from the position of the display screen 193.

[0092] The pressure sensor is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor can be set on the display screen 193. There are many types of pressure sensors, 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 device monitors the touch operation intensity according to the pressure sensor. The electronic device can also calculate the touch position based on the monitoring signal of the pressure sensor. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.

[0093] The electronic device implements the display function through a GPU, a display screen 193, and an application processor. The GPU is a microprocessor for image editing, connecting the display screen 193 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0094] The electronic device can realize the shooting function through ISP, camera 195, video codec, GPU, display screen 193 and application processor.

[0095] ISP is used to process data fed back by camera 195. For example, when taking a photo, the shutter is opened, and light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise and brightness of the image. ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, ISP can be set in camera 195. Camera 195 is used to capture still images or videos. In some embodiments, the electronic device may include 1 or N cameras, where N is a positive integer greater than 1. Camera 195 can be a front camera or a rear camera.

[0096] Digital signal processors are used to process digital signals. In addition to processing digital image signals, they can also process other digital signals. For example, when an electronic device selects a frequency point, a digital signal processor is used to perform Fourier transform on the frequency point energy.

[0097] The display screen 193 is used to display images, videos, etc. The display screen 193 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device may include 1 or N display screens 193, where N is a positive integer greater than 1.

[0098] In an embodiment of the present application, the display screen 193 can be used to display the interface of the electronic device (for example, a camera preview interface, a video preview interface, a finished film preview interface, etc.), and display images taken from any one or more cameras 195 in the interface.

[0099] The wireless communication function of the electronic device can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem and baseband processor.

[0100] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas.

[0101] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to electronic devices. The mobile communication module 150 can receive electromagnetic waves through the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.

[0102] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate 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. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 193. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0103] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to electronic devices. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0104] The SIM card interface 194 is used to connect a SIM card. The SIM card can be connected to or disconnected from the electronic device by inserting it into or removing it from the SIM card interface 194. The electronic device can support one or more SIM card interfaces. The SIM card interface 194 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. Multiple cards can be inserted into the same SIM card interface 194 at the same time. The SIM card interface 194 can also be compatible with external memory cards. The electronic device interacts with the network through the SIM card to implement functions such as calls and data communications. One SIM card corresponds to one user number.

[0105] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation of the electronic device. In other embodiments of the present application, the electronic device may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0106] Of course, it is understandable that the above Figure 2 The figure is only an exemplary description when the electronic device is in the form of a mobile phone. If the electronic device is in the form of a tablet computer, a handheld computer, a PC, a PDA, a wearable device (such as a smart watch, a smart bracelet), etc., the structure of the electronic device may include Figure 2 The structure shown in the figure is less than Figure 2 More structures are shown in the figure, which are not limited here.

[0107] It is understandable that, in general, the realization of electronic device functions requires the support of hardware and the cooperation of software. The software system of the electronic device can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. Taking the system as an example, the software structure of the electronic device is illustrated.

[0108] Figure 3 A schematic diagram of a layered architecture of a software system of an electronic device provided in an embodiment of the present application. The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces (such as APIs).

[0109] In some examples, reference Figure 3 As shown, in an embodiment of the present application, the software of the electronic device is divided into five layers, namely, from top to bottom, an application layer, a framework layer (or called an application framework layer), a system library and an Android runtime (android runtime), a HAL layer (hardware abstraction layer) and a driver layer (or called a kernel layer).

[0110] The application layer can include a series of applications. Figure 3 As shown, the application layer may include applications (APP) such as camera, gallery, calendar, map, WLAN, Bluetooth, music, video, short message, call, contact, live broadcast, etc. Among them, the call application and contact may be factory preset in the electronic device, or may be a third-party application for user calls provided by the application market.

[0111] Each application in the application layer may include a thread creation module (not shown in the figure), which can complete the creation of threads according to the needs during the operation of the application. In the embodiment of the present application, the thread creation module will determine the thread name based on the development logic pre-defined by the developer when a thread needs to be established, and determine 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 it belongs. If it is a common thread, the thread is created and the thread identifier is assigned according to the existing process; if it is a key thread, an identifier allocation request (carrying the thread name of the key thread and the process name of the process to which the key thread belongs) can be generated based on the thread name of the key thread and the process name of the process to which the key thread belongs, and sent to the thread identifier allocation module, so that the thread identifier allocation module can allocate the final thread identifier to the key thread based on the identifier allocation request. After that, the thread creation module can complete the creation of the key thread based on the final thread identifier. Of course, in practice, when a thread needs to be created, the thread creation module included in the application is mainly used to generate a thread creation request based on the needs of the application described therein and the final thread identifier assigned by the thread allocation module. Afterwards, a thread creation request can be sent to a function or method for creating a thread in the operating system kernel (specifically, the framework layer) (this process can also be called calling a function or method for creating a thread) so that the function for creating a thread in the operating system kernel completes the creation of the thread.

[0112] Of course, the thread creation module provided in the embodiment of the present application may also be a function or method located in the framework layer that actually completes the thread creation (it may be a type of API for thread creation). Different applications will call the thread creation module to complete the thread creation when they need to create a thread.

[0113] The framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some 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., and the embodiments of the present application do not impose any restrictions on this.

[0114] The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make the data accessible to the application. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build applications. The display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying pictures. The phone manager is used to provide communication functions for electronic devices. For example, the phone manager can manage the call status of the call application (including initiation, connection, hang up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify the completion of downloads, message reminders, etc. The notification manager can also be a notification that appears in the top status bar of the system in the form of an icon or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0115] In an embodiment of the present application, the framework layer may include a thread identifier allocation service (or thread identifier allocation module). After receiving an identifier allocation request sent by a thread creation module, the thread identifier allocation service may allocate a final thread identifier to the key thread according to specific rules based on pre-configured key thread identifier allocation data. Afterwards, the thread identifier allocation service sends the final thread identifier to the thread creation module, so that the thread creation module completes the creation of the key thread based on the final thread identifier.

[0116] In the prior art, the thread ID allocation service may allocate thread IDs to threads by using a specific function to add 1 to the maximum value of the used thread IDs as the thread ID of the thread that currently needs to be allocated a thread ID. The specific logic code may be as follows:

[0117]

[0118] Among them, tid is a private member variable used to store the unique identifier (ID) of the thread. threadSeqNumber is a static long integer variable used to record the thread sequence number. It is defined as private and modified with the synchronization keyword synchronized to ensure the uniqueness of the thread ID in a multi-threaded environment. nextThreadId() is a static synchronization method used to generate the next thread ID. Inside this method, threadSeqNumber is incremented and then returned, so that each time the method is called, a different incrementing ID is returned. By modifying it with the synchronized keyword, it can be ensured that only one thread can execute this method at the same time in a multi-threaded environment.

[0119] The above code snippet is mainly used to assign an independent and unique ID to each thread. By calling the nextThreadId() method, a new thread ID can be obtained and assigned to the tid member variable to identify the unique identity of the current thread.

[0120] In the embodiment of the present application, the improvement of the thread ID allocation service mainly lies in the change of "private staticsynchronized long nexThreadId()" therein, so that the thread ID allocation module can achieve the purpose of allocating fixed thread IDs to key threads.

[0121] In the embodiment of the present application, the thread creation module and the thread identifier allocation service (or thread identifier allocation module) can cooperate to complete the thread identifier allocation solution provided in the embodiment of the present application.

[0122] The system library can include multiple functional modules. For example: surface manager, media library, OpenGL ES, SGL, etc. The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. OpenGL ES is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc. SGL is a drawing engine for 2D drawing.

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

[0124] The HAL layer is an interface layer between the operating system kernel and the hardware circuit, and its purpose is to abstract the hardware. It hides the hardware interface details of a specific platform and provides a virtual hardware platform for the operating system, making it hardware-independent and portable on multiple platforms. The HAL layer provides a standard interface to display device hardware functions to the higher-level Java API framework (i.e., the framework layer). The HAL layer contains multiple library modules, each of which implements an interface for a specific type of hardware component, such as: audio HAL audio module, bluetooth HAL Bluetooth module, camera HAL camera module, sensors HAL sensor module (or Isensor service, sensor service).

[0125] The kernel layer is the layer between hardware and software. The kernel layer includes at least display driver, camera driver, audio driver, sensor driver, battery driver, etc., which are not limited in this application.

[0126] Based on the above hardware architecture and software architecture, the following takes the electronic device as a mobile phone as an example. Figure 4 , the thread identifier allocation method provided in the embodiment of the present application is introduced. Figure 4 As shown, the thread identifier allocation method provided in the embodiment of the present application may include S401-S410:

[0127] S401. When creating a target thread, the thread creation module of the mobile phone determines thread information of the target thread.

[0128] The thread information includes: the thread name and the process name of the process to which it belongs.

[0129] In an embodiment of the present application, the thread creation module can actually create the target thread at any feasible time. For example, after the game application is started, in order to better display a smooth game interface to the user, it will trigger the thread creation module to create the surfaceflinger thread. Of course, in practice, when any application or any process or service in the operating system needs to execute a certain target business, if the target thread corresponding to the target business is not running or created, the thread creation module will create the target thread so that the target business can be smoothly executed.

[0130] The purpose of the technical solution provided in this application is to fix the thread identifiers of all key threads, so as to facilitate the quick and accurate acquisition of the thread identifiers of key threads when it is necessary to implement optimization strategies to improve the system flow based on the thread identifiers of key threads. Based on this, when creating any thread, the thread creation module in this application can first determine whether the thread is a key thread based on the thread name of the thread, and only implement the subsequent operation of allocating thread identifiers when it is determined that the thread is a key 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 key thread and not a key thread.

[0131] Therefore, in order to more accurately determine whether the target thread is a key thread, when creating the target thread, in addition to determining the thread name, it is also necessary to determine the process name.

[0132] In addition, in an embodiment of the present application, when the target thread is a key thread, the thread information of the target thread will be referenced to assign a thread identifier to the target thread. Therefore, in order to ensure that the thread identifier subsequently assigned to the target thread based on the thread information can complete the distinction between the same threads under different processes (i.e., threads with the same thread name), the thread name and process name of the target thread should also be determined when creating the thread.

[0133] In the embodiment of the present application, the key thread can be specifically determined by analyzing the user usage data, and in some key scenarios where users have high requirements for the system fluency of the mobile phone, the thread corresponding to the business closely related to the key scenario. For example, the surfaceflinger thread that is closely related to the game screen smoothness program in the key scenario of the game scene is a key thread. In practice, the determination of the key thread needs to be based on actual user needs, and this application does not specifically limit the number and category of key threads.

[0134] In the prior art, when creating a thread, the thread creation module can directly determine the process name of the process to which the thread to be created belongs (the process is established before the thread is created, so all the information of the process can be directly obtained in any feasible way), but the thread name does not exist. Under normal circumstances, only after the thread is created, there will be a thread name change function that can set the name (i.e., thread name) of the created thread for the thread device name. However, in the embodiment of the present application, in order to make the thread name of the key thread directly available when it is created, there can be the following two implementation methods:

[0135] In the first possible implementation method, when developing each application, the developer can adjust the function of the thread creation module through programming after clarifying the creation timing of all key threads during the operation of the application (for example, the thread triggered by process A when it needs to execute task A is named A, and this thread is a key process), so that the thread creation module can directly determine the thread name of the key thread when creating the key thread corresponding to the application.

[0136] In the second possible implementation method, developers can also adjust the function of the thread creation module through programming after clarifying the creation timing of all threads during the running of the application, so that the thread creation module can directly determine the thread name when creating each thread corresponding to the application.

[0137] Of course, compared to the first implementable method, the second implementable method requires more work from the developer and more code changes to the application.

[0138] In this way, when creating a target thread, the thread creation module can successfully obtain the thread name of the target thread.

[0139] After the thread creation module of the mobile phone obtains the thread information of the target thread, it can determine whether the target thread is a key thread based on the thread information to obtain a thread detection result, that is, execute S402, wherein the thread detection result can be used to indicate that the target thread is the target thread, or the thread detection result can be used to indicate that the target thread is not the target thread.

[0140] Based on the thread detection result, it can be decided whether to execute the subsequent process of setting a fixed TID for the key thread.

[0141] S402: The thread creation module of the mobile phone determines whether the target thread is a key thread based on the thread information of the target thread.

[0142] In one achievable manner, the mobile phone may store an association relationship of multiple key threads and multiple 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 key thread in the association relationship is the same as the thread information of the target thread, the target thread may be determined to be a key thread. If the thread information of a key thread in the association relationship is not the same as the thread information of the target thread, the target thread may be determined not to be a key thread.

[0143] In an embodiment of the present application, the associated information may be that before the mobile phone leaves the factory, the mobile phone manufacturer may use any feasible method to collect all key threads and corresponding thread information of most applications that the user may use, and then obtain statistical summary.

[0144] In some embodiments, the association relationship can be pre-configured and stored critical thread identifier allocation data. The critical thread identifier allocation data includes thread information of multiple critical threads. At this time, S402 can specifically be: the thread creation module of the mobile phone determines the thread detection result based on the thread information of the target thread and the thread information of multiple critical threads in the critical thread identifier allocation data. Specifically, if the thread information of a critical thread (for example, the first critical programming) in the critical thread identifier 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 a critical thread. If the thread information of any critical thread in the critical thread identifier allocation data is not the same as the thread information of the target thread, the thread detection result is used to indicate that the target thread is not a critical thread.

[0145] When the thread creation module of the mobile phone determines that the target thread is a key thread, the thread identifier allocation module of the mobile phone needs to allocate the corresponding first thread identifier to the target thread based on the pre-configured key thread identifier allocation data, that is, execute the subsequent S403-S407.

[0146] When the thread creation module of the mobile phone determines that the target thread is a key thread, the thread identifier allocation module of the mobile phone may subsequently allocate a first thread identifier to the target thread according to the existing thread identifier allocation logic, ie, execute subsequent S408-S410.

[0147] It should be noted that in practice, the judgment step S402 may not exist, and the thread creation module of the mobile phone may directly execute S403 when the target thread is determined to be a key thread based on the thread information of the target thread; and execute S408 when the target thread is determined not to be a key thread based on the thread information of the target thread. This application does not make any specific restrictions on this.

[0148] S403: The thread creation module of the mobile phone sends an identifier allocation request to the thread identifier allocation module.

[0149] The identifier allocation request carries thread information of a target thread, and is used to request allocation of a thread identifier for the target thread.

[0150] S404: The thread identifier allocation module of the mobile phone receives the identifier allocation request from the thread creation module.

[0151] S405: The thread identifier allocation module of the mobile phone determines a first thread identifier of the target thread based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data.

[0152] In the embodiment of the present application, the key thread identifier allocation data may include identifier allocation data in addition to the thread information of multiple key threads. The identifier allocation data may be used to instruct the mobile phone to allocate a fixed thread identifier to the key thread, or the identifier allocation data may be used to guide the mobile phone to allocate a fixed thread identifier to the key thread.

[0153] In the embodiment of the present application, the thread identifier allocation module of the mobile phone determines the first thread identifier of the target thread based on the thread information of the target thread in the identifier allocation request and the key thread identifier allocation data. There are two implementation methods as follows:

[0154] In a first possible implementation, the identifier allocation data included in the critical thread identifier allocation data may include a critical identifier allocation range for the process to which each critical thread belongs. The thread identifier allocation module of the mobile phone may allocate an identifier to the target thread based on the critical identifier range that can be allocated to the process to which the target thread belongs in the critical thread identifier allocation data. In an embodiment of the present application, the critical identifier allocation range specifically refers to the range of thread identifiers available to the critical thread under the process. For example, if the critical identifier allocation range under a process is 1000-1999, it indicates that the thread identifier of the critical thread under the process can be 1000-1999. In some embodiments, the critical identifier allocation range can be identified by a critical process number segment. Specifically, if the critical identifier allocation range is 1000-1999, the critical process number segment can be 100 or any other feasible value. Exemplarily, the critical thread identifier allocation data may be shown in Table 2 below.

[0155] Table 2 - Key TI D allocation table

[0156]

[0157]

[0158] In order to facilitate the subsequent mobile phone to smoothly obtain the thread identifier of the critical thread when it needs to query. In the case where the target thread is a critical thread, after the thread identifier allocation module allocates the first thread identifier to the target thread, the first thread identifier can be stored in the critical thread identifier allocation data, and the association relationship between the critical thread corresponding to the target thread and the first thread identifier in the critical thread identifier allocation data is established to update the critical thread identifier allocation data. For example, as shown in Table 2, the key TID allocation table corresponding to the pre-configured critical thread identifier allocation data can reserve enough storage locations for storing the thread identifier of each critical thread in advance. Afterwards, each time the thread identifier allocation module allocates a thread identifier to a critical thread, the corresponding thread identifier can be placed in the position where the thread identifier of the critical thread is placed in the table to update the table corresponding to the critical thread identifier allocation data. For example, if the thread identifier allocated by the thread identifier allocation module to the surfaceflinger thread under the surfaceflinger process is 10001, the thread identifier allocation module can be based on the updated critical thread identifier allocation data as shown in Table 3 below.

[0159] Table 3 - Key TID allocation table

[0160]

[0161] Among them, the thread ID of the key thread surfaceflinger under surfaceflinger is set to 10001, and the other key threads that have not been assigned thread IDs do not have corresponding thread IDs.

[0162] In this way, the mobile phone can then quickly and easily find the thread identifier of the key thread from the key thread identifier allocation data.

[0163] In this implementation, the thread identifier allocation module can parse the key thread identifier allocation data pre-stored in the mobile phone during the process of starting up the mobile phone, thereby obtaining the thread name of the key thread that can be directly used for subsequent processing and the process name of the process to which the key thread belongs, as well as the key identifier allocation range of each process.

[0164] Based on the above description, in some embodiments, combined with Figure 4 , refer to Figure 5 As shown, S405 may specifically include S501-S504:

[0165] S501. A thread identifier allocation module of a mobile phone determines whether a thread identifier of a target thread exists in key thread identifier allocation data based on thread information of the target thread in an identifier allocation request.

[0166] Specifically, the thread identifier allocation module may first determine whether the thread information of a key thread in the key thread identifier allocation data is the same as the thread information of the target thread.

[0167] If there is a critical thread with the same thread information as the target thread, it is determined whether the thread identifier of the critical thread exists in the critical thread identifier allocation data. If there is a thread identifier of the critical thread, it is determined that the thread identifier of the target thread exists in the critical thread identifier allocation data. After that, the first thread identifier can be allocated to the target thread based on the critical identifier allocation range corresponding to the target thread in the critical thread identifier allocation data and the available thread identifiers to be allocated in the critical identifier allocation range corresponding to the target thread. That is, S502 and S503 are executed.

[0168] If there is no critical thread with the same thread information as the target thread, it can be considered that the determination result of the thread creation module that the target thread is a critical thread is wrong or the identification allocation request sent by the thread creation module may be tampered with. At this time, it can be considered that the target thread is abnormal. In order to prevent the thread identification available to the critical process from being illegally occupied, the target thread can be determined as a normal thread. Afterwards, the thread identification allocation module can allocate a first thread identification to the target thread according to the existing thread identification allocation logic, that is, execute the subsequent S408-S410.

[0169] In the embodiment of the present application, step S501 may also be referred to as a thread verification mechanism, which may prevent a thread that is uncertain whether it is a critical thread from being assigned a thread identifier that should be assigned to a critical thread, thereby avoiding thread identifier assignment errors.

[0170] It should be noted that in practice, the judgment step 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; and execute S408 when determining that the thread identifier of the target thread does not exist in the key thread identifier allocation data based on the thread information of the target thread in the identifier allocation request. This application does not make specific restrictions on this.

[0171] S502. The thread identifier allocation module of the mobile phone determines the thread identifier to be allocated in the key identifier allocation range corresponding to the target thread from the identifier allocation data in the key thread identifier allocation data based on the process name of the process to which the target thread belongs in the identifier allocation request.

[0172] The thread identifier to be allocated refers to a thread identifier that has not been allocated to any key thread.

[0173] Specifically, the thread identifier allocation module can determine the key identifier allocation range of the process whose process name in the key thread identifier allocation data is the same as the process name of the process to which the target thread belongs as the key identifier allocation range corresponding to the target thread. 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.

[0174] The allocated thread identifiers that have been allocated to other key threads in the key identifier allocation range corresponding to the target thread can be directly determined from the key thread identifier allocation data, and the other thread identifiers in the key identifier allocation range are thread identifiers to be allocated.

[0175] It should be noted that when the thread identifier allocation module of the mobile phone allocates a thread identifier for the target thread determined as a critical thread for the first time, the thread identifier of the target thread must not exist in the critical thread identifier allocation data, and all thread identifiers in the critical identifier allocation range corresponding to the target thread are thread identifiers to be allocated.

[0176] S503: The thread identifier allocation module of the mobile phone determines the first thread identifier of the target thread from all thread identifiers to be allocated according to a preset rule.

[0177] In a possible implementation, the preset rule may be to use the one with the smallest value among all the thread identifiers to be allocated as the first thread identifier of the target thread. That is, the preset rule may make the identifiers in the key identifier allocation range of each process in the key identifier allocation range be allocated thread identifiers from small to large in the order in which each key process first appears. Of course, in practice, the preset rule may also be any other feasible implementation, and this application does not make any specific limitation on this.

[0178] To ensure that the thread ID of a key thread can be obtained quickly and conveniently from the key thread ID allocation data when it is needed later, after the first thread ID is determined for the target thread each time, the key thread ID allocation data should be updated in time, that is, S504 is executed.

[0179] S504: The thread identifier allocation module of the mobile phone adds a correspondence between the key thread corresponding to the target thread and the first thread identifier in the key thread identifier allocation data.

[0180] Exemplarily, taking the key thread identifier allocation data shown in Table 2 as an example, S502 may specifically be to add the first thread identifier to the placement position of the thread identifier of the key thread corresponding to the target thread in the table corresponding to the key thread identifier allocation data. For example, if the target thread is the surfaceflinger thread under the surfaceflinger process, and the thread identifier allocated by the thread identifier allocation module to the surfaceflinger thread under the surfaceflinger process is 10001, then the key thread identifier allocation data updated by the thread identifier allocation module based on the first thread identifier may be as shown in Table 3 above.

[0181] In the embodiment of the present application, each updated critical thread identifier allocation data will be fixedly stored before the next update, so as to facilitate the subsequent mobile phone to obtain the thread identifier of any critical thread from the critical thread identifier allocation data. In this case, after all the critical threads in the critical thread identifier allocation data have corresponding thread identifiers, the mobile phone only needs to query the critical thread identifier allocation data once and then store it to obtain the thread identifier of any critical thread, and can directly use the stored thread identifier without querying and obtaining it, thereby improving the efficiency of subsequent acquisition of the thread identifier of the critical thread.

[0182] In some embodiments, each time the mobile phone is restarted or turned off, it may cause the key thread identifier allocation data to be changed to the initial state, that is, the state where there is no thread identifier of any thread. In this case, each time the mobile phone is restarted or turned off, it may cause the thread identifier determined or allocated by the thread identifier allocation module for the key thread based on the key thread identifier allocation data to change due to the change in the first creation order of a key thread. In this case, after each restart or shutdown of the mobile phone, if it is necessary to obtain the thread identifier of a key thread that has already obtained the thread identifier before the mobile phone is restarted or shut down, it is necessary to search again from the key thread identifier allocation data. Compared with the method of obtaining the thread identifier of the key thread when the key thread identifier allocation data after each update is fixedly stored before the next update, the acquisition efficiency of this method will be lower.

[0183] Based on the technical solutions corresponding to S501-S504 above, the mobile phone can allocate a fixed thread identifier to the target thread, which is a 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 fixed thread identifier is reflected in specific data (i.e., the key thread identifier allocation data). In this way, whenever the thread identifier of a key thread is needed, the thread identifier of the key thread can be obtained from the key thread identifier allocation data, so that operations that need to be implemented based on the thread identifier of the key thread (such as optimization strategies) can be implemented smoothly.

[0184] In a second possible implementation, the identification allocation data included in the critical thread identification allocation data may include the thread identification of each critical thread. The thread identification of each critical thread may be determined and set in the critical thread identification allocation data by the mobile phone manufacturer before the mobile phone leaves the factory. Exemplarily, the critical thread identification allocation data may be as shown in Table 4 below.

[0185] Table 4 - Key TID Allocation Table

[0186]

[0187] Of course, in this implementation, the identifier allocation data included in the key thread identifier allocation data may also include the key identifier allocation range of the process to which each key thread belongs. Exemplarily, the key thread identifier allocation data may be as shown in Table 5 below.

[0188] Table 5 - Key TID allocation table

[0189]

[0190]

[0191] In this implementation, the thread identifier allocation module can parse the key thread identifier allocation data pre-stored in the mobile phone during the process of starting up the mobile phone, so as to obtain the thread name of each key thread and the process name of the process to which the key thread belongs. Afterwards, for ease of use, the thread identifier allocation module can concatenate the thread name and the process name into a string (i.e., convert the thread information of the key thread into a string), and store the string and the corresponding thread identifier in the memory as a key-value pair, so as to facilitate subsequent query or call when needed. Exemplarily, taking the key thread identifier allocation data shown in Table 4 as an example, the key thread identifier allocation data converted by the thread identifier allocation module is shown in Table 6 below.

[0192] Table 6 - Key thread identification allocation data

[0193] Thread information of key thread (key) Thread ID (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

[0194] Based on the above identification, in some embodiments, combined with Figure 4 , refer to Figure 6 As shown, S405 may specifically include S601:

[0195] S601. A thread identifier allocation module of a mobile phone determines a first thread identifier of a target thread from identifier allocation data in key thread identifier allocation data based on thread information of the target thread in an identifier allocation request.

[0196] Specifically, the thread identifier allocation module may determine the thread identifier of the key thread whose thread information in the key thread identifier allocation data is the same as the thread information of the target thread as the first thread identifier of the target thread. For example, taking the key thread identifier allocation data as the content 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, then the first thread identifier of the target thread is the thread identifier 3000 corresponding to system_server-system_server.

[0197] In addition, it should be noted that, in practice, if the thread creation module determines that the target thread is a critical thread, this judgment result is wrong or the identification allocation request sent by the thread creation module is tampered with, then there will be no critical thread whose thread information is the same as the thread information of the target thread in the critical thread identification allocation data. At this time, it can be considered that the target thread is abnormal. In order to prevent the thread identification available to the critical process from being illegally occupied, the target thread can be determined as a normal thread. Afterwards, the thread identification allocation module can allocate a second thread identification to the target thread according to the existing thread identification allocation logic, that is, execute the subsequent S408-S410.

[0198] Based on the technical solution corresponding to S601 above, the mobile phone can allocate a fixed thread identifier to the target thread, which is a 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 fixed in the key thread identifier allocation data. In this way, whenever the thread identifier of a key thread is needed later, the thread identifier of the key thread can be obtained from the key thread identifier allocation data, so that operations that need to be implemented based on the thread identifier of the key thread (such as optimization strategies) can be implemented smoothly.

[0199] S406: The thread identifier allocation module of the mobile phone sends the first thread identifier to the thread creation module.

[0200] 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, wherein the thread identifier allocation response carries first indication information indicating that the thread identifier of the target thread is the first thread identifier.

[0201] S407: The thread creation module of the mobile phone receives the first thread identifier from the thread identifier allocation module, and completes the creation of the target thread based on the first thread identifier.

[0202] Specifically, when creating a target thread, the thread creation module of the mobile phone needs to determine the first thread identifier of the target thread and allocate corresponding thread resources (such as memory space, CPU time slice and other resources) to the target thread so that the target thread can run normally, thus completing the creation of the target thread.

[0203] After S407, whenever the mobile phone (or the thread usage module in the mobile phone) needs the thread identifier of a key thread, it can obtain the thread identifier of the key thread based on the key thread identifier allocation data, so that operations that need to be implemented based on the thread identifier of the key thread (such as optimization strategies) can be implemented smoothly.

[0204] In addition, it should be noted that in practice, before the mobile phone or the thread usage module of the mobile phone allocates data based on the key thread identifier and obtains the thread identifier of a certain key thread, it is also necessary to verify the existence status of the key thread. Only when the existence status of the key thread is alive (i.e., running), the thread usage module is useful to execute the optimization strategy for improving the system process based on the thread identifier of the key thread. Therefore, when the existence status of a certain key thread is not alive, the thread usage module of the mobile phone or the mobile phone will no longer obtain the thread identifier of the key thread. Specifically, the thread usage module of the mobile phone or the mobile phone can determine the thread name of the key thread and the existence status of the key thread by viewing the kernel node proc / t id / comm.

[0205] S408. The thread identifier allocation module of the mobile phone determines, according to the default allocation rule, a second thread identifier of the target thread from thread identifiers other than all thread identifiers corresponding to the key thread identifier allocation data.

[0206] Exemplarily, the default allocation rule may be to determine the thread identifier with the smallest value among all thread identifiers other than the thread identifiers corresponding to the critical thread identifier allocation data as the second thread identifier of the target thread. Of course, any other feasible default allocation rule may be used in practice.

[0207] It should be noted that, in the embodiment of the present application, the first thread identifier and the second thread identifier are only used to distinguish the thread identifiers in two different situations where the target thread is a critical thread and a non-critical thread, and does not mean that the target thread has two thread identifiers.

[0208] In a possible implementation, if the key thread identifier allocation data includes thread information of multiple key threads, and the identifier allocation data included in the key thread identifier allocation data includes the key identifier allocation range of the process to which each key thread belongs, then S408 may specifically be that the thread identifier allocation rule determines the second thread identifier of the target thread from the thread identifiers outside the key identifier allocation range corresponding to the key thread identifier allocation data according to the default allocation rule.

[0209] In another possible implementation, if the key thread identifier allocation data includes thread information of multiple key threads, and the identifier allocation data included in the key thread identifier allocation data includes the thread identifier of each key thread, then S408 may specifically be that the thread identifier allocation rule determines the second thread identifier of the target thread from the thread identifiers other than the thread identifiers of all key identifiers corresponding to the key thread identifier allocation data according to the default allocation rule.

[0210] In this way, it can be ensured that critical threads have sufficient thread identifiers available for allocation, and ordinary threads can also obtain thread identifiers according to the original allocation rules.

[0211] In some embodiments, in order to ensure the uniformity of processing logic, the thread creation module of the mobile phone will also send an identifier allocation request to the thread identifier allocation module when determining that the target thread is not a key thread, but the identifier allocation request does not carry the thread information of the target thread and is only used to request the allocation of a thread identifier. After that, S408-S410 can be executed to complete the determination of the second thread identifier of the target thread and the creation of the target thread.

[0212] S409: The thread allocation module of the mobile phone sends the second thread identifier to the thread creation module.

[0213] 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, and the second indication information indicates that the thread identifier of the target thread is the second thread identifier.

[0214] S410: The thread creation module of the mobile phone receives the second thread identifier from the thread identifier allocation module, and completes the creation of the target thread based on the second thread identifier.

[0215] The specific implementation of S410 may refer to the related description of S407 mentioned above, which will not be repeated here.

[0216] Based on the technical solution provided by the embodiment of the present application, it is possible to allocate a fixed thread identifier to a critical thread each time it is created based on pre-configured critical thread identifier allocation data. Among them, the critical thread identifier allocation data can be used to guide the allocation of the thread identifier of the critical thread, and the thread identifier of the critical thread after allocation is fixed. In this way, since the technical solution can allocate a fixed thread identifier to a specific critical thread based on the pre-configured critical thread identifier allocation data, the subsequent mobile phone can accurately and quickly obtain the thread identifier of the critical thread when it needs to obtain the critical thread identifier, thereby improving the efficiency of obtaining the thread identifier of the critical thread. In addition, the optimization strategy based on the thread identifier of the critical thread aimed at improving the fluency of the system is smoothly implemented, thereby improving the user experience.

[0217] In some embodiments, if the critical thread identifier allocation data includes thread information of multiple critical threads, and the identifier allocation data included in the critical thread identifier allocation data includes the thread identifier of each critical thread. Then the thread creation module of the mobile phone can also determine the expected thread identifier of the target thread from the critical thread identifier allocation data based on the thread information of the target thread after determining the thread information of the target thread. Afterwards, the thread creation module can send the expected thread identifier and the thread information of the target thread to the thread identifier allocation module, so that the thread identifier allocation module determines the final first thread identifier of the target programming based on the expected thread identifier and the critical thread identifier allocation data. Afterwards, the thread identifier allocation module can return the first thread identifier to the thread creation module so that it can complete the creation of the target thread. Based on this, refer to Figure 7 As shown, the embodiment of the present application also provides another thread identifier allocation method, which may include S701-S711:

[0218] S701. When creating a target thread, the thread creation module of the mobile phone determines thread information of the target thread.

[0219] The specific implementation of S701 may refer to the relevant description of S401 in the aforementioned embodiment, which will not be repeated here.

[0220] S702: The thread creation module of the mobile phone determines whether the target thread is a key thread based on the thread information of the target thread and the key thread identification allocation data.

[0221] Specifically, if the thread information of a certain key thread in the key thread identifier allocation data is the same as the thread information of the target thread, the target thread can be determined to be the key thread. If the thread information of a certain key thread in the key thread identifier allocation data is not the same as the thread information of the target thread, the target thread can be determined not to be the key thread.

[0222] When the thread creation module of the mobile phone determines that the target thread is a key thread based on the thread information of the target thread and the key thread identifier allocation data, the thread identifier allocation module of the mobile phone can subsequently allocate a first thread identifier to the target thread based on the pre-configured key thread identifier allocation data, that is, execute subsequent S704-S708.

[0223] When the thread creation module of the mobile phone determines that the target thread is not 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 mobile phone can subsequently allocate a second thread identifier to the target thread according to the existing thread identifier allocation logic, that is, execute subsequent S709-S711.

[0224] It should be noted that in practice, the judgment step S702 may not exist, and the thread creation module of the mobile phone may directly execute S703 when the target thread is determined to be a key thread based on the thread information of the target thread and the key thread identifier allocation data; and execute S709 when the target thread is determined not to be a key thread based on the thread information of the target thread and the key thread identifier allocation data. This application does not make specific restrictions on this.

[0225] S703: The thread creation module of the mobile phone determines the expected thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data.

[0226] Specifically, the thread identifier allocation module can determine the thread identifier of the key thread whose thread information in the key thread identifier allocation data is the same as the thread information of the target thread as the expected thread identifier of the target thread. For example, taking the key thread identifier allocation data as the content 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, then the expected thread identifier of the target thread is the thread identifier 3000 corresponding to system_server-system_server.

[0227] After the thread creation module obtains the expected thread identifier based on the key thread identifier allocation data, it can directly request the thread identifier allocation module to allocate the expected thread identifier. That is, at this time, the thread creation module can directly send an identifier allocation request carrying the expected thread identifier to the thread identifier allocation module. After receiving the identifier allocation request, the thread identifier allocation module can directly determine the expected thread identifier as the first thread identifier of the target thread and return it to the thread creation module so that it completes the creation of the target thread.

[0228] However, the thread creation module is more open than the thread identifier allocation module, and is more susceptible to malicious manipulation. Therefore, it is possible that the expected thread identifier of the target thread determined by the thread creation module after determining that the target thread is a critical thread is not obtained from the critical thread identifier allocation data but is directly modified by malicious means, or when the target thread itself is a critical thread, the thread creation module is maliciously manipulated to obtain a thread identifier from the critical thread identifier allocation data as the expected thread identifier and send it to the thread identifier allocation module for allocation request. In these cases, if the thread identifier allocation module directly allocates the expected thread identifier to the target thread, it may cause the target thread, which is not a critical thread, to use the thread identifier that should be allocated to the critical thread, or to allocate a random thread identifier (not a thread identifier in the critical thread identifier allocation data) to the target thread, which is a critical thread, and other errors, resulting in confusion in thread identifier allocation, and some critical threads will not be allocated to appropriate fixed thread identifiers.

[0229] Based on this, after S703, the identifier allocation request sent by the thread creation module to the thread identifier allocation module should carry the thread information of the target thread and the expected thread identifier. After receiving the identifier allocation request, the thread identifier allocation module should verify the thread information of the target thread and the expected thread identifier based on the key thread identifier allocation data. If the verification is successful, the expected thread identifier is sent 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 the second thread identifier can be allocated to the target thread according to the existing thread identifier allocation logic. That is, the subsequent S704-S711 is executed.

[0230] S704: The thread creation module of the mobile phone sends an identifier allocation request to the thread identifier allocation module.

[0231] The identifier allocation request carries thread information of a target thread and an expected thread identifier, and the identifier allocation request is used to request allocation of a thread identifier for the target thread.

[0232] S705: The thread identifier allocation module of the mobile phone receives the identifier allocation request from the thread creation module.

[0233] S706. The thread identifier allocation module of the mobile phone verifies the thread information of the target thread and the expected thread identifier in the identifier allocation request according to the key thread identifier allocation data to obtain a verification result.

[0234] The verification result is used to indicate that the thread information of the target thread and the expected thread identifier are critical thread data, or the verification result is used to indicate that the thread information of the target thread and the expected thread identifier are non-critical thread data.

[0235] Specifically, if the thread information of a certain key thread in the key thread identifier allocation data is the same as the thread information of the target thread, and the thread identifier of the key thread is the same as the expected thread identifier of the target thread, then the verification result is used to indicate that the thread information and the expected thread identifier of the target thread are key thread data. At this time, the thread identifier allocation module can directly return the expected thread identifier as the first thread identifier to the thread creation module so that it completes the creation of the target thread. That is, S707 and S708 are executed.

[0236] If the key thread identifier allocation data does not contain a key thread whose thread information is the same as the target thread's thread information, or does not contain a key thread whose thread identifier is the same as the target thread's expected thread identifier, the verification result indicates that the target thread's thread information and expected thread identifier are not key thread data. At this point, the target thread can be identified as a common thread (or not a key thread), and the subsequent thread identifier allocation module of the mobile phone can allocate a second thread identifier to the target thread according to the existing thread identifier allocation logic, i.e., execute the subsequent S709-S711.

[0237] S707: The thread identifier allocation module of the mobile phone determines the expected thread identifier as the first thread identifier of the target thread, and sends the first thread identifier to the thread creation module.

[0238] S708. The thread creation module of the mobile phone receives the first thread identifier from the thread identifier allocation module, and completes the creation of the target thread based on the first thread identifier.

[0239] The specific implementation of S707 and S708 may refer to the related descriptions of S406 and S407 in the aforementioned embodiment, which will not be repeated here.

[0240] S709: The thread identifier allocation module of the mobile phone determines, according to the default allocation rule, a second thread identifier of the target thread from thread identifiers other than all thread identifiers corresponding to the key thread identifier allocation data.

[0241] Exemplarily, the default allocation rule may be to determine the thread identifier with the smallest value among all thread identifiers other than the thread identifiers corresponding to the critical thread identifier allocation data as the second thread identifier of the target thread. Of course, any other feasible default allocation rule may be used in practice.

[0242] In a possible implementation, if the key thread identifier allocation data also includes thread information and thread identifiers of multiple key threads, and the key identifier allocation range of the process to which each key thread belongs, then S709 may specifically be that the thread identifier allocation rule determines the second thread identifier of the target thread from the thread identifiers outside the key identifier allocation range corresponding to the key thread identifier allocation data according to the default allocation rule.

[0243] In another possible implementation, if the key thread identifier allocation data only includes thread information and thread identifiers of multiple key threads, S709 may specifically be that the thread identifier allocation rule determines the second thread identifier of the target thread from thread identifiers other than the thread identifiers of all key identifiers corresponding to the key thread identifier allocation data according to the default allocation rule.

[0244] In this way, it can be ensured that critical threads have sufficient thread identifiers available for allocation, and ordinary threads can also obtain thread identifiers according to the original allocation rules.

[0245] In some embodiments, in order to ensure the uniformity of processing logic, the thread creation module of the mobile phone will also send an identifier allocation request to the thread identifier allocation module when determining that the target thread is not a key thread, but the identifier allocation request does not carry the thread information of the target thread and is only used to request the allocation of a thread identifier. After that, S709-S711 can be executed to complete the determination of the second thread identifier of the target thread and the creation of the target thread.

[0246] S710. The thread allocation module of the mobile phone sends a second thread identifier to the thread creation module.

[0247] S711. The thread creation module of the mobile phone receives the second thread identifier from the thread identifier allocation module, and completes the creation of the target thread based on the second thread identifier.

[0248] The specific implementation of S710 and S711 may refer to the specific implementation of S409 and S410 in the aforementioned embodiment, which will not be described in detail here.

[0249] Based on the technical solution provided by the embodiment of the present application, it is possible to more accurately and safely assign a fixed thread identifier to a critical thread each time it is created, based on the pre-configured critical thread identifier allocation data. Among them, the critical thread identifier allocation data can be used to guide the allocation of the thread identifier of the critical thread, and the thread identifier of the critical thread after allocation is fixed. In this way, since the technical solution can assign a fixed thread identifier to a specific critical thread based on the pre-configured critical thread identifier allocation data, subsequent mobile phones can accurately and quickly obtain the thread identifier of the critical thread when they need to obtain the critical thread identifier, thereby improving the efficiency of obtaining the thread identifier of the critical thread. In addition, the optimization strategy based on the thread identifier of the critical thread, which aims to improve the fluency of the system, is smoothly implemented, thereby improving the user experience.

[0250] The following takes the key thread identifier allocation data including the thread information and thread identifiers of multiple key threads, and the key identifier allocation range of the process to which each key thread belongs (wherein the thread identifier and the key identifier allocation range are the contents of the allocation data represented in the key thread identifier allocation data) as an example, referring to Figure 8 As shown, in this application Figure 7 A specific implementation process of the thread identifier allocation method shown in FIG. Figure 8 As shown, the specific implementation process of the thread identifier allocation method may include:

[0251] 1. First, when the mobile phone starts, the thread identifier allocation module first parses the key thread identifier allocation data to obtain the thread information of the key thread and the key identifier allocation range of each process and cache it. Specifically, the thread information of the key thread can be cached in the form of key-value pairs as shown in Table 6. In addition, the thread identifier allocation module can also set the maximum value t idSeq of the currently allocated thread identifier to 0.

[0252] 2. When the thread creation module creates a thread (i.e., the aforementioned target thread), first, after determining the thread information of the thread (the thread name and the process name of the process to which it belongs), it can determine whether the thread to be created is a common thread (i.e., a non-critical thread) or a critical thread based on the critical thread identification allocation data. The specific judgment method can refer to the relevant description in the aforementioned embodiment, which will not be repeated here.

[0253] When it is determined that a common thread is created, the thread creation module sends an identifier allocation request that does not carry thread information of the common thread to the thread identifier allocation module. The identifier allocation request is used to request allocation of a thread identifier.

[0254] When it is determined that the creation of a critical thread is to be performed, the thread creation module can determine the expected thread identifier of the critical thread based on the critical thread identifier allocation data, and then send an identifier allocation request carrying the thread information of the critical thread and the expected thread identifier to the thread identifier allocation module. The identifier allocation request is used to request the allocation of a thread identifier. The specific implementation of determining the expected thread identifier can refer to the relevant description in the aforementioned embodiment.

[0255] 3. When the thread identifier allocation module of the mobile phone receives the identifier allocation request from the thread creation module, it verifies the content carried in the identifier allocation request.

[0256] Specifically, if the identifier allocation request is empty, it indicates that the identifier allocation request is sent by the thread creation module when creating a normal thread. At this time, the thread identifier allocation module can allocate a thread identifier to the normal thread according to the existing default allocation rule. Specifically, the default allocation rule can allocate the smallest thread identifier other than all thread identifiers corresponding to the key thread identifier allocation data to the normal thread. In specific implementation, the thread identifier allocation module can first determine whether the maximum value of the currently allocated thread identifier + 1 is within any key identifier allocation range in the key thread identifier allocation data. If so, in order to avoid allocating the thread identifier available to the key thread to the normal thread, the maximum value of all key identifier allocation ranges in the key thread identifier allocation data can be determined as the maximum value of the currently allocated thread identifier. For example, taking the key thread identifier allocation data as shown in Table 5 as an example, X000+1000 can be used as tidSeq. Afterwards, tidSeq+1 is returned to the thread creation module as the thread identifier allocated to the normal thread.

[0257] If the identifier allocation request is not empty, but there is no key thread in the key thread identifier allocation data that is the same as the thread information carried in the identifier allocation request, or the key thread identifier allocation data does not contain the expected thread identifier in the identifier allocation request, then the identifier allocation request can be regarded as the identifier allocation request sent by the thread creation module when creating an ordinary thread. At this time, the thread identifier can be allocated to the ordinary thread according to the existing default allocation rules. The specific implementation method is described in the above paragraph.

[0258] If the identifier allocation request is not empty, there is a key thread in the key thread identifier allocation data that is the same as the thread information carried in the identifier allocation request, 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, then it can be determined that the thread creation module sent the identifier allocation request when creating the key thread. At this time, the expected thread identifier can be used as the final thread identifier allocated to the key thread created by the thread creation module.

[0259] 4. After receiving the thread identifier from the identifier allocation module, the thread creation module completes thread creation based on the thread identifier.

[0260] Based on the above technical solution, when creating a key thread, the mobile phone can reasonably allocate a fixed thread identifier to the key thread based on the pre-configured key thread identifier allocation data. When the thread identifier of the key thread needs to be obtained later, the corresponding thread identifier can be obtained from the key thread identifier allocation data conveniently and quickly, thereby improving the efficiency of obtaining the thread identifier of the key thread. This enables the optimization strategy based on the thread identifier of the key thread to be smoothly implemented to improve the system fluency and improve the user experience.

[0261] It should be noted that in practice, with the increase in the number of applications and the increase in user usage scenarios, critical threads that are not included in the critical thread identifier allocation data may be generated. In order to include all critical threads in the critical thread identifier allocation data as much as possible, when the mobile phone manufacturer or the developer of the application determines that a new critical thread has appeared, the thread update information is sent to the mobile phone through the update server. The thread update information may include the thread information of the newly added critical thread and / or the thread identifier of the newly added critical thread and / or the latest critical identifier allocation range of the process to which the newly added critical thread belongs. After receiving the thread update information, the mobile phone can use any feasible method to update the content in the critical thread identifier allocation data using the content contained in the update information, so that the critical thread identifier allocation data includes the latest thread information and / or thread identifiers of all critical threads and / or the latest critical identifier allocation range of the process to which they belong.

[0262] For ease of understanding, the following Fig. 9 The thread identifier allocation method provided in the embodiment of the present application is described. Fig. 9 As shown, the method may include S901-S904:

[0263] S901. When creating a target thread, the electronic device determines thread information of the target thread.

[0264] The thread information includes the thread name and the process name of the process to which it belongs.

[0265] The specific implementation of S901 may refer to the relevant description of S401 in the aforementioned embodiment, which will not be repeated here.

[0266] S902: The electronic device determines a thread detection result based on thread information of the target thread.

[0267] The thread detection result is used to indicate that the target thread is a critical thread, or the thread detection result is used to indicate that the target thread is not a critical thread.

[0268] In some possible implementations, S902 may include: the electronic device determines the thread detection result based on the thread information of the target thread and the thread information of multiple key threads in the key thread identifier allocation data. Specifically, if the thread information of the first key thread in the thread information of multiple key threads in the key thread identifier 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 a key thread; if the thread information of any key thread in the thread information of multiple key threads in the key thread identifier 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 not a key thread.

[0269] The specific implementation of S902 may refer to the relevant description of S402 in the aforementioned embodiment, which will not be repeated here.

[0270] S903: When the thread detection result indicates that the target thread is a critical thread, the electronic device determines a first thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data.

[0271] The key thread identifier allocation data includes thread information of multiple key threads and identifier allocation data; the identifier allocation data is used to instruct the electronic device to allocate a fixed thread identifier to the key thread.

[0272] The specific implementation of S903 may refer to the relevant descriptions of S403 to S405 in the aforementioned embodiment, which will not be repeated here.

[0273] In one possible implementation, if the identifier allocation data includes a key identifier allocation range of a process to which each key thread among multiple key threads belongs, and the key identifier allocation range is used to indicate a range of thread identifiers available to the key threads under the process; then S903 may specifically include: when the electronic device does not have the thread identifier of the target thread in the key thread identifier allocation data, the electronic device determines the to-be-allocated thread identifier in the key identifier allocation range corresponding to the target thread from the identifier allocation data; and the electronic device module determines the first thread identifier of the target thread from all the to-be-allocated thread identifiers according to preset rules.

[0274] Exemplarily, the preset rule may include: taking the one with the smallest value among all the thread identifiers to be allocated as the first thread identifier.

[0275] In addition, in order to ensure that the thread identifier of a key thread can be obtained from the key thread identifier allocation data conveniently and quickly when it is needed later, after executing S903, the electronic device can also add the corresponding relationship between the key thread corresponding to the target thread and the first thread identifier in the key thread identifier allocation data.

[0276] For the specific implementation of this possible implementation method, reference may be made to the relevant descriptions in S501-S504 in the aforementioned embodiment, which will not be described in detail here.

[0277] In another possible implementation, if the identifier allocation data includes the thread identifier of each key thread in multiple key threads, S903 may specifically include: the electronic device determines, based on the thread information of the target thread, the thread identifier of the key thread whose thread information in the identifier allocation data is the same as the thread information of the target thread, as the first thread identifier of the target thread.

[0278] For the specific implementation of this possible implementation method, reference may be made to the relevant description in S601 in the aforementioned embodiment, which will not be described in detail here.

[0279] S904: The electronic device completes creation of a target thread based on the first thread identifier.

[0280] The specific implementation of S904 may refer to the related descriptions of S406-S407 in the aforementioned embodiment, which will not be repeated here.

[0281] Based on the technical solution provided by the present application, it is possible to assign a fixed thread identifier to a critical thread each time it is created based on pre-configured critical thread identifier allocation data. Among them, the critical thread identifier allocation data can be used to guide the allocation of the thread identifier of the critical thread, and the thread identifier of the critical thread after allocation is fixed. In this way, since the present technical solution can assign a fixed thread identifier to a specific critical thread based on the pre-configured critical thread identifier allocation data, subsequent electronic devices can accurately and quickly obtain the thread identifier of the critical thread when they need to obtain the critical thread identifier, thereby improving the efficiency of obtaining the thread identifier of the critical thread. In addition, the optimization strategy based on the thread identifier of the critical thread, which aims to improve the fluency of the system, is smoothly implemented, thereby improving the user experience.

[0282] In some embodiments, if the identifier allocation data includes the thread identifier of each critical thread in multiple critical threads, when the thread detection result is used to indicate that the target thread is a critical thread, the method also includes: the electronic device determines the expected thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data; the electronic device determines the expected thread identifier as the first thread identifier of the target thread; and the electronic device completes the creation of the target thread based on the first thread identifier.

[0283] Specifically, the specific implementation and effect of the above solution can refer to the relevant description of S703 in the above embodiment, which will not be repeated here.

[0284] Furthermore, after the electronic device determines the expected thread identifier of the target thread based on the thread information of the target thread and the critical thread identifier allocation data, the method also includes: the electronic device verifies the thread information of the target thread and the expected thread identifier of the target thread based on the critical thread identifier allocation data to obtain a verification result; the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, or the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are non-critical thread data; when the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, the electronic device determines the expected thread identifier as the first thread identifier of the target thread.

[0285] Specifically, the specific implementation and effect of the above solution can refer to the relevant descriptions of S704-S706 in the aforementioned embodiment, and will not be repeated here.

[0286] In addition, in order to ensure that the electronic device can normally assign thread identifiers to non-critical threads, when the thread detection result indicates that the target thread is not a critical thread, the method further includes: the electronic device determines the second thread identifier of the target thread from the thread identifiers other than all thread identifiers corresponding to the critical thread identifier assignment data according to the default assignment rule. Exemplarily, the default assignment rule includes: determining the thread identifier with the smallest value from the thread identifiers other than all thread identifiers corresponding to the critical thread identifier assignment data as the second thread identifier of the target thread.

[0287] Specifically, the specific implementation and effects of the above solution can refer to the relevant descriptions of S408-S410 or S709-S711 in the aforementioned embodiments, and will not be repeated here.

[0288] It is understandable that, in order to realize the above functions, the above electronic device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present invention can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present application.

[0289] The embodiment of the present application can divide the functional modules of the above-mentioned electronic device according to the above-mentioned method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present invention is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0290] In the case of dividing each functional module into corresponding functional modules, refer to Fig.10 As shown, an embodiment of the present application provides an electronic device, which can implement the thread identifier allocation method provided in the above embodiment. The electronic device can include a thread creation module 1001 and a thread identifier allocation module 1002.

[0291] Specifically, the thread creation module 1001 is used to determine the thread information of the target thread when creating the target thread; the thread information includes the thread name and the process name of the process to which it belongs; the thread creation module 1001 is also used to determine the thread detection result based on the thread information of the target thread; the thread detection result is used to indicate that the target thread is a critical thread, or the thread detection result is used to indicate that the target thread is not a critical thread; the thread identifier allocation module 1002 is used to, when the thread detection result determined by the thread creation module 1001 is used to indicate that the target thread is a critical thread, determine the first thread identifier of the target thread based on the thread information of the target thread determined by the thread creation module 1001 and the critical thread identifier allocation data; the critical thread identifier allocation data includes thread information of multiple critical threads, and identifier allocation data; the identifier allocation data is used to instruct the electronic device to allocate a fixed thread identifier to the critical thread; the thread creation module 1001 is also used to complete the creation of the target thread based on the first thread identifier determined by the thread identifier allocation module 1002.

[0292] Optionally, the thread creation module 1001 is specifically used to determine the thread detection result based on the thread information of the target thread and the thread information of multiple key threads in the key thread identifier allocation data.

[0293] Optionally, the thread creation module 1001 is specifically used for: if, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of the first key thread is the same as the thread information of the target thread, then the thread detection result is used to indicate that the target thread is a key thread; if, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of any key thread is not the same as the thread information of the target thread, then the thread detection result is used to indicate that the target thread is not a key thread.

[0294] Optionally, the identifier allocation data includes a key identifier allocation range of a process to which each key thread among multiple key threads belongs, and the key identifier allocation range is used to indicate the range of thread identifiers available to the key threads under the process; the thread identifier allocation module 1002 is specifically used to: when the thread identifier of the target thread does not exist in the key thread identifier allocation data, determine the to-be-allocated thread identifier in the key identifier allocation range corresponding to the target thread from the identifier allocation data; and determine the first thread identifier of the target thread from all the to-be-allocated thread identifiers according to preset rules.

[0295] Optionally, the preset rule includes: taking the one with the smallest value among all the thread identifiers to be allocated as the first thread identifier.

[0296] Optionally, the thread identifier allocation module 1002 is further configured to add a correspondence between a key thread corresponding to the target thread and the first thread identifier in the key thread identifier allocation data.

[0297] Optionally, the identifier allocation data includes the thread identifier of each key thread in multiple key threads; the thread identifier allocation module 1002 is specifically used for: the electronic device determines the thread identifier of the key thread whose thread information in the identifier allocation data is the same as the thread information of the target thread as the first thread identifier of the target thread based on the thread information of the target thread.

[0298] Optionally, the identifier allocation data includes the thread identifier of each key thread in multiple key threads. When the thread detection result is used to indicate that the target thread is a key thread, the thread creation module 1001 is also used to determine the expected thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data; the thread identifier allocation module 1002 is also used to determine the expected thread identifier determined by the thread creation module 1001 as the first thread identifier of the target thread; the thread creation module 1001 is also used to complete the creation of the target thread based on the first thread identifier determined by the thread identifier allocation module 1002.

[0299] Optionally, after the thread creation module 1001 determines the expected thread identifier of the target thread, the thread identifier allocation module 1002 is further used 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 to obtain a verification result; the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, or the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are non-critical thread data; in the case where the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, the thread identifier allocation module 1002 is further used to determine the expected thread identifier as the first thread identifier of the target thread.

[0300] Optionally, when the thread detection result indicates 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 thread identifiers other than all thread identifiers corresponding to the critical thread identifier allocation data.

[0301] Optionally, the default allocation rule includes: determining the thread identifier with the smallest value among all thread identifiers other than the thread identifiers corresponding to the key thread identifier allocation data as the second thread identifier of the target thread.

[0302] Regarding the electronic device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the thread identifier allocation method in the above embodiment, and will not be elaborated here. The relevant beneficial effects can also refer to the relevant beneficial effects of the above thread identifier allocation method, and will not be repeated here.

[0303] The present application also provides an electronic device, which includes: a memory and one or more processors; the memory is coupled to the processor; wherein the memory stores computer program code, the computer program code includes computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the thread identifier allocation method provided in the above embodiment. The specific structure of the electronic device can be referred to Figure 2 The structure of the electronic device shown in .

[0304] An embodiment of the present application also provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the thread identifier allocation method provided in the above embodiment.

[0305] An embodiment of the present application also provides a computer program product, which includes executable instructions. When the computer program product is run on an electronic device, the electronic device executes the thread identifier allocation method provided in the above embodiment.

[0306] The present application also provides a chip system, such as Fig.11 As shown, the chip system 1100 includes at least one processor 1101 and at least one interface circuit 1102. The processor 1101 and the interface circuit 1102 can be interconnected through a line. For example, the interface circuit 1102 can be used to receive signals from other devices (such as a memory of an electronic device). For another example, the interface circuit 102 can be used to send signals to other devices (such as the processor 1101).

[0307] Exemplarily, the interface circuit 1102 can read the instruction stored in the memory and send the instruction to the processor 1101. When the instruction is executed by the processor 1101, the electronic device can execute each step in the above embodiment. Of course, the chip system can also include other discrete devices, which is not specifically limited in the embodiment of the present application.

[0308] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0309] In the several embodiments provided in the present application, it should be understood that the disclosed devices / equipment and methods can be implemented in other ways. For example, the device / equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0310] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0311] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0312] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0313] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A thread identifier allocation method, characterized in that: Applied to electronic equipment, the method comprises: When creating a target thread, the electronic device determines thread information of the target thread; the thread information includes a thread name and a process name of the process to which it belongs; The electronic device determines a thread detection result based on the thread information and the associated information of the target thread; the thread detection result is used to indicate that the target thread is a critical thread, or the thread detection result is used to indicate that the target thread is not a critical thread; the associated information includes an associated relationship between multiple critical threads and multiple thread information; In the case where the thread detection result indicates that the target thread is a critical thread, the electronic device determines a first thread identifier of the target thread based on thread information of the target thread and critical thread identifier allocation data; the critical thread identifier allocation data includes thread information of a plurality of critical threads and identifier allocation data; the identifier allocation data includes a correspondence between each critical thread and a thread identifier; The electronic device completes creation of the target thread based on the first thread identifier.

2. The method according to claim 1, characterized in that: The association information is the key thread identification allocation data.

3. The method according to claim 2, characterized in that The electronic device determines a thread detection result based on the thread information of the target thread and the thread information of multiple key threads in the key thread identifier allocation data, including: If, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of a first key thread is the same as the thread information of the target thread, the thread detection result is used to indicate that the target thread is a key thread; If, among the thread information of multiple key threads in the key thread identifier allocation data, the thread information of any key thread is not the same as the thread information of the target thread, the thread detection result is used to indicate that the target thread is not a key thread.

4. The method according to claim 1, characterized in that: The corresponding relationship includes a key identifier allocation range of a process to which each key thread among the multiple key threads belongs, and the key identifier allocation range is used to indicate a range of thread identifiers available to the key threads under the process; The electronic device determines the first thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data, including: When the thread identifier of the target thread does not exist in the key thread identifier allocation data, the electronic device determines the thread identifier to be allocated in the key identifier allocation range corresponding to the target thread from the corresponding relationship; The electronic device module determines the first thread identifier of the target thread from all thread identifiers to be allocated according to a preset rule.

5. The method according to claim 4, characterized in that: The preset rule includes: taking the one with the smallest value among all the thread identifiers to be allocated as the first thread identifier.

6. The method according to claim 4, characterized in that After the electronic device module determines the first thread identifier of the target thread from all thread identifiers to be allocated according to a preset rule, the method further includes: The electronic device adds a correspondence between a critical thread corresponding to the target thread and the first thread identifier in the critical thread identifier allocation data.

7. The method according to claim 1, characterized in that The corresponding relationship includes a thread identifier of each key thread in the multiple key threads; The electronic device determines the first thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data, including: The electronic device determines, based on the thread information of the target thread, a thread identifier of a key thread having the same thread information as the thread information of the target thread in the corresponding relationship as a first thread identifier of the target thread.

8. The method according to claim 1, characterized in that The identification allocation data includes a thread identification of each key thread in the multiple key threads. When the thread detection result is used to indicate that the target thread is a key thread, the method further includes: The electronic device determines the expected thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data; The electronic device determines the expected thread identifier as the first thread identifier of the target thread; The electronic device completes creation of the target thread based on the first thread identifier.

9. The method according to claim 8, characterized in that After the electronic device determines the expected thread identifier of the target thread based on the thread information of the target thread and the key thread identifier allocation data, the method further includes: The electronic device verifies the thread information of the target thread and the expected thread identifier of the target thread based on the critical thread identifier allocation data to obtain a verification result; the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are critical thread data, or the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are non-critical thread data; In a case where the verification result is used to indicate that the thread information of the target thread and the expected thread identifier of the target thread are key thread data, the electronic device determines the expected thread identifier as the first thread identifier of the target thread.

10. The method according to any one of claims 1 to 9, characterized in that: When the thread detection result indicates 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 thread identifiers other than all thread identifiers corresponding to the critical thread identifier allocation data.

11. The method according to claim 10, characterized in that The default allocation rule includes: determining the thread identifier with the smallest value among all thread identifiers other than the thread identifiers corresponding to the key thread identifier allocation data as the second thread identifier of the target thread.

12. An electronic device, characterized in that: It comprises a memory and one or more processors; the memory is coupled to the processor; wherein the memory stores computer program code, the computer program code comprises computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the thread identifier allocation method as described in any one of claims 1-11.

13. A computer-readable storage medium, characterized in that: The method comprises computer instructions, and when the computer instructions are executed on an electronic device, the electronic device executes the thread identifier allocation method according to any one of claims 1 to 11.