An information processing method, apparatus, electronic device, storage medium, and product

CN122777286APending Publication Date: 2026-09-18BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510323388.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-18
Publication Date
2026-09-18

AI Technical Summary

Technical Problem

[0004]然而,主线程是应用的渲染进程,一旦被挂起将影响交互操作,进而导致卡顿问题

Benefits of technology

[0020] In this embodiment, when the current thread is the main thread, a trial method is used to acquire the lock. This trial method employs a non-blocking approach, attempting to acquire the lock without blocking the main thread if the lock is not acquired. This solves the problem of the main thread being suspended when it fails to acquire the lock. When the main thread fails to acquire the lock, a compensation flag is set to indicate that idle worker threads need to be woken up, thus compensating for the main thread's failure to acquire the lock and the resulting lack of wake-up of idle worker threads. If an idle worker thread is woken up, the compensation flag is cleared to indicate that the wake-up of the idle worker thread has been completed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122777286A_ABST
    Figure CN122777286A_ABST
Patent Text Reader

Abstract

This disclosure provides an information processing method, apparatus, electronic device, storage medium, and product. The information processing method includes, when the current thread is the main thread, acquiring a lock through an attempt method. The current thread includes the thread currently calling a notification method. The attempt method is a non-blocking method for attempting to acquire the lock. The notification method is a method for waking up blocked threads, including threads waiting to retrieve tasks from a task queue, where the task queue includes a blocking queue. If the main thread fails to acquire the lock, a compensation flag is set to indicate that idle worker threads need to be woken up. If an idle worker thread is woken up, the compensation flag is cleared. The main thread will not be blocked if it fails to acquire the lock. This solves the problem of the main thread being suspended when it fails to acquire the lock. Compensation is provided for situations where the main thread fails to acquire the lock and therefore does not wake up idle worker threads.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to computer technology, and more particularly to an information processing method, apparatus, electronic device, storage medium, and product. Background Technology

[0002] A thread pool is a mechanism for managing and reusing threads, and it is widely used in multithreaded development. When waking up a worker thread in a thread pool, a lock needs to be acquired; the lock is used to control the worker thread's acquisition of tasks.

[0003] In scenarios with many worker threads, lock contention can be extremely fierce. Once the main thread fails to acquire the lock, it will be suspended until it successfully acquires the lock resource again.

[0004] However, the main thread is the application's rendering process, and if it is suspended, it will affect interactive operations, leading to lag issues. Summary of the Invention

[0005] This disclosure provides an information processing method, apparatus, electronic device, storage medium, and product to prevent the main process from being suspended due to lock contention failure.

[0006] In a first aspect, embodiments of this disclosure provide an information processing method, including:

[0007] When the current thread is the main thread, the lock is acquired by trying a method. The current thread includes the thread currently calling the notification method. The trying method is a method that attempts to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to retrieve tasks from the task queue. The task queue includes a blocking queue.

[0008] In the event that the main thread fails to acquire the lock, a compensation flag is set to indicate that compensation is needed to wake up idle worker threads;

[0009] If an idle worker thread is awakened, the compensation flag information is cleared.

[0010] Secondly, embodiments of this disclosure also provide an information processing apparatus, including:

[0011] The acquisition module is used to acquire a lock by trying a method when the current thread is the main thread. The current thread includes the thread that is currently calling the notification method. The trying method is a method to try to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to get tasks from the task queue. The task queue includes a blocking queue.

[0012] The setting module is used to set compensation flag information to indicate that compensation is needed to wake up idle worker threads when the main thread fails to acquire the lock.

[0013] The clearing module is used to clear the compensation flag information when an idle worker thread is awakened.

[0014] Thirdly, embodiments of this disclosure also provide an electronic device, the electronic device comprising:

[0015] One or more processing devices;

[0016] Storage device for storing one or more programs.

[0017] When the one or more programs are executed by the one or more processing devices, the one or more processing devices perform the methods provided in the embodiments of this disclosure.

[0018] Fourthly, embodiments of this disclosure also provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the methods provided in embodiments of this disclosure.

[0019] Fifthly, embodiments of this disclosure also provide a computer program product, including a computer program that, when executed by a processor, implements the method provided according to embodiments of this disclosure.

