Thread control method and device, storage medium and computer program product
By detecting and adjusting the locked state and synchronization state of the target thread, identifying and optimizing the running parameters of the first-level associated thread, the problem of slow response in the blocked state is solved, and fast response execution is achieved.
Patent Information
- Application Number
- CN202410145324.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-01
- Publication Date
- 2025-08-01
AI Technical Summary
When multiple threads are accessed concurrently and the target thread is in a blocking state, the prior art cannot effectively improve its running speed, resulting in slow response execution.
By detecting the locked and synchronous state of the target thread, the first-level associated thread is identified and its running parameters are adjusted to reduce the blocking time of the target thread.
It effectively reduces the time when the target thread is blocked, ensures that it can respond quickly to execution, and improves the system's operating efficiency.
Smart Images

Figure CN120407216A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to thread control, but is not limited to the field of thread control, and particularly relates to a thread control method, apparatus, electronic device, storage medium, and computer program product. Background Art
[0002] In the related art, concurrent access of threads has increasingly become a performance bottleneck of mobile phone systems. How to still enable a target thread to be quickly responded and executed when multiple threads access concurrently has become a hot topic in system optimization. In the related art, when the target thread is not in a blocked state, the running speed of the target thread can be increased by increasing the priority of the target thread, so that the target thread can be quickly responded and executed. However, in the related art, when the target thread is in a blocked state, even if the priority of the target thread is increased, the running speed of the target thread cannot be effectively increased, resulting in the target thread not being able to be quickly responded and executed. Thus, there is a problem in the related art that it is difficult to quickly run the target thread. Summary of the Invention
[0003] To overcome the problems existing in the related art, embodiments of the present disclosure disclose a thread control method, apparatus, electronic device, storage medium, and computer program product to solve the problem of how to increase the running speed of a target thread.
[0004] According to a first aspect of embodiments of the present disclosure, a thread control method is provided. The method includes:
[0005] When the target thread is in a blocked state, detecting the lock-holding state and synchronization state of the target thread to obtain a first detection result;
[0006] When it is determined based on the first detection result that there is a first lock-holding thread holding a first target lock or a first synchronization thread associated with the target thread, determining the first lock-holding thread or the first synchronization thread as the first-level associated thread corresponding to the target thread; where the first target lock is the target lock waited for by the target thread;
[0007] Adjusting the running parameters of the first-level associated thread to reduce the blocked time of the target thread.
[0008] In some embodiments, the method further includes:
[0009] After adjusting the running parameters of the first-level associated thread, if the first-level associated thread releases the first target lock or completes synchronization with the first synchronization thread, running the target thread.
[0010] In some embodiments, the method further includes:
[0011] After adjusting the running parameters of the first-level associated thread, if the first-level associated thread is in a blocked state, determine the second-level associated thread associated with the first-level associated thread;
[0012] Adjust the running parameters of the second-level associated thread. If the second-level associated thread is in a blocked state, determine the third-level associated thread associated with the second-level associated thread until traversing the associated threads associated with the target thread.
[0013] In some embodiments, among the associated threads associated with the target thread, the (N + 1)-th level associated thread includes: the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread associated with the N-th level associated thread; the (N + 1)-th lock-holding thread holds the (N + 1)-th target lock waited for by the N-th level associated thread; N is a positive integer.
[0014] In some embodiments, the method includes:
[0015] After adjusting the running parameters of the (N + 1)-th level associated thread, if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes synchronization with the (N + 1)-th synchronization thread, run the N-th level associated thread;
[0016] If the first-level associated thread releases the held first target lock or completes synchronization with the first synchronization thread, run the target thread.
[0017] In some embodiments, the method further includes: configuring a tag for each determined level of associated thread; wherein, the tag is used to identify the level corresponding to the associated thread;
[0018] Adjusting the running parameters of the first-level associated thread includes:
[0019] When it is detected that there is a tag corresponding to the first-level associated thread, adjust the running parameters of the first-level associated thread;
[0020] Adjusting the running parameters of the second-level associated thread includes:
[0021] When it is detected that there is a tag corresponding to the second-level associated thread, adjust the running parameters of the second-level associated thread.
[0022] In some embodiments, the method further includes:
[0023] If the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization, delete the tag corresponding to the (N + 1)-th level associated thread and cancel the set (N + 1)-th level associated thread;
[0024] and / or,
[0025] If the first-level associated thread releases the held first target lock or completes thread synchronization, delete the tag corresponding to the first-level associated thread and cancel the set first-level associated thread.
[0026] In some embodiments, the method further includes:
[0027] If the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization, adjust the operating parameters of the (N + 1)-th level associated thread to the initial operating parameters corresponding to the (N + 1)-th level associated thread;
[0028] and / or,
[0029] If the first-level associated thread releases the held first target lock or completes thread synchronization, adjust the operating parameters of the first-level associated thread to the initial operating parameters corresponding to the first-level associated thread;
[0030] Wherein, the initial operating parameters corresponding to the (N + 1)-th level associated thread are the operating parameters corresponding to the (N + 1)-th level associated thread before adjusting the operating parameters of the (N + 1)-th level associated thread; the initial operating parameters corresponding to the first-level associated thread are the operating parameters corresponding to the first-level associated thread before adjusting the operating parameters of the first-level associated thread.
[0031] According to a second aspect of the embodiments of the present disclosure, there is provided a thread control device, the device includes:
[0032] A detection module, configured to detect the lock-holding state and synchronization state of a target thread when the target thread is in a blocked state, and obtain a first detection result;
[0033] A determination module, configured to, when it is determined based on the first detection result that there is a first lock-holding thread holding a first target lock or a first synchronization thread associated with the target thread, determine the first lock-holding thread or the first synchronization thread as the first-level associated thread corresponding to the target thread; wherein, the first target lock is the target lock waited for by the target thread;
[0034] An adjustment module, configured to adjust the operating parameters of the first-level associated thread to reduce the blocked time of the target thread.
[0035] According to a third aspect of the embodiments of the present disclosure, there is provided an electronic device, including:
[0036] A processor;
[0037] A memory for storing computer programs or instructions;
[0038] Wherein, the processor executes the computer program or instruction to implement the steps of any one of the thread control methods in the present disclosure.
[0039] According to a fourth aspect of the embodiments of the present disclosure, there is provided a non-transitory computer-readable storage medium storing a computer program or instructions. When the computer program or instructions in the storage medium are executed by a processor, the steps of any one of the thread control methods in the present disclosure are implemented.
[0040] According to a fourth aspect of the embodiments of the present disclosure, there is provided a computer program product including a computer program or instructions. When the computer program or instructions are executed by a processor, the steps of any one of the thread control methods in the present disclosure are implemented.
[0041] The technical solutions provided by the embodiments of the present disclosure may include the following beneficial effects:
[0042] In the embodiments of the present disclosure, when the target thread is in a blocked state, the lock-holding state and the synchronization state of the target thread are detected simultaneously. That is, when the target thread enters the blocked state due to waiting for lock-holding or waiting for the synchronization thread to run successfully, the reasons for blocking the target thread from running, i.e., waiting for lock-holding or waiting for the synchronization thread to run successfully, are comprehensively detected, so as to accurately identify the first lock-holding thread or the first synchronization thread that blocks the target thread from running.
[0043] Compared with the related art in which the target thread cannot be quickly responded and executed when the target thread is in a blocked state, in the embodiments of the present disclosure, by adjusting the running parameters of the accurately identified first lock-holding thread or first synchronization thread, the time for the target thread to be blocked by the first lock-holding thread or the first synchronization thread can be effectively reduced, so as to ensure that the target thread can quickly enter the running state. In this way, the running effect of the target thread can be ensured to be good in the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present disclosure and used together with the specification to explain the principles of the present disclosure.
[0045] Figure 1 It is a schematic flowchart of a thread control method shown according to an exemplary embodiment.
[0046] Figure 2 It is a schematic flowchart of a thread control method shown according to an exemplary embodiment.
[0047] Figure 3 It is a schematic flowchart of a thread control method shown according to an exemplary embodiment.
[0048] Figure 4 It is a schematic structural diagram of a thread control device shown according to an exemplary embodiment.
[0049] Figure 5 It is a schematic structural diagram of an electronic device shown according to an exemplary embodiment. Detailed implementation manners
[0050] In order to make the objectives, technical solutions, and advantages of the present disclosure clearer, the present disclosure will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be construed as limitations on the present disclosure. All other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present disclosure.
[0051] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments. However, it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and they can be combined with each other without conflict.
[0052] In the following description, the terms "first / second / third" are used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first / second / third" can be interchanged with a specific order or sequence when permitted, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0053] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the art belonging to the technical field of the present disclosure. The terms used herein are only for the purpose of describing the embodiments of the present disclosure and are not intended to limit the present disclosure.
[0054] As Figure 1 shown, the embodiments of the present disclosure provide a thread control method, and the method includes:
[0055] Step S11, when the target thread is in a blocked state, detecting the lock-holding state and synchronization state of the target thread to obtain a first detection result;
[0056] Step S12, when it is determined based on the first detection result that there is a first lock-holding thread holding a first target lock or a first synchronization thread associated with the target thread, determining the first lock-holding thread or the first synchronization thread as the first-level associated thread corresponding to the target thread; wherein, the first target lock is the target lock that the target thread is waiting for;
[0057] Step S13, adjusting the running parameters of the first-level associated thread to adjust the blocked time of the target thread.
[0058] It can be understood that the first-level associated thread is the thread that directly blocks the running of the target thread.
[0059] In some embodiments, any of the methods in the embodiments of the present disclosure can be applied to an electronic device.
[0060] In some embodiments, the electronic device may include, but is not limited to, a mobile communication terminal, a portable entertainment device, a wearable device, a household appliance, and a dedicated device. Among them, the mobile communication terminal may include, but is not limited to, a mobile phone, a tablet computer, and a smart watch, etc.; the portable entertainment device may include, but is not limited to, an audio player and a digital camera; the wearable device may include, but is not limited to, a smart bracelet and smart glasses; the household appliance may include, but is not limited to, a television, a stereo, and a video recorder; the dedicated device includes, but is not limited to, a drone and an electronic game console.
[0061] In some embodiments, the target thread may be a critical thread in the system. The running priority corresponding to the critical thread may be higher than the priority threshold. And / or, the response time corresponding to the critical thread is set to be less than the time threshold. It can be understood that the critical thread may be a thread that needs to be quickly responded to in the system to enter the running state.
[0062] In some embodiments, the critical thread may be a thread related to display. Exemplarily, the critical thread may be a thread related to the data to be displayed. For example, the critical thread may be a thread for processing first predetermined data to obtain the data to be displayed. Here, by quickly running the critical thread, the speed of performing related operations on the data to be displayed can be increased, the display speed of the data to be displayed can be increased, the situation of frame stuttering can be reduced, and the user experience can be improved during the interaction between the user and the device.
[0063] In some embodiments, the critical thread may be a thread related to audio output. Exemplarily, the critical thread may be a thread related to audio data. For example, the critical thread may be a thread for processing second predetermined data to obtain audio data. Here, by quickly running the critical thread, the speed of performing related operations on the audio data can be increased, the speed of outputting the audio data can be increased, the situation of the device getting stuck in sound can be reduced, and the user experience can be improved during the interaction between the user and the device.
[0064] It can be understood that the target thread may enter the blocked state (interrupted sleep) due to being interrupted by other threads, or the target thread may not enter the blocked state (uninterrupted sleep) due to being terminated by other threads. For example, it may be the case that when the target thread needs to call a predetermined resource, and since the predetermined resource has not been released by other threads, the target thread enters the blocked state.
[0065] In some embodiments, the target thread being in a blocked state may mean that during the operation of the system, the target thread falls into a long-term sleep due to reasons such as lock acquisition failure and / or waiting for a synchronization thread, resulting in the target thread being in a state where it cannot run normally.
[0066] In some embodiments, when the target thread is in a blocked state, the operating parameters of the target thread can be adjusted.
[0067] For example, when the target thread is in a blocked state, the operating priority of the target thread can be adjusted, and / or, the processor corresponding to the target thread can be adjusted. The adjusted operating priority corresponding to the target thread can be higher than the operating priority before adjustment, and the computing power resources corresponding to the adjusted processor corresponding to the target thread can be greater than the computing power resources corresponding to the adjusted processor.
[0068] In some embodiments, detecting the lock-holding state and synchronization state of each thread to obtain a first detection result includes: detecting whether there is a first lock-holding thread and detecting whether there is a first synchronization thread to obtain a first detection result.
[0069] In some embodiments, the first detection result may include at least one of the following: the blocking type corresponding to the target thread and the blocking thread. The blocking type corresponding to the target thread can indicate the reason for blocking the target thread. For example, the blocking type can include lock blocking and synchronization task blocking. When the blocking type is lock blocking, the target thread enters the blocked state due to waiting to hold the first target lock; or, when the blocking type is synchronization task blocking, the target thread enters the blocked state due to waiting for the first synchronization thread to run successfully. The blocking thread corresponding to the target thread can be the specific thread that blocks the operation of the target thread. For example, the blocking thread can be the first lock-holding thread or the first synchronization thread.
[0070] In some embodiments, the blocking thread corresponding to the target thread can be determined based on the blocking type corresponding to the target thread.
[0071] For example, when the blocking type corresponding to the target thread is lock blocking, the blocking thread corresponding to the target thread can be determined as the first lock-holding thread. Or, when the blocking type corresponding to the target thread is synchronization task blocking, the blocking thread corresponding to the target thread can be determined as the first lock-holding thread.
[0072] In some embodiments, in the case where the blocking type is lock blocking, the type of the first holding thread can be determined based on the type of the first target lock that the target thread is waiting to hold. The first target lock can be a lock including but not limited to at least one of the following: mutually exclusive (mutex), read-write semaphore (rwsem), and fast userspace mutex (futex).
[0073] In some embodiments, when a thread is in a blocked state, the address of the target lock that the thread is waiting to hold or the synchronization thread associated with the thread can be stored.
[0074] In some embodiments, in the case where it is determined that the target thread is blocked, the first detection result can be determined based on the stored address of the first target lock or the first synchronization thread corresponding to the target thread. The first detection result at least includes the first holding thread or the first synchronization thread that holds the first target lock.
[0075] It can be understood that in the present disclosure, after determining the first-level associated thread corresponding to the target thread as the first holding thread or the first synchronization thread, the operating parameters of the first-level associated thread can be adjusted. Here, the specific type of the operating parameters of the first-level associated thread and the specific manner of adjusting the operating parameters are not limited, and it is only necessary to ensure that after the first-level associated thread runs according to the adjusted operating parameters, the blocking time of the target thread can be reduced.
[0076] In some embodiments, the operating parameters of the first-level associated thread can be adjusted to increase the running speed of the first-level associated thread.
[0077] In some embodiments, the operating parameters can be used to determine at least one of the following: the running priority and the corresponding processor for running the thread. Different computing power resources can be configured for different processors.
[0078] In some embodiments, adjusting the operating parameters of the first-level associated thread can mean increasing the running priority of the first-level associated thread. In this way, by increasing the running priority of the first-level associated thread, the corresponding running speed of the first-level associated thread can be increased.
[0079] In some embodiments, the running priority of the first-level associated thread can be adjusted based on the running priority corresponding to the target thread. For example, the adjusted first-level associated thread can be consistent with the running priority corresponding to the target thread.
[0080] In some embodiments, adjusting the operating parameters of the first-level associated threads may refer to adjusting the processor corresponding to the first-level associated threads to a target processor. The computing power resources corresponding to the processor before adjustment are less than those corresponding to the target processor. Here, the computing power resources of the processor running the first-level associated threads can be increased to utilize sufficient computing power resources to quickly run the first-level associated threads, thereby increasing the running speed corresponding to the first-level associated threads.
[0081] In some embodiments, the operating priority of the first-level associated threads may be adjusted based on the processor corresponding to the target thread. Exemplarily, the computing power resources of the processor corresponding to the adjusted first-level associated threads may be the same as those of the processor corresponding to the target thread. For example, the processor corresponding to the adjusted first-level associated threads may be the same as the processor corresponding to the target thread.
[0082] In the embodiments of the present disclosure, when the target thread is in a blocked state, the lock-holding state and synchronization state of the target thread are detected simultaneously. That is, when the target thread enters the blocked state due to waiting for lock-holding or waiting for the synchronization thread to run successfully, the reasons for blocking the target thread from running, i.e., waiting for lock-holding or waiting for the synchronization thread to run successfully, are comprehensively detected, so as to accurately identify the first lock-holding thread or the first synchronization thread that blocks the target thread from running.
[0083] Compared with the related art where the target thread cannot be quickly responded and executed when it is in a blocked state, in the embodiments of the present disclosure, by adjusting the operating parameters of the accurately identified first lock-holding thread or first synchronization thread, the time for the target thread to be blocked by the first lock-holding thread or first synchronization thread can be effectively reduced, thereby ensuring that the target thread can quickly enter the running state. In this way, the running effect of running the target thread can be ensured in the present disclosure.
[0084] In some embodiments, the method further includes:
[0085] After adjusting the operating parameters of the first-level associated threads, if the first-level associated threads release the first target lock or complete synchronization with the first synchronization thread, then run the target thread.
[0086] It can be understood that after adjusting the operating parameters of a thread, if the thread does not fall into a blocked state, the thread will run according to the adjusted operating parameters. For example, here, after adjusting the operating parameters of the first-level associated threads, if the first-level associated threads do not fall into a blocked state, the first-level associated threads will run according to the adjusted operating parameters.
[0087] In some embodiments, if the first-level associated thread only includes the first lock-holding thread, then after adjusting the running parameters of the first-level associated thread, if the first-level associated thread releases the first target lock, the first-level associated thread is run. Alternatively, if the first-level associated thread only includes the first synchronization thread, then after adjusting the running parameters of the first-level associated thread, if the first-level associated thread completes synchronization with the first synchronization thread, the first-level associated thread is run.
[0088] In the embodiments of the present disclosure, after adjusting the running of the first-level associated thread, during the process of running the first-level associated thread based on the adjusted running parameters, the running speed of the first-level associated thread can be increased, so that the first-level associated thread quickly releases the first target lock or completes synchronization with the first synchronization thread. In this way, when the first-level associated thread quickly releases the first target lock or completes synchronization with the first synchronization thread, the target thread can be quickly run to accelerate the response speed of the target thread's running.
[0089] In some embodiments, the method further includes:
[0090] After adjusting the running parameters of the first-level associated thread, if the first-level associated thread is in a blocked state, determine the second-level associated thread associated with the first-level associated thread;
[0091] Adjust the running parameters of the second-level associated thread. If the second-level associated thread is in a blocked state, determine the third-level associated thread associated with the second-level associated thread until all the associated threads associated with the target thread are traversed.
[0092] In some embodiments, after adjusting the running parameters of the first-level associated thread, if the first-level associated thread is in a blocked state, determine the second-level associated thread associated with the first-level associated thread; adjust the running parameters of the second-level associated thread. If the second-level associated thread is not in a blocked state, adjust the second-level associated thread according to the adjusted running parameters until the second-level associated thread does not block the running of the first-level associated thread or the second-level associated thread enters a blocked state.
[0093] It can be understood that after determining the second-level associated thread, if the second-level associated thread is not in a blocked state, there will be no third-level associated thread associated with the second-level associated thread, and there is no need to continue to determine the third-level associated thread associated with the target thread. At this time, only the running parameters of the second-level associated thread need to be adjusted, and the second-level associated thread is run according to the adjusted running parameters until the second-level associated thread runs successfully or the second-level associated thread enters a blocked state.
[0094] Here, the Nth-level associated thread may enter a blocked state (interrupted sleep) due to being interrupted by other threads, or the Nth-level associated thread may not enter a blocked state due to being interrupted by other threads (uninterrupted sleep); where N is a positive integer. For example, it may be the case that when the Nth-level associated thread needs to call a predetermined resource, and since the predetermined resource has not been released by other threads, the Nth-level associated thread enters a blocked state.
[0095] In some embodiments, when the Nth-level associated thread enters a blocked state, the (N + 1)th-level associated thread associated with the Nth-level associated thread may be determined; where N is a positive integer. For example, N may be 1, or N may be 2. It can be understood that here, the (N + 1)th-level associated thread associated with the Nth-level associated thread can be understood as the (N + 1)th-level associated thread that blocks the operation of the Nth-level associated thread. That is, the (N + 1)th-level associated thread blocks the operation of the Nth-level associated thread.
[0096] In some embodiments, after determining the (N + 1)th-level associated thread, the operating parameters of the (N + 1)th-level associated thread may be adjusted. The operating parameters of the (N + 1)th-level associated thread can be used to determine at least one of the following: the operating priority of the (N + 1)th-level associated thread and the processor for running the (N + 1)th-level associated thread. The adjusted operating priority of the Nth-level associated thread is higher than the priority of the Nth-level associated thread before adjustment. And / or, the computing power resources of the adjusted processor corresponding to the Nth-level associated thread are higher than the computing power resources of the processor before adjustment.
[0097] In some embodiments, after adjusting the operating parameters of the Nth-level associated thread and when the Nth-level associated thread is in an unblocked state, the Nth-level associated thread may be run based on the adjusted operating parameters corresponding to the Nth-level associated thread; during the process of running the Nth-level associated thread, when the Nth-level associated thread is in a blocked state, the (N + 1)th-level associated thread that blocks the operation of the Nth-level associated thread is determined.
[0098] In some embodiments, when the operating parameters of the Nth-level associated thread are adjusted for the first time and it is determined that there is an (N + 1)th-level associated thread, the operating parameters of the Nth-level associated thread may be adjusted for the second time. Wherein, the adjusted operating priority of the Nth-level associated thread after the second adjustment is higher than the operating priority of the Nth-level associated thread after the first adjustment. And / or, the computing power resources of the adjusted processor corresponding to the Nth-level associated thread after the second adjustment are higher than the computing power resources of the processor after the first adjustment.
[0099] Here, when the N - level associated thread is blocked by the (N + 1)-level associated thread, by readjusting the operating parameters of the N - level associated thread, when the (N + 1)-level associated thread finishes running, the running speed of the N - level associated thread can be increased, the impact of the event that the (N + 1)-level associated thread blocks the N - level associated thread on the running duration of the N - level associated thread can be reduced, the completion of the running of the N - level associated thread can be accelerated, and the target thread can be quickly triggered to be responded to and run.
[0100] In some embodiments, a blocking link corresponding to the target thread can be constructed; when the first - level associated thread that blocks the target thread is determined, the first - level associated thread can be added to the blocking link; when the (N + 1)-level associated thread that blocks the running of the N - level associated thread is determined, the (N + 1)-level associated thread can be added to the blocking link.
[0101] In some embodiments, when the N - level associated thread exists in the blocking link, the operating parameters of the N - level associated thread are adjusted. Or, when the N - level associated thread does not exist in the blocking link, the operating parameters of the N - level associated thread are not adjusted. Here, the operating parameters of the N - level associated thread can be adjusted only when the N - level associated thread exists in the blocking link. In this way, it is convenient to manage each thread that blocks the target thread by using the blocking link, and the management efficiency can be improved.
[0102] In some embodiments, when the N - level associated thread is determined, the operating parameters of the N - level associated thread can be adjusted; when the N - level associated thread exists in the blocking link, the N - level associated thread can be run based on the adjusted operating parameters corresponding to the N - level associated thread; or, when the N - level associated thread does not exist in the blocking link, the N - level associated thread can be run without relying on the adjusted operating parameters corresponding to the N - level associated thread.
[0103] In the present disclosure, traversing the associated threads associated with the target thread can be understood as, when the last - level associated thread determined is in a blocked state, continuing to determine the next - level associated thread. When the last - level associated thread determined is in an unblocked state, it can be determined that the traversal of the associated threads associated with the target thread is completed.
[0104] In some embodiments, if the associated thread at the last level is in an unblocked state, it can be determined that the traversal of the associated threads associated with the target thread is completed; if the associated thread at the last level switches from an unblocked state to a blocked state, the traversal of the associated threads associated with the target thread can continue until the re-determined associated thread at the last level is in an unblocked state. For example, the associated thread at the last level can be the Nth-level associated thread. If the Nth-level associated thread is in an unblocked state, it can be determined that the traversal of the associated threads associated with the target thread is completed; if the Nth-level associated thread switches from an unblocked state to a blocked state, the traversal of the associated threads associated with the target thread can continue until the re-determined associated thread at the last level is in an unblocked state.
[0105] It can be understood that at different times, the associated thread at the last level associated with the target thread can be different.
[0106] Exemplarily, at the first moment, the associated thread at the last level can be the (N + 1)th-level associated thread; at the second moment, if the (N + 1)th-level associated thread releases the (N + 1)th target lock or completes thread synchronization, the Nth-level associated thread is run. At this time, at the second moment, the associated thread at the last level changes from the (N + 1)th-level associated thread to the Nth-level associated thread. The second moment can be greater than the first moment.
[0107] Exemplarily, if at the first moment the associated thread at the last level is the (N + 1)th-level associated thread and the (N + 1)th-level associated thread is in an unblocked state, it can be determined that the traversal of the associated threads associated with the target thread is completed; if at the second moment the associated thread at the last level changes to the Nth-level associated thread and the Nth-level associated thread is in a blocked state, the (N + 1)th-level associated thread can be determined to continue (i.e., continue to traverse the associated threads associated with the target thread).
[0108] It can be understood that the (N + 1)th-level associated thread to be determined at the second moment can be the same as the (N + 1)th-level associated thread at the first moment. That is to say, at different times, the (N + 1)th-level associated thread blocking the Nth-level associated thread can be the same. After the (N + 1)th-level associated thread at the first moment stops blocking the operation of the Nth-level associated thread, it may start blocking the operation of the Nth-level associated thread again at the second moment. Or, the (N + 1)th-level associated thread to be determined at the second moment can also be different from the (N + 1)th-level associated thread at the first moment. That is to say, at different times, the (N + 1)th-level associated thread blocking the Nth-level associated thread can be different. In the present disclosure, the associated threads at each level can be dynamically changed.
[0109] In the present disclosure, it is possible to accurately identify the associated threads blocking the target thread and the next-level associated threads blocking the associated threads, that is, it is possible to accurately identify all the threads nestedly blocking the target thread. And by adjusting the running parameters of the accurately identified associated threads at all levels, so that the associated threads at all levels can quickly break away from the blocked state, reduce the time for the associated threads at all levels to be blocked, and increase the running speed of the associated threads at all levels. In this way, by increasing the running speed of the associated threads at all levels directly or indirectly blocking the target thread, the time for the target thread to be blocked can be effectively reduced, ensuring that the target thread can quickly switch from the blocked state to the running state, and ensuring good running effect of the running target thread.
[0110] In some embodiments, among the associated threads associated with the target thread, the (N + 1)-th level associated thread includes: the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread associated with the N-th level associated thread; the (N + 1)-th lock-holding thread holds the (N + 1)-th target lock waited for by the N-th level associated thread; N is a positive integer.
[0111] In some embodiments, please refer to Figure 2 , the method includes:
[0112] S21, when the N-th level associated thread is in a blocked state, detect the lock-holding state and synchronization state of the N-th level associated thread to obtain the (N + 1)-th detection result;
[0113] S22, when it is determined based on the (N + 1)-th detection result that there is an (N + 1)-th lock-holding thread holding the (N + 1)-th target lock or an (N + 1)-th synchronization thread associated with the N-th level associated thread, determine the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread associated with the N-th level associated thread as the (N + 1)-th level associated thread; wherein, the (N + 1)-th target lock is the target lock waited for by the second-level associated thread; N is a positive integer;
[0114] S23, adjust the running parameters of the (N + 1)-th level associated thread to reduce the time for the N-th level associated thread to be blocked.
[0115] In some embodiments, the (N + 1)-th detection result may include the blocking type and / or blocking thread corresponding to the N-th level associated thread. The blocking type corresponding to the N-th level associated thread is used to indicate the reason for the N-th level associated thread being blocked, and the blocking thread is the specific thread blocking the operation of the N-th level associated thread. For example, the blocking thread may be the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread associated with the N-th level associated thread.
[0116] Here, in the case where there is a (N + 1)-th level associated thread that blocks the operation of the N-th level associated thread, the operation parameters of the (N + 1)-th level associated thread can be adjusted to increase the operation speed of the (N + 1)-th level associated thread, so as to reduce the time that the N-th level associated thread is blocked. It can be understood that after determining the N-th level associated thread, if the N-th level associated thread is not in a blocked state, there will be no (N + 1)-th level associated thread associated with the N-th level associated thread, and there is no need to continue to determine the (N + 1)-th level associated thread associated with the target thread. At this time, only the operation parameters of the N-th level associated thread need to be adjusted, and the N-th level associated thread is run according to the adjusted operation parameters until the N-th level associated thread runs successfully or the N-th level associated thread enters a blocked state.
[0117] In some embodiments, when a thread is in a blocked state, the target lock that the thread waits to hold and / or the address of the synchronization thread associated with the thread can be stored. In the case where it is determined that the N-th level associated thread is in a blocked state, based on the stored address of the N-th target lock or the (N + 1)-th synchronization thread corresponding to the N-th level associated thread, an (N + 1)-th detection result can be determined; based on the (N + 1)-th detection result, the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread that holds the N-th target lock is determined, and the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread is set as the (N + 1)-th level associated thread. The N-th target lock is the target lock that the N-th level associated thread waits to hold.
[0118] In the embodiments of the present disclosure, when the N-th level associated thread is in a blocked state, the lock-holding state and the synchronization state of the N-th level associated thread are detected simultaneously. That is, in the case where the N-th level associated thread enters a blocked state due to waiting to hold a lock or waiting for the synchronization thread to run successfully, a comprehensive detection is performed on the reason for blocking the operation of the target thread, which is waiting to hold a lock or waiting for the synchronization thread to run successfully, so as to accurately identify the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread that blocks the operation of the target thread.
[0119] Compared with the related art, in the case where the N-th level associated thread is in a blocked state and the N-th level associated thread cannot be quickly responded and executed, in the embodiments of the present disclosure, by adjusting the operation parameters of the accurately identified (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread, the time that the N-th level associated thread is blocked by the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread can be effectively reduced, so as to ensure that the N-th level associated thread can quickly enter the running state. In this way, in the present disclosure, it can be ensured that all levels of associated threads that block the target thread can be quickly responded and run, thereby reducing the time that the target thread is blocked and ensuring that the running response speed of the target thread is fast.
[0120] In some embodiments, the method includes:
[0121] After adjusting the running parameters of the (N + 1)-th level associated thread, if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes synchronization with the (N + 1)-th synchronization thread, then run the N-th level associated thread;
[0122] If the first-level associated thread releases the held first target lock or completes synchronization with the first synchronization thread, then run the target thread.
[0123] It can be understood that in the present disclosure, after each level of associated thread releases the held target lock or completes thread synchronization in sequence, the next level of associated thread is run until the first-level associated thread finishes running, and then the target thread is run.
[0124] In some embodiments, after the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes synchronization with the (N + 1)-th synchronization thread, the (N + 1)-th level associated thread can be deleted from the blocking link.
[0125] In some embodiments, if the (N + 1)-th level associated thread does not enter the blocking state, and the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes synchronization with the N-th synchronization thread, then cancel the set (N + 1)-th level associated thread and run the N-th level associated thread; if the N-th level associated thread enters the blocking state during the running of the N-th level associated thread, update the (N + 1)-th level associated thread that blocks the running of the N-th level associated thread. N is greater than 1 or N equals 1, and N is a positive integer.
[0126] Exemplarily, the target thread may be thread a, and the Nth-level associated thread may be thread b. When the Nth-level associated thread b is in a blocked state, determine that the (N + 1)th-level associated thread that blocks the Nth-level associated thread b from running is thread c; after adjusting the running parameters of the (N + 1)th-level associated thread c, run the (N + 1)th-level associated thread c; if the (N + 1)th-level associated thread c does not enter a blocked state and the (N + 1)th-level associated thread c releases the held (N + 1)th target lock or completes synchronization with the Nth synchronization thread, cancel the set (N + 1)th-level associated thread c and continue to run the Nth-level associated thread b; if the Nth-level associated thread b enters a blocked state during the running of the Nth-level associated thread b, update the (N + 1)th-level associated thread that blocks the Nth-level associated thread b from running to thread d; adjust the running parameters of the (N + 1)th-level associated thread d and run the (N + 1)th-level associated thread d; if the (N + 1)th-level associated thread d does not enter a blocked state and the (N + 1)th-level associated thread d releases the held (N + 1)th target lock or completes synchronization with the Nth synchronization thread, cancel the set (N + 1)th-level associated thread d and continue to run the Nth-level associated thread b; if the Nth-level associated thread b does not enter a blocked state and the Nth-level associated thread b releases the held (N + 1)th target lock or completes synchronization with the Nth synchronization thread, cancel the set Nth-level associated thread b; if N is equal to 1, run the target thread a.
[0127] In some embodiments, the updated (N + 1)th-level associated thread may be re-added to the blocking link.
[0128] In the embodiments of the present disclosure, by adjusting the running parameters of the (N + 1)th-level associated thread, the Nth-level associated thread can be run in a timely manner after the (N + 1)th-level associated thread that blocks the Nth-level associated thread finishes running, until the target thread is run in a timely manner after quickly running through the first-level associated thread. In this way, the running speed of the target thread can be ensured.
[0129] In some embodiments, the method further includes:
[0130] Configuring a tag for each determined level of associated thread; wherein the tag is used to identify the level corresponding to the associated thread;
[0131] Adjusting the running parameters of the first-level associated thread includes:
[0132] When it is detected that there is a tag corresponding to the first-level associated thread, adjusting the running parameters of the first-level associated thread;
[0133] Adjusting the running parameters of the second-level associated thread includes:
[0134] When it is detected that there is a tag corresponding to the second-level associated thread, the operating parameters of the second-level associated thread are adjusted.
[0135] In some embodiments, tags are configured for each level of associated threads determined, including: when it is detected that there is a first-level associated thread, a tag can be configured for the first-level associated thread. When it is detected that there is an (N + 1)-th level associated thread, a tag can be configured for the (N + 1)-th level associated thread.
[0136] In some embodiments, when it is detected that there is a tag configured for the N-th level associated thread, the operating parameters of the N-th level associated thread are adjusted; or, when it is not detected that there is a tag configured for the N-th level associated thread, the operating parameters of the N-th level associated thread are not adjusted.
[0137] In some embodiments, after a tag is configured for the first-level associated thread, the first-level associated thread with the configured tag can be added to the blocking link corresponding to the target thread. After a tag is configured for the (N + 1)-th level associated thread, the (N + 1)-th level associated thread with the configured tag is added to the blocking link corresponding to the target thread.
[0138] In some embodiments, when it is detected that there is a first-level associated thread, it is determined whether there is a first-level associated thread in the blocking link corresponding to the target thread; when it is determined that there is a first-level associated thread in the blocking link, a tag is configured for the first-level associated thread. When it is determined that there is no first-level associated thread in the blocking link, a tag is not configured for the first-level associated thread.
[0139] In some embodiments, when it is detected that there is a tag corresponding to the first-level associated thread and the first-level associated thread is in the blocking link, the operating parameters of the first-level associated thread are adjusted.
[0140] In some embodiments, when it is detected that there is an (N + 1)-th level associated thread blocking the operation of the N-th level associated thread, it is determined whether there is an (N + 1)-th level associated thread in the blocking link corresponding to the target thread; when it is determined that there is an (N + 1)-th level associated thread in the blocking link, a tag is configured for the (N + 1)-th level associated thread. When it is determined that there is no (N + 1)-th level associated thread in the blocking link, a tag is not configured for the (N + 1)-th level associated thread. Here, by means of the tags configured for each level of associated threads, different levels of associated threads can be accurately identified in the blocking link, which can reduce the situation of misconfiguring tags for threads outside the blocking link and improve the management efficiency of the threads in the blocking link.
[0141] In some embodiments, when it is detected that there is a tag corresponding to the (N + 1)-th level associated thread and the (N + 1)-th level associated thread is in a blocked link, the running parameters of the (N + 1)-th level associated thread can be adjusted.
[0142] In some embodiments, when the target thread is in a blocked state, a blocked link corresponding to the target thread can be constructed and the target thread can be added to the blocked link. When the target thread is in the blocked link, the lock-holding state and synchronization state of the target thread are detected to obtain a first detection result. Alternatively, when the target thread is not in the blocked link, the lock-holding state and synchronization state of the target thread are not detected.
[0143] In some embodiments, a corresponding tag can be configured for the target thread. The tag is used to identify that each thread belongs to the target thread or an associated thread. The running parameters of the target thread can be adjusted based on the tag corresponding to the target thread. For example, when it is detected that there is a tag corresponding to the target thread, the running parameters of the target thread are adjusted. Alternatively, when it is not detected that there is a tag corresponding to the target thread, the running parameters of the target thread are not adjusted.
[0144] In the embodiments of the present disclosure, when it is detected that there are associated threads at all levels, the running parameters of the associated threads at all levels are not directly adjusted. Instead, the running parameters of the associated threads at all levels are adjusted only when the tags of the associated threads at all levels also meet the conditions. In this way, in the process of adjusting the running parameters of the associated threads at a predetermined level, the associated threads at the predetermined level can be accurately identified through the configured tags, reducing the situation of mis-adjusting the running parameters of non-associated threads or associated threads at other levels, and ensuring good adjustment effect of the adjusted running parameters.
[0145] In some embodiments, the method further includes:
[0146] If the (N + 1)-th level associated thread releases the held (N + 1)-th target lock and / or completes thread synchronization, the tag corresponding to the (N + 1)-th level associated thread is deleted, and the set (N + 1)-th level associated thread is cancelled;
[0147] and / or,
[0148] If the first-level associated thread releases the held first target lock and / or completes thread synchronization, the tag corresponding to the first-level associated thread is deleted, and the set first-level associated thread is cancelled.
[0149] In an embodiment of the present disclosure, if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization, the label corresponding to the N-th level associated thread is deleted, and the set (N + 1)-th level associated thread is cancelled. At this time, after the (N + 1)-th level associated thread finishes running, in the case where the label corresponding to the (N + 1)-th level associated thread cannot be detected, the running parameters of the (N + 1)-th level associated thread will not be mis-adjusted and the (N + 1)-th level associated thread will not be re-run. Moreover, if the first-level associated thread releases the held first target lock or completes thread synchronization, the label corresponding to the first-level associated thread is deleted, and the set first-level associated thread is cancelled. At this time, after the first-level associated thread finishes running, in the case where the label corresponding to the first-level associated thread cannot be detected, the running parameters of the first-level associated thread will not be mis-adjusted and the first-level associated thread will not be re-run. In this way, it can be ensured that the adjustment effect of adjusting the running parameters of the associated thread is good, and the situation of mis-running the associated thread is reduced.
[0150] In some embodiments, the method further includes:
[0151] If the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization, adjust the running parameters of the (N + 1)-th level associated thread to the initial running parameters corresponding to the (N + 1)-th level associated thread;
[0152] And / or,
[0153] If the first-level associated thread releases the held first target lock or completes thread synchronization, adjust the running parameters of the first-level associated thread to the initial running parameters corresponding to the first-level associated thread;
[0154] Wherein, the initial running parameters corresponding to the (N + 1)-th level associated thread are the running parameters corresponding to the (N + 1)-th level associated thread before adjusting the running parameters of the (N + 1)-th level associated thread; the initial running parameters corresponding to the first-level associated thread are the running parameters corresponding to the first-level associated thread before adjusting the running parameters of the first-level associated thread.
[0155] In some embodiments, before adjusting the running parameters of the first-level associated thread or the (N + 1)-th level associated thread, the first-level associated thread or the (N + 1)-th level associated thread can run according to the initial running parameters corresponding to the thread.
[0156] In the embodiments of the present disclosure, if the associated threads at all levels release the held target lock or complete thread synchronization, that is, when the associated threads at all levels do not directly block or indirectly block the running of the target thread, the running parameters of the associated threads at all levels will be adjusted to the initial running parameters. In this way, it is possible to reduce the situation where the running parameters of the associated threads at all levels do not meet the initial requirements while effectively reducing the blocked time of the target thread, and reduce the situation where the system resource scheduling deviates due to the continuous priority occupation of system resources by the associated threads at all levels. In this way, the reliability of the overall system resource scheduling can be ensured.
[0157] To better understand the embodiments of the present disclosure, please refer to Figure 3 , Figure 3 An exemplary thread control method is shown, and the method includes:
[0158] Step S31, run the target thread;
[0159] Step S32, during the running of the target thread, detect whether the target thread enters a blocked state;
[0160] If it is detected that the target thread enters a blocked state, then execute step S33; otherwise, continue to execute step S31;
[0161] It can be understood that during the running of the target thread, the target thread may enter a blocked state because it is interrupted by an associated thread, and / or the target thread may enter a dormant state (i.e., a blocked state) because it waits to hold a lock or waits for an associated synchronization thread to complete execution.
[0162] Step S33, determine the Nth-level associated thread associated with the target thread;
[0163] Wherein, N is a positive integer;
[0164] Step S34, detect whether the Nth-level associated thread enters a blocked state;
[0165] If it is detected that the Nth-level associated thread does not enter a blocked state, then execute step S35; or, execute step S33, at this time, update N in step S33, and the updated N is equal to the sum of the updated N and 1;
[0166] Step S35, adjust the running parameters of the Nth-level associated thread associated with the target thread, and run the Nth-level associated thread based on the adjusted running parameters;
[0167] Step S36, determine whether the Nth-level associated thread releases the held Nth target lock and / or completes synchronization with the Nth synchronization thread;
[0168] If it is determined that the Nth-level associated thread releases the held Nth target lock and / or completes synchronization with the Nth synchronization thread, step S37 is executed; otherwise, step S34 is executed;
[0169] Step S37, perform at least one of the following operations: delete the label corresponding to the Nth-level associated thread, adjust the running parameters of the Nth-level associated thread to the initial running parameters, and cancel the set Nth-level associated thread;
[0170] Step S38, determine whether N is equal to 1
[0171] If N is not equal to 1, after step S38 is executed, step S35 is executed. At this time, N in step S35 is updated, and the updated N is equal to the difference between the updated N and 1; or, if N is equal to 1, step S39 is executed;
[0172] Step S39, run the target thread.
[0173] As Figure 4 shown, an embodiment of the present disclosure provides a thread control device, and the device includes:
[0174] A detection module 41, configured to detect the lock-holding state and synchronization state of a target thread to obtain a first detection result when the target thread is in a blocked state;
[0175] A determination module 42, configured to determine the first hold thread or the first synchronization thread as the first-level associated thread corresponding to the target thread when it is determined based on the first detection result that there is a first hold thread holding the first target lock or a first synchronization thread associated with the target thread; wherein, the first target lock is the target lock waited for by the target thread;
[0176] An adjustment module 43, configured to adjust the running parameters of the first-level associated thread to reduce the blocked time of the target thread.
[0177] In some embodiments, the device further includes:
[0178] A running module, configured to run the target thread if the first-level associated thread releases the first target lock or completes synchronization with the first synchronization thread after the running parameters of the first-level associated thread are adjusted.
[0179] In some embodiments, the determination module 42 is configured to, after the running parameters of the first-level associated thread are adjusted, determine a second-level associated thread associated with the first-level associated thread if the first-level associated thread is in a blocked state; adjust the running parameters of the second-level associated thread, and if the second-level associated thread is in a blocked state, determine a third-level associated thread associated with the second-level associated thread until the associated threads associated with the target thread are traversed.
[0180] In some embodiments, among the associated threads associated with a target thread, the (N + 1)-th level associated thread includes: the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread associated with the N-th level associated thread; the (N + 1)-th lock-holding thread holds the (N + 1)-th target lock waited for by the N-th level associated thread; N is a positive integer.
[0181] In some embodiments, the running module is configured to: after adjusting the running parameters of the (N + 1)-th level associated thread, if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes synchronization with the (N + 1)-th synchronization thread, run the N-th level associated thread; if the first-level associated thread releases the held first target lock or completes synchronization with the first synchronization thread, run the target thread.
[0182] In some embodiments, the apparatus further includes:
[0183] a configuration module, configured to configure a label for each determined level of associated thread; wherein the label is used to identify the level corresponding to the associated thread;
[0184] an adjustment module 43, configured to adjust the running parameters of the first-level associated thread when detecting the existence of a label corresponding to the first-level associated thread; and adjust the running parameters of the second-level associated thread when detecting the existence of a label corresponding to the second-level associated thread.
[0185] In some embodiments, the apparatus further includes:
[0186] a deletion module, configured to delete the label corresponding to the (N + 1)-th level associated thread and cancel the set (N + 1)-th level associated thread if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization; and / or delete the label corresponding to the first-level associated thread and cancel the set (N + 1)-th level associated thread if the first-level associated thread releases the held first target lock or completes thread synchronization.
[0187] In some embodiments, the adjustment module 43 is configured to adjust the running parameters of the (N + 1)-th level associated thread to the initial running parameters corresponding to the (N + 1)-th level associated thread if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization; and / or adjust the running parameters of the first-level associated thread to the initial running parameters corresponding to the first-level associated thread if the first-level associated thread releases the held first target lock or completes thread synchronization;
[0188] Among them, the initial operating parameter corresponding to the (N + 1)-th level associated thread is the operating parameter corresponding to the (N + 1)-th level associated thread before adjusting the operating parameter of the (N + 1)-th level associated thread; the initial operating parameter corresponding to the first-level associated thread is the operating parameter corresponding to the first-level associated thread before adjusting the operating parameter of the first-level associated thread.
[0189] In some embodiments, the present disclosure provides a computer-readable storage medium storing an executable program, wherein the executable program, when executed by a processor, implements the method according to any one of the embodiments of the present disclosure.
[0190] Figure 5 FIG. is a block diagram of an electronic device 500 shown according to an exemplary embodiment. The method of the present disclosure can be applied to this electronic device.
[0191] For example, the electronic device 500 can be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, or a personal digital assistant, etc.
[0192] Referring to Figure 5 , the electronic device 500 may include one or more of the following components: a processing component 502, a memory 504, a power supply component 506, a multimedia component 508, an audio component 510, an input / output (I / O) interface 512, a sensor component 514, and a communication component 516.
[0193] The processing component 502 generally controls the overall operation of the electronic device 500, such as operations associated with at least one of display, telephone call, data communication, camera operation, and recording operation. The processing component 502 may include one or more processors 520 to execute instructions to complete all or part of the steps of the above method. In addition, the processing component 502 may include one or more modules to facilitate the interaction between the processing component 502 and other components. For example, the processing component 502 may include a multimedia module to facilitate the interaction between the multimedia component 508 and the processing component 502.
[0194] The memory 504 is configured to store various types of data to support the operation of the electronic device 500. Examples of such data include at least one of the following: instructions for any application or method operating on the electronic device 500, contact data, phone book data, messages, pictures, and videos. The memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disk.
[0195] The power supply component 506 provides power to various components of the electronic device 500. The power supply component 506 can include at least one of the following: a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 500.
[0196] The multimedia component 508 includes a screen that provides an output interface between the electronic device 500 and the user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operations. In some embodiments, the multimedia component 508 includes a front camera and / or a rear camera. When the electronic device 500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have focal length and optical zoom capabilities.
[0197] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC). When the electronic device 500 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive external audio signals. The received audio signals can be further stored in the memory 504 or transmitted via the communication component 516. In some embodiments, the audio component 510 further includes a speaker for outputting audio signals.
[0198] The I / O interface 512 provides an interface between the processing component 502 and a peripheral interface module, and the peripheral interface module can be a keyboard, a click wheel, buttons, etc. These buttons can include but are not limited to: a home button, a volume button, a power button, and a lock button.
[0199] The sensor component 514 includes one or more sensors for providing status assessments of various aspects of the electronic device 500. For example, the sensor component 514 can detect the on / off state of the electronic device 500, the relative positioning of components, such as the display and keypad of the electronic device 500. The sensor component 514 can also detect a change in the position of the electronic device 500 or a component of the electronic device 500, the presence or absence of user contact with the electronic device 500, the orientation or acceleration / deceleration of the electronic device 500, and the temperature change of the electronic device 500. The sensor component 514 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor component 514 can also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor component 514 can further include at least one of the following: an acceleration sensor, a gyro sensor, a magnetic sensor, a pressure sensor, and a temperature sensor.
[0200] The communication component 516 is configured to facilitate communication between the electronic device 500 and other devices in a wired or wireless manner. The electronic device 500 can access a communication standard-based wireless network, such as Wi-Fi, 4G, 5G, or a combination thereof. In an exemplary embodiment, the communication component 516 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra Wide Band (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0201] In an exemplary embodiment, the electronic device 500 can be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components.
[0202] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including executable instructions or a computer program, and the above instructions or computer program can be executed by a processor 520 of the electronic device 500 to complete the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a Random Access Memory (RAM), a Compact Disc Read-Only Memory (CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0203] A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute any one of the thread control methods in the above embodiments of the present disclosure. For example, the method includes:
[0204] When the target thread is in a blocked state, detect the lock-holding state and synchronization state of the target thread to obtain a first detection result;
[0205] When it is determined based on the first detection result that there is a first lock-holding thread holding a first target lock or a first synchronization thread associated with the target thread, determine the first lock-holding thread or the first synchronization thread as the first-level associated thread corresponding to the target thread; wherein, the first target lock is the target lock that the target thread is waiting for;
[0206] Adjust the running parameters of the first-level associated thread to reduce the time that the target thread is blocked.
[0207] An embodiment of the present disclosure provides a computer program product, which includes: a computer program or executable instructions, and the computer program or executable instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer program or executable instructions from the computer-readable storage medium, and the processor executes the computer program or executable instructions, so that the computer device executes any one of the above thread control methods of the embodiments of the present disclosure.
[0208] Those skilled in the art will readily think of other implementations of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure, which follow the general principles of the present disclosure and include well-known knowledge or conventional technical means in the technical field not disclosed in the present disclosure.
[0209] It should be understood that the present disclosure is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope.
Claims
1. A thread control method, characterized in that The method includes: When the target thread is in a blocked state, detecting the lock-holding state and synchronization state of the target thread to obtain a first detection result; When it is determined based on the first detection result that there is a first lock-holding thread holding a first target lock or a first synchronization thread associated with the target thread, determining the first lock-holding thread or the first synchronization thread as the first-level associated thread corresponding to the target thread; wherein, the first target lock is the target lock that the target thread is waiting for; Adjusting the running parameters of the first-level associated thread to reduce the blocked time of the target thread.
2. The thread control method according to claim 1, wherein The method further includes: After adjusting the running parameters of the first-level associated thread, if the first-level associated thread releases the first target lock or completes synchronization with the first synchronization thread, then running the target thread.
3. The thread control method according to claim 1, wherein The method further includes: After adjusting the running parameters of the first-level associated thread, if the first-level associated thread is in a blocked state, determining a second-level associated thread associated with the first-level associated thread; Adjusting the running parameters of the second-level associated thread, if the second-level associated thread is in a blocked state, determining a third-level associated thread associated with the second-level associated thread, until traversing the associated threads associated with the target thread.
4. The thread control method according to claim 3, wherein Among the associated threads associated with the target thread, the (N + 1)-th level associated thread includes: the (N + 1)-th lock-holding thread or the (N + 1)-th synchronization thread associated with the N-th level associated thread; the (N + 1)-th lock-holding thread holds the (N + 1)-th target lock that the N-th level associated thread is waiting for; N is a positive integer.
5. The thread control method according to claim 4, characterized in that, The method includes: After adjusting the running parameters of the (N + 1)-th level associated thread, if the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes synchronization with the (N + 1)-th synchronization thread, then running the N-th level associated thread; If the first-level associated thread releases the held first target lock or completes synchronization with the first synchronization thread, then running the target thread.
6. The thread control method according to any one of claims 4 or 5, characterized in that, The method further includes: Configuring a label for each determined level of associated thread; wherein, the label is used to identify the level corresponding to the associated thread; The adjusting of the running parameters of the first-level associated thread includes: When it is detected that there is a label corresponding to the first-level associated thread, adjusting the running parameters of the first-level associated thread; The adjusting of the running parameters of the second-level associated thread includes: When it is detected that there is a label corresponding to the second-level associated thread, adjusting the running parameters of the second-level associated thread.
7. The thread control method according to claim 6, characterized in that, The method further includes: If the (N + 1)-th level associated thread releases the held (N + 1)-th target lock and / or completes thread synchronization, then deleting the label corresponding to the (N + 1)-th level associated thread and canceling the set (N + 1)-th level associated thread; and / or If the first-level associated thread releases the held first target lock or completes thread synchronization, delete the tag corresponding to the first-level associated thread and cancel the set first-level associated thread.
8. The thread control method according to any one of claims 4 to 5, characterized in that The method further includes: If the (N + 1)-th level associated thread releases the held (N + 1)-th target lock or completes thread synchronization, adjust the running parameters of the (N + 1)-th level associated thread to the initial running parameters corresponding to the (N + 1)-th level associated thread; and / or If the first-level associated thread releases the held first target lock or completes thread synchronization, adjust the running parameters of the first-level associated thread to the initial running parameters corresponding to the first-level associated thread; wherein, the initial running parameters corresponding to the (N + 1)-th level associated thread are the running parameters corresponding to the (N + 1)-th level associated thread before adjusting the running parameters of the (N + 1)-th level associated thread; the initial running parameters corresponding to the first-level associated thread are the running parameters corresponding to the first-level associated thread before adjusting the running parameters of the first-level associated thread.
9. A thread control device, characterized in that, The apparatus includes: A detection module, configured to detect the lock-holding state and synchronization state of a target thread when the target thread is in a blocked state, and obtain a first detection result; A determination module, configured to determine the first lock-holding thread that holds the first target lock or the first synchronization thread associated with the target thread as the first-level associated thread corresponding to the target thread when it is determined based on the first detection result that there is such a thread; wherein, the first target lock is the target lock that the target thread is waiting for; An adjustment module, configured to adjust the running parameters of the first-level associated thread to reduce the blocked time of the target thread.
10. An electronic device, characterized in that, Includes: A processor; A memory for storing computer programs or instructions; wherein, the processor executes the computer programs or instructions to implement the steps of the thread control method according to any one of claims 1 to 8.
11. A non-transitory computer-readable storage medium storing a computer program or instructions, characterized in that, When the computer programs or instructions in the storage medium are executed by the processor, the steps of the thread control method according to any one of claims 1 to 8 are implemented.
12. A computer program product comprising a computer program or instructions, characterized in that, When the computer programs or instructions are executed by the processor, the steps of the thread control method according to any one of claims 1 to 8 are implemented.