[0020] In this embodiment, when the current thread is the main thread, a trial method is used to acquire the lock. This trial method employs a non-blocking approach, attempting to acquire the lock without blocking the main thread if the lock is not acquired. This solves the problem of the main thread being suspended when it fails to acquire the lock. When the main thread fails to acquire the lock, a compensation flag is set to indicate that idle worker threads need to be woken up, thus compensating for the main thread's failure to acquire the lock and the resulting lack of wake-up of idle worker threads. If an idle worker thread is woken up, the compensation flag is cleared to indicate that the wake-up of the idle worker thread has been completed. Attached Figure Description

[0021] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.

[0022] Figure 1 This is a flowchart illustrating an information processing method provided in an embodiment of this disclosure;

[0023] Figure 2This is a flowchart illustrating another information processing method provided in this embodiment of the present disclosure;

[0024] Figure 3 This is a schematic flowchart of another information processing method provided in the embodiments of this disclosure;

[0025] Figure 4 This is a schematic diagram of the structure of an information processing device provided in an embodiment of this disclosure;

[0026] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0027] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.

[0028] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.

[0029] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.

[0030] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.

[0031] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0032] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.

[0033] A thread pool is a multithreading technology that manages and reuses threads, improving thread efficiency and reducing the overhead of thread creation and destruction, thereby enhancing the overall system performance and responsiveness. Thread pools mainly consist of the following modules:

[0034] Task queue: Used to store tasks waiting to be executed. These tasks can be instances of classes that implement different interfaces. When a thread in the thread pool has an idle thread, it will retrieve a task from the task queue and execute it.

[0035] Thread pool manager: It is the core component of the thread pool, responsible for creating and destroying threads, managing the lifecycle of threads, and detecting the status of the thread pool.

[0036] Worker threads: These threads retrieve tasks from the task queue and execute them. The number of worker threads in a thread pool is usually limited to prevent the creation of too many threads from exhausting system resources. After completing a task, a worker thread will continue to retrieve the next task from the task queue until the thread pool is shut down or there are no more tasks to execute.

[0037] The task queue can be a blocking queue based on a linked list, with unlimited capacity. In a task enqueue scenario, if the previous task count is 0, it indicates that there may be idle worker threads waiting for new tasks to be enqueued. It's necessary to try waking up an idle worker thread to consume the task.

[0038] When waking up a worker thread, it is necessary to acquire a lock, such as takeLock, which is the lock that the worker thread uses to retrieve tasks.

[0039] In scenarios with many worker threads, contention for this lock can be extremely fierce, and if the main thread fails to acquire the lock, it will be suspended until it successfully acquires the lock resource again.

[0040] Because locks are equal, if dozens of worker threads compete with the main thread for the lock simultaneously, the main thread may continuously fail to win the competition in extreme cases. Furthermore, if the main thread is suspended for an extended period, it becomes unresponsive to user interactions, leading to stuttering and other issues.

[0041] To avoid the aforementioned problems, this disclosure suggests attempting to move the task submission action to a sub-thread. This avoids scenarios where the main thread is blocked, but it may result in issues such as delayed task submission.

[0042] Based on this, this disclosure provides an information processing method to avoid the problem of the main thread being suspended due to lock contention failure when submitting tasks to the task queue. Figure 1This is a flowchart illustrating an information processing method provided in an embodiment of this disclosure. This embodiment is applicable to scenarios where multiple threads acquire locks, specifically the case where the main thread acquires the lock. This method can be executed by an information processing device, which can be implemented in software and / or hardware. Optionally, it can be implemented by an electronic device, such as a mobile terminal, a PC, or a server.

[0043] like Figure 1 As shown, the method includes:

[0044] S110. If the current thread is the main thread, acquire the lock by trying different methods.

[0045] The current thread includes the thread currently calling the notification method. The attempt method is a method that attempts to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to retrieve tasks from the task queue. The task queue includes a blocking queue.

[0046] The notification method is called after a thread submits a task to the task queue. It is used to wake up threads that are waiting to retrieve a task from the queue. When a new task is added to the queue, the notification method is called to notify waiting threads that they can attempt to retrieve the task.

[0047] In this embodiment, the thread that calls the notification method is considered the current thread. The notification method can be called by the task-adding method. The task-adding method can be triggered by a thread. If the main thread has a task to execute, it submits the task to the task queue using the task-adding method. When the conditions for calling the notification method are met, the task-adding method (i.e., the task-adding method) calls the notification method; at this point, it can be considered that the main thread has called the notification method. Calling the notification method is intended to wake up waiting threads. These waiting threads can be worker threads that were previously dormant due to not having acquired a task, such as blocked threads. The conditions for calling the notification method are that the task-adding method successfully adds the task to the task queue and the task queue was empty before insertion.

[0048] In this disclosure, there can be multiple times when the lock is acquired, including when the worker thread retrieves a task, and when the main thread acquires the lock and wakes up the worker thread.

[0049] In this disclosure, the task queue can be a blocking queue. A blocking queue can trigger thread blocking when a task is enqueued or dequeued. When a thread submits or retrieves a task, it first acquires the lock. If the task queue's state does not meet the operation requirements (e.g., the queue is full or empty), the thread will wait, release the lock, and pause execution, entering a blocked state. When the queue state changes (e.g., another thread submits or retrieves a task) and the operation conditions are met, the waiting thread will be awakened, allowing it to reacquire the lock and continue execution.

[0050] Tasks can be submitted using the `task add` method, which adds a task to the task queue. If the task queue is full, the thread calling the `task add` method will be blocked. The `get` method can be used to remove a task from the task queue and return it. If the task queue is empty, the thread calling the `get` method will be blocked.

[0051] In this disclosure, the attempt method can be a method to try to acquire a lock. If the lock is not acquired by another thread, the lock can be acquired successfully; otherwise, the corresponding thread will not be blocked. This can avoid threads being blocked for a long time and improve the responsiveness of the program.

[0052] S120. If the main thread fails to acquire the lock, set a compensation flag to indicate that compensation is needed to wake up the idle worker thread.

[0053] A thread pool can be a pre-created and maintained collection (pool) of threads. When a task needs to be executed, an idle worker thread is obtained from the thread pool to perform the task. After the task is completed, the thread is not destroyed but returned to the thread pool to wait for the next task. This approach avoids the overhead of frequently creating and destroying threads, improving program performance. Worker threads are threads in the thread pool that retrieve tasks from the task queue and execute them; worker threads are threads managed internally by the thread pool.

[0054] The compensation flag can be considered as information used to indicate whether compensation is needed to wake up an idle worker thread. If the main thread fails to acquire the lock and cannot wake up an idle worker thread, the compensation flag can be set to indicate that compensation is needed to wake up an idle worker thread.

[0055] In this embodiment, the compensation flag information can be used to handle the problem of untimely thread scheduling that may occur due to the failure to acquire the lock. When the main thread fails to acquire the lock, it cannot wake up an idle worker thread. At this time, a compensation wake-up flag is set to indicate that an idle worker thread needs to be woken up, so that when subsequent conditions are met (such as a child thread triggering the wake-up of an idle worker thread, or the main thread triggering the wake-up of an idle worker thread after submitting other tasks), an idle worker thread can be woken up to compensate for the main thread's failure to wake up an idle worker thread due to the failure to acquire the lock. Therefore, when the main thread attempts to acquire the lock but fails, compensation flag information can be set to wake up an idle worker thread at a future time as compensation.

[0056] Furthermore, since the main thread uses an attempt method, it is not suspended if it fails to acquire the lock.

[0057] S130. If an idle worker thread is awakened, the compensation flag information is cleared.

[0058] This operation does not specify the method for waking up idle worker threads, such as waking them up through a child thread or waking them up by the main thread after submitting subsequent tasks. Once an idle worker thread is woken up, the compensation flag information can be cleared to avoid repeatedly waking up idle worker threads.

[0059] Clearing the compensation flag information can be done by removing or recharging the information used to identify idle worker threads that need to be woken up, so that it no longer has an identifying function, thus indicating that the idle worker thread has been woken up.

[0060] Once the worker thread is awakened, it can retrieve tasks from the task queue and execute them.

[0061] The technical solution of this disclosure, when the current thread is the main thread, uses a trial method to acquire the lock. This trial method attempts to acquire the lock in a non-blocking manner, and will not block the main thread if the lock is not acquired. This solves the problem of the main thread being suspended when it fails to acquire the lock. When the main thread fails to acquire the lock, a compensation flag is set to indicate that idle worker threads need to be woken up, thus compensating for the main thread's failure to acquire the lock and the resulting lack of wake-up of idle worker threads. If an idle worker thread is woken up, the compensation flag is cleared to indicate that the wake-up of the idle worker thread has been completed.

[0062] Based on the above embodiments, modified embodiments of the above embodiments are proposed. It should be noted that, in order to keep the description brief, only the differences from the above embodiments are described in the modified embodiments.

[0063] In one embodiment, when the current thread is the main thread, acquiring the lock by trying different methods includes:

[0064] In response to the task addition method triggered by the target thread, the corresponding task is added to the task queue;

[0065] When the notification method is called through the task addition method, the target thread is determined to be the current thread;

[0066] Determine whether the current thread is the main thread;

[0067] If so, acquire the lock using the trial method.

[0068] The target thread can be considered the thread that triggered the task add method. The target thread triggers the task add method to add the target thread's task to the task queue, waiting for execution.

[0069] This embodiment does not limit the timing of the call to the notification method by the task addition method. The notification method can be used to wake up threads that are waiting to retrieve tasks from the task queue. After the task addition method adds a task to the task queue, it calls the notification method to notify the waiting threads that they can retrieve the task. That is, after a task is added to the task queue, if there are threads waiting to retrieve tasks from the task queue, the notification method is called to wake up one or more waiting threads to retrieve tasks from the task queue.

[0070] The task queue can store tasks to be processed. In a multithreaded environment, threads that produce tasks add tasks to the task queue, and threads that consume tasks retrieve tasks from the task queue for execution.

[0071] In this embodiment, when the task addition method is triggered by the target thread and the notification method is called, the target thread is identified as the current thread. It is then determined whether the current thread is the main thread. If so, the main thread can use the attempt method to acquire the lock to avoid blocking the main thread.

[0072] In one embodiment, the number of threads in the thread pool where the worker thread resides is greater than a set value.

[0073] In this embodiment, the set value can be a pre-defined numerical value. If the number of threads in the thread pool exceeds the set value, it can be considered that there are too many threads in the thread pool. In this scenario, the number of worker threads in the thread pool will also be large. Many worker threads will compete with the main thread for the lock, thus increasing the probability that the main thread will be blocked. Therefore, in this scenario, the main thread uses a trial-and-error method to acquire the lock to avoid being suspended.

[0074] In one embodiment, clearing the compensation flag information when an idle worker thread is awakened includes:

[0075] If an idle worker thread is awakened, release the lock used for the wake-up and delete the compensation flag information.

[0076] In this embodiment, when an idle worker thread is awakened, the lock used to awaken that idle worker thread can be released. For example, if a thread, such as a child thread or the main thread, acquires the lock, it can wake up an idle worker thread. After the worker thread is awakened, the lock acquired by that thread will be released.

[0077] When an idle worker thread is awakened, this embodiment can delete the compensation flag information to achieve the clearing of the compensation flag information.

[0078] In one embodiment, the information processing method further includes:

[0079] If the main thread successfully acquires the lock, an idle worker thread is woken up.

[0080] In this embodiment, if the main thread successfully acquires the lock, an idle worker thread can be woken up. Once awakened, this worker thread can retrieve tasks from the task queue and execute them. After the idle worker thread is awakened, the compensation flag information will be cleared, and the lock will be released.

[0081] In one embodiment, the information processing method further includes:

[0082] When the current thread is a child thread, the lock is acquired using a blocking lock acquisition method;

[0083] If the lock is acquired, an idle worker thread is woken up.

[0084] A blocking lock acquisition method means that when a thread attempts to acquire a lock, if the lock is already held by another thread, the thread will enter a blocked state until the lock is released and the thread successfully acquires the lock before continuing its subsequent operations. This method ensures that a thread will not continue execution when it cannot acquire the lock, thereby avoiding data races and inconsistencies.

[0085] When the current thread is a child thread, it acquires the lock using a blocking method. If the lock is successfully acquired, the idle worker thread is awakened. If the lock is not acquired, it can remain in a blocked state.

[0086] In this embodiment, the child thread can use a blocking lock acquisition method when acquiring the lock. The main thread can use a trial method when acquiring the lock. It should be noted that, besides the main thread, other threads can also use the trial method to avoid entering a blocked state if they fail to acquire the lock. The settings for these other threads can be determined based on the actual situation. For example, they could be threads with higher priority for the operations being performed. The criteria for determining "higher priority" are not limited here; they can be defined by specific values.

[0087] Figure 2 This is a flowchart illustrating another information processing method provided in this embodiment. This embodiment also wakes up idle worker threads by setting up sub-thread compensation. For example... Figure 2 As shown, this embodiment includes the following steps:

[0088] S210. If the current thread is the main thread, acquire the lock by trying different methods.

[0089] S220. If the main thread fails to acquire the lock, set a compensation flag to indicate that compensation is needed to wake up the idle worker thread.

[0090] S230. Determine whether there is compensation flag information indicating that the idle worker thread needs to be woken up by setting a child thread. If yes, execute S240; otherwise, execute S250.

[0091] The child thread is designated as a thread corresponding to the main thread, specifically used to compensate for waking up idle worker threads.

[0092] There is no limitation on when the child thread is set to trigger the judgment to check whether there is a compensation flag indicating that compensation is needed to wake up idle worker threads; it can be a timed judgment.

[0093] The main thread can have a corresponding child thread. This child thread can parse the compensation flag information and determine whether compensation is needed to wake up an idle worker thread. If not, the operation ends without needing to wake it up through the child thread. If so, the child thread can be configured to trigger the wake-up of a worker thread.

[0094] A designated child thread can be used as a fallback to wake up an idle worker thread. An idle worker thread can be obtained by either a child thread other than the designated child thread or by the main thread. If no thread can wake up an idle worker thread, the designated child thread can be used as a fallback to do so.

[0095] S240, The child thread acquires the lock using the blocking method as specified, and then executes S260.

[0096] When a child thread determines that compensation flag information indicates the need to wake up an idle worker thread, it can trigger the waking up of an idle worker thread. To trigger the waking up of an idle worker thread, the child thread can first acquire the lock using a blocking lock acquisition method. After acquiring the lock, an idle worker thread can be woken up.

[0097] S250, End operation.

[0098] S260. If the lock is acquired, wake up an idle worker thread.

[0099] After a child thread acquires the lock, it can wake up an idle worker thread to achieve compensation.

[0100] S270. If an idle worker thread is awakened, the compensation flag information is cleared.

[0101] In this embodiment, the idle worker thread that is woken up is the designated child thread. After waking up, the compensation flag information is cleared to avoid repeated wake-ups.

[0102] In this embodiment, a child thread is set up to wake up idle worker threads, thus compensating for the lack of idle worker threads. The woken worker thread can then execute tasks, improving task execution efficiency.

[0103] The information processing method provided in this embodiment avoids delegating task submission from the main thread to child threads. While delegating task submission to child threads (i.e., asynchronous task submission) avoids the problem of contention by the main thread, it delays the timing of task submission. Since the main thread cannot know in advance whether it will fail to compete for the lock, it needs to delegate the submission of all tasks to child threads, resulting in delayed execution of all tasks and increased performance overhead.

[0104] This disclosure avoids the problem of the main thread being suspended for a long time due to lock contention failure when submitting tasks to the task queue without affecting the timing of task submission.

[0105] Figure 3 This is a schematic flowchart illustrating another information processing method provided in an embodiment of this disclosure. See also... Figure 3 The information processing methods include the following operations:

[0106] 1. The task addition method adds the task to the task queue and calls the notification method. The trigger thread for the task addition method can be the current thread. It checks whether the current thread is the main thread.

[0107] 2. In scenarios where the main thread is involved, use the attempt method to acquire the lock (the main thread will not be suspended if the lock acquisition fails);

[0108] 3. Determine whether the lock was successfully acquired. If the lock was acquired, wake up an idle thread, i.e. an idle worker thread, normally. After successfully waking up the thread, clear the compensation flag (i.e. clear the compensation flag information) and release the lock.

[0109] 4. If the lock is not acquired, mark the lock acquisition failure as requiring compensation and wake up an idle worker thread. A child thread is then configured to periodically check for compensation and wake-up; (this will not block the main thread's execution and will not affect the task submission timing).

[0110] 5. If the current thread is a child thread, use a blocking lock acquisition method to acquire the lock. After successfully acquiring the lock, wake up the idle thread, then clear the compensation flag and release the lock (the strategy of clearing the compensation flag reduces the problem of repeated wake-ups);

[0111] 6. After marking that a compensation wake-up is needed due to failure to acquire the lock, a child thread can be triggered periodically (e.g., every x milliseconds) to check if there is a compensation wake-up flag, i.e., to supplement wake-up information indicating that an idle worker thread needs to be woken up. If so, the lock is acquired using a blocking lock acquisition method, and an idle worker thread is woken up after the lock is acquired.

[0112] After the worker thread is woken up, it can acquire the lock using a blocking lock acquisition method. After acquiring the lock, it retrieves a task from the task queue and executes the acquired task.

[0113] After optimizing the lock for large thread pools (i.e., scenarios where the number of threads exceeds a set value), the problem of the main thread being suspended due to lock contention failure can be significantly reduced.

[0114] Figure 4 This is a schematic diagram of the structure of an information processing device provided in an embodiment of this disclosure, as shown below. Figure 4 As shown, the device includes:

[0115] The acquisition module 410 is used to acquire a lock by trying a method when the current thread is the main thread. The current thread includes the thread that is currently calling the notification method. The trying method is a method to try to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to get tasks from the task queue. The task queue includes a blocking queue.

[0116] Setting module 420 is used to set compensation flag information to indicate that compensation is needed to wake up idle worker threads when the main thread fails to acquire the lock;

[0117] The clearing module 430 is used to clear the compensation flag information when an idle worker thread is awakened.

[0118] The technical solution provided in this disclosure involves an acquisition module that, when the current thread is the main thread, uses a trial method to acquire the lock. This trial method employs a non-blocking approach, attempting to acquire the lock without blocking the main thread if the lock is not acquired. This solves the problem of the main thread being suspended when it fails to acquire the lock. The setting module, when the main thread fails to acquire the lock, sets a compensation flag to indicate that idle worker threads need to be woken up, thus compensating for the main thread's failure to acquire the lock and the resulting lack of wake-up of idle worker threads. The clearing module, when an idle worker thread is woken up, clears the compensation flag to indicate that the wake-up of the idle worker thread has been completed.

[0119] The information processing apparatus provided in this disclosure can execute the information processing method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects for executing the method.

[0120] In one embodiment, the acquisition module 410 is specifically used for:

[0121] In response to the task addition method triggered by the target thread, the corresponding task is added to the task queue;

[0122] When the notification method is called through the task addition method, the target thread is determined to be the current thread;

[0123] Determine whether the current thread is the main thread;

[0124] If so, acquire the lock using the trial method.

[0125] In one embodiment, the number of threads in the thread pool where the worker thread resides is greater than a set value.

[0126] In one embodiment, the clearing module 430 is specifically used for:

[0127] If an idle worker thread is awakened, release the lock used for the wake-up and delete the compensation flag information.

[0128] In one embodiment, the information processing apparatus further includes:

[0129] The compensation module is configured to: determine whether there is compensation flag information indicating that an idle worker thread needs to be woken up by setting a sub-thread, wherein the set sub-thread is a thread corresponding to the main thread dedicated to waking up idle worker threads for compensation; if so, acquire the lock by using the set sub-thread in a blocking manner; if the lock is acquired, wake up an idle worker thread.

[0130] In one embodiment, the information processing apparatus further includes a first wake-up module configured as follows:

[0131] If the main thread successfully acquires the lock, an idle worker thread is woken up.

[0132] In one embodiment, the information processing apparatus further includes a second wake-up module configured as follows:

[0133] When the current thread is a child thread, the lock is acquired using a blocking lock acquisition method;

[0134] If the lock is acquired, an idle worker thread is woken up.

[0135] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the protection scope of the embodiments of this disclosure.

[0136] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Refer to the following... Figure 5 It illustrates an electronic device suitable for implementing embodiments of the present disclosure (e.g., Figure 5 A structural diagram of the terminal device or server in the 500.

[0137] Electronic equipment 500, including:

[0138] One or more processing devices 501;

[0139] Storage device 508, for storing one or more programs,

[0140] When the one or more programs are executed by the one or more processing devices 501, the one or more processing devices 501 implement any of the methods provided in this disclosure.

[0141] The terminal devices in this disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (such as in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0142] like Figure 5As shown, electronic device 500 may include a processing unit (e.g., central processing unit, graphics processor, etc.) 501, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 502 or a program loaded from storage device 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of electronic device 500. The processing unit 501, ROM 502, and RAM 503 are interconnected via bus 504. An edit / output (I / O) interface 505 is also connected to bus 504.

[0143] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows electronic device 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 An electronic device 500 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0144] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, it performs the functions defined in the methods of embodiments of this disclosure.

[0145] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.

[0146] The electronic device provided in this embodiment and the information processing method provided in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.

[0147] This disclosure provides a computer storage medium storing a computer program that, when executed by a processor, implements the information processing method provided in the above embodiments.

[0148] It should be noted that the computer-readable medium described above in this disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination thereof.

[0149] The computer storage medium may be a storage medium for computer-executable instructions, which, when executed by a computer processor, are used to perform information processing methods as provided in this disclosure.

[0150] Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0151] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.

[0152] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0153] The aforementioned computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to: acquire a lock by means of an attempt method, wherein the current thread is the main thread, the current thread includes the thread currently calling the notification method, the attempt method is a method for attempting to acquire the lock in a non-blocking manner, the notification method is a method for waking up blocked threads, the blocked threads include threads waiting to retrieve tasks from a task queue, and the task queue includes a blocking queue;

[0154] In the event that the main thread fails to acquire the lock, a compensation flag is set to indicate that compensation is needed to wake up idle worker threads;

[0155] If an idle worker thread is awakened, the compensation flag information is cleared.

[0156] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including but not limited to object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0157] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0158] The modules or units described in the embodiments of this disclosure can be implemented in software or hardware. The names of modules or units do not necessarily limit the specific unit; for example, a clearing module can also be described as a "compensation marker information clearing module".

[0159] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.

[0160] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0161] A computer program product includes a computer program that, when executed by a processor, implements the information processing method provided in this disclosure. It possesses the corresponding functional modules and beneficial effects for implementing the method.

[0162] According to one or more embodiments of this disclosure, [Example 1] provides an information processing method, including:

[0163] When the current thread is the main thread, the lock is acquired by trying a method. The current thread includes the thread currently calling the notification method. The trying method is a method that attempts to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to retrieve tasks from the task queue. The task queue includes a blocking queue.

[0164] In the event that the main thread fails to acquire the lock, a compensation flag is set to indicate that compensation is needed to wake up idle worker threads;

[0165] If an idle worker thread is awakened, the compensation flag information is cleared.

[0166] According to one or more embodiments of this disclosure, [Example 2] provides the method described in Example 1, in which the lock is acquired by trying different methods when the current thread is the main thread, including:

[0167] In response to the task addition method triggered by the target thread, the corresponding task is added to the task queue;

[0168] When the notification method is called through the task addition method, the target thread is determined to be the current thread;

[0169] Determine whether the current thread is the main thread;

[0170] If so, acquire the lock using the trial method.

[0171] According to one or more embodiments of this disclosure, [Example 3] provides the method described in Example 1, wherein the number of threads in the thread pool where the worker thread resides is greater than a set value.

[0172] According to one or more embodiments of this disclosure, [Example 4] provides the method of Example 1, wherein clearing the compensation flag information when an idle worker thread is awakened includes:

[0173] If an idle worker thread is awakened, release the lock used for the wake-up and delete the compensation flag information.

[0174] According to one or more embodiments of this disclosure, Example 5 provides the method described in Example 1, further comprising:

[0175] The existence of a compensation flag indicating that an idle worker thread needs to be woken up is determined by setting a child thread. The set child thread is a thread corresponding to the main thread that is dedicated to waking up idle worker threads.

[0176] If so, the child thread acquires the lock using a blocking lock acquisition method as described above;

[0177] If the lock is acquired, an idle worker thread is woken up.

[0178] According to one or more embodiments of this disclosure, Example 6 provides the method of Example 1, further comprising:

[0179] If the main thread successfully acquires the lock, an idle worker thread is woken up.

[0180] According to one or more embodiments of this disclosure, Example 7 provides the method of Example 1, further comprising:

[0181] When the current thread is a child thread, the lock is acquired using a blocking lock acquisition method;

[0182] If the lock is acquired, an idle worker thread is woken up.

[0183] According to one or more embodiments of this disclosure, [Example 8] provides an information processing apparatus, including:

[0184] The acquisition module is used to acquire a lock by trying a method when the current thread is the main thread. The current thread includes the thread that is currently calling the notification method. The trying method is a method to try to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to get tasks from the task queue. The task queue includes a blocking queue.

[0185] The setting module is used to set compensation flag information to indicate that compensation is needed to wake up idle worker threads when the main thread fails to acquire the lock.

[0186] The clearing module is used to clear the compensation flag information when an idle worker thread is awakened.

[0187] According to one or more embodiments of this disclosure, [Example 9] an electronic device is provided, the electronic device comprising:

[0188] One or more processing devices;

[0189] Storage device for storing one or more programs.

[0190] When the one or more programs are executed by the one or more processing devices, the one or more processing devices perform the method as described in any of Examples 1-7.

[0191] According to one or more embodiments of this disclosure, [Example 10] provides a storage medium containing computer-executable instructions that, when executed by a computer processor, are used to perform the method described in any of Examples 1-7.

[0192] According to one or more embodiments of this disclosure, [Example 11] provides a computer program product including a computer program that, when executed by a processor, implements the method according to any one of Examples 1-7.

[0193] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

[0194] Furthermore, although the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. Multitasking and parallel processing may be advantageous in certain environments. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0195] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.

Claims

1. An information processing method, characterized in that, include: When the current thread is the main thread, the lock is acquired by trying a method. The current thread includes the thread currently calling the notification method. The trying method is a method that attempts to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to retrieve tasks from the task queue. The task queue includes a blocking queue. In the event that the main thread fails to acquire the lock, a compensation flag is set to indicate that compensation is needed to wake up idle worker threads; If an idle worker thread is awakened, the compensation flag information is cleared.

2. The method according to claim 1, characterized in that, When the current thread is the main thread, acquire the lock by trying different methods, including: In response to the task addition method triggered by the target thread, the corresponding task is added to the task queue; When the notification method is called through the task addition method, the target thread is determined to be the current thread; Determine whether the current thread is the main thread; If so, acquire the lock using the trial method.

3. The method according to claim 1, characterized in that, The number of threads in the thread pool where the worker thread resides is greater than a set value.

4. The method according to claim 1, characterized in that, The step of clearing the compensation flag information when an idle worker thread is awakened includes: If an idle worker thread is awakened, release the lock used for the wake-up and delete the compensation flag information.

5. The method according to claim 1, characterized in that, Also includes: The existence of a compensation flag indicating that an idle worker thread needs to be woken up is determined by setting a child thread. The set child thread is a thread corresponding to the main thread that is dedicated to waking up idle worker threads. If so, the child thread acquires the lock using a blocking method as described above; If the lock is acquired, an idle worker thread is woken up.

6. The method according to claim 1, characterized in that, Also includes: If the main thread successfully acquires the lock, an idle worker thread is woken up.

7. The method according to claim 1, characterized in that, Also includes: When the current thread is a child thread, the lock is acquired using a blocking lock acquisition method; If the lock is acquired, an idle worker thread is woken up.

8. An information processing device, characterized in that, include: The acquisition module is used to acquire a lock by trying a method when the current thread is the main thread. The current thread includes the thread that is currently calling the notification method. The trying method is a method to try to acquire the lock in a non-blocking manner. The notification method is a method used to wake up blocked threads. The blocked threads include threads waiting to get tasks from the task queue. The task queue includes a blocking queue. The setting module is used to set compensation flag information to indicate that compensation is needed to wake up idle worker threads when the main thread fails to acquire the lock. The clearing module is used to clear the compensation flag information when an idle worker thread is awakened.

9. An electronic device, characterized in that, The electronic device includes: One or more processing devices; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processing devices, the one or more processing devices perform the method as described in any one of claims 1-7.

10. A storage medium comprising computer-executable instructions, which, when executed by a computer processor, are used to perform the method as described in any one of claims 1-7.

11. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-7.