Multi-thread printing scheduling method and device, electronic equipment and storage medium

By using thread locks and ring queues in a multi-threaded environment, the problem of character interleaving and resource competition when multi-threaded simultaneous printing is solved, and efficient and stable multi-threaded printing scheduling is achieved.

CN120066433AActive Publication Date: 2025-05-30QIJING INFORMATION TECHNOLOGY (SHANGHAI) CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510550743.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-29
Publication Date
2025-05-30
Estimated Expiration
2045-04-29

AI Technical Summary

Technical Problem

In a multi-threaded environment, when multiple threads try to write print content to the serial port at the same time, it is easy to cause character interleaving, garbled code and resource competition problems, and each thread independently completes the printing process, which increases code complexity and reduces efficiency.

Method used

Lock the cache area through thread lock, allocate the string of the printed log to the cache area, and record its address information into the ring queue, and release the thread lock. The ring queue is accessed by an independent print thread, and the print log in the cache is obtained and sent to the target serial port.

Benefits of technology

It ensures the integrity and consistency of output information, avoids printing conflicts and garbled code problems, and improves the stability and printing efficiency of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066433A_ABST
    Figure CN120066433A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a multi-thread printing scheduling method and device, electronic equipment and a storage medium. According to the scheme, when any service thread outputs the printing log, the cache region is locked through the thread lock, the character string corresponding to the printing log is allocated to the cache region, the address information corresponding to the cache region is recorded into the annular queue, the thread lock is released, the address information in the annular queue is accessed through the printing thread, and the printing log is output through the printing thread. And obtaining the printing log in the cache region, and sending the printing log to the target serial port to complete the printing task. According to the embodiment of the invention, the printing tasks of different threads are subjected to cache management through a uniform interface, and the independent printing thread is responsible for actual output, so that not only is the integrity of output information ensured, but also the printing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of multi-threaded printing, and particularly to a multi-threaded printing scheduling method, device, electronic device, and storage medium. Background Art

[0002] In an embedded system and a multi-threaded application environment, the output of debugging information is a key link in system development and maintenance. Usually, multiple threads need to output their respective running states or log information through a shared debugging serial port. When the system executes some high-concurrency tasks such as printing tasks, multiple threads may simultaneously attempt to write data to the serial port. Currently, the serial port printing function of most multi-threaded systems still adopts a direct output method, that is, each thread directly sends the content to be printed to the specified serial port device in its internal logic.

[0003] Although this method is simple and easy to implement, it has many defects in practical applications. For example, when a thread has not completed the current printing task, another thread may have inserted its own printing content, resulting in character interleaving or garbled characters in the finally output information, which is difficult to interpret and analyze. At the same time, multiple threads accessing the serial port hardware simultaneously are also prone to resource competition problems. In addition, since each thread needs to independently complete the entire process from data splicing to serial port writing, the repeated operations not only increase the code complexity but also reduce the overall printing efficiency. Summary of the Invention

[0004] This application provides a multi-threaded printing scheduling method, device, electronic device, and storage medium, which can manage the caching of printing tasks of different threads through a unified interface and hand them over to an independent printing thread for actual output, not only ensuring the integrity of the output information but also improving the printing efficiency.

[0005] This application provides a multi-threaded printing scheduling method, including: When any business thread outputs a printing log, lock the buffer area through a thread lock; Allocate the string corresponding to the printing log to the buffer area, record the address information corresponding to the buffer area in a circular queue, and release the thread lock; Access the address information in the circular queue through a printing thread to obtain the printing log in the buffer area; Send the printing log to the target serial port to complete the printing task.

[0006] Optionally, the step of determining that a business thread outputs a printing log includes: When any business thread generates a log, obtain the printing level of the log and the identifier of the associated printing module; Judge whether the log meets the printing condition according to the printing level and the identifier; If so, determine that the log is a print log.

[0007] Optionally, the step of allocating the string corresponding to the print log to the buffer includes: Combine the original data of the print log with a preset format template to generate a complete log text; Allocate the string corresponding to the log text to the buffer and add print parameters.

[0008] Optionally, the step of allocating the string corresponding to the print log to the buffer includes: Determine the length of the string corresponding to the print log; Select an idle area from multiple pre-allocated buffer pools of different specifications according to the length to cache the string to the idle area.

[0009] Optionally, the step of accessing the address information in the circular queue by the printing thread includes: Initialize the buffer and the circular queue, and detect the status of the circular queue through the printing thread; When it is detected that the circular queue has the address information, lock the buffer again through the thread lock, and release the thread lock after the printing task is completed.

[0010] Optionally, the step of locking the buffer through the thread lock includes: Obtain the label information of the current business thread or printing thread; Lock the buffer by the thread lock according to the label information.

[0011] Optionally, the method further includes: When the circular queue contains multiple address information, determine the priority information of each of the multiple address information; Send multiple print logs to the target serial port in sequence according to the priority information.

[0012] This application also provides a multi-threaded printing scheduling device, including: An output module, configured to lock the buffer through a thread lock when any business thread outputs a print log; An allocation module, configured to allocate the string corresponding to the print log to the buffer, record the address information corresponding to the buffer in the circular queue, and release the thread lock; An acquisition module, configured to access the address information in the circular queue through a printing thread to obtain the print log in the buffer; A sending module, configured to send the printing log to a target serial port to complete a printing task.

[0013] This application also provides an electronic device, which includes a memory and a processor. A computer program is stored in the memory, and the processor executes the steps in any one of the multi-threaded printing scheduling methods provided by this application by calling the computer program stored in the memory.

[0014] This application also provides a storage medium, which stores a computer program. The computer program is suitable for being loaded by a processor to execute the steps in any one of the multi-threaded printing scheduling methods provided by this application.

[0015] The multi-threaded printing scheduling method provided by this application can, when any service thread outputs a printing log, lock the buffer area through a thread lock, allocate the string corresponding to the printing log to the buffer area, record the address information corresponding to the buffer area in a circular queue, and release the thread lock. The printing thread accesses the address information in the circular queue to obtain the printing log in the buffer area, and sends the printing log to the target serial port to complete the printing task. In the embodiments of this application, the printing tasks of different threads are managed in a unified interface through caching, and are handed over to an independent printing thread for actual output, which not only ensures the integrity of the output information, but also improves the printing efficiency. Description of the Drawings

[0016] To more clearly illustrate the technical solutions in this application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of this application. For those skilled in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0017] Figure 1 is a schematic flowchart of a multi-threaded printing scheduling method provided by an embodiment of this application; Figure 2 is another schematic flowchart of a multi-threaded printing scheduling method provided by an embodiment of this application; Figure 3 is a schematic structural diagram of a multi-threaded printing scheduling device provided by an embodiment of this application; Figure 4 is a schematic structural diagram of an electronic device provided by an embodiment of this application. Detailed Embodiments

[0018] Exemplary embodiments will be described in detail herein, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0019] It should be noted that in this document, the terms "including", "comprising", or any other variant thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device that includes a series of elements includes not only those elements but also other elements not expressly listed, or elements that are inherent to such process, method, article, or device. Without further limitation, an element defined by the phrase "including a..." does not exclude the existence of additional identical elements in the process, method, article, or device that includes the element. In addition, components, features, and elements with the same name in different embodiments of the present application may have the same meaning or different meanings, and their specific meanings need to be determined based on their interpretations in the specific embodiments or further in combination with the context of the specific embodiments.

[0020] It should be understood that although the steps in the flowcharts in the embodiments of the present application are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this document, the execution of these steps is not strictly limited in order and may be executed in other orders. Moreover, at least some of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time but may be executed at different times, and their execution order is not necessarily sequential but may be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.

[0021] It should be noted that in this document, step codes such as 101 and 102 are used. The purpose is to more clearly and briefly express the corresponding content and do not constitute a substantial limitation in order. Those skilled in the art may execute 102 first and then 101 during specific implementation, etc., but these should all be within the protection scope of the present application.

[0022] Referring to "embodiment" in this document means that a specific feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the present application. The occurrence of this phrase in various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein may be combined with other embodiments.

[0023] An embodiment of the present application provides a multi-threaded printing scheduling method. The execution entity of the multi-threaded printing scheduling method can be the multi-threaded printing scheduling device provided by the embodiment of the present application, or a server integrated with the multi-threaded printing scheduling device, where the multi-threaded printing scheduling device can be implemented in a hardware or software manner.

[0024] As Figure 1 shown, Figure 1 FIG. 1 is a first flowchart of the multi-threaded printing scheduling method provided by the embodiment of the present application. The specific process of the multi-threaded printing scheduling method can be as follows: 101. When any service thread outputs a print log, lock the buffer through a thread lock.

[0025] In an environment where multiple threads execute concurrently, multiple service threads can simultaneously attempt to output print logs. Without an effective protection mechanism, simultaneous access to the buffer by different threads will cause data competition problems. For example, if Thread A and Thread B write data to the buffer simultaneously, it will cause data to overwrite and be scrambled with each other, and finally the output print log will appear as garbled or error messages. In this embodiment, a thread lock is used to lock the buffer, just like adding a "lock" to the buffer. When a service thread obtains this "lock", other threads cannot access the buffer until the thread releases this "lock". This can ensure that at the same moment, only one thread can operate on the buffer, thereby ensuring the integrity and consistency of the buffer data, laying a foundation for accurately processing print logs subsequently, effectively avoiding common conflict problems when multiple threads operate on shared resources, and being a key step in realizing orderly printing scheduling. Compared with the traditional lock-free operation method, it greatly improves the reliability and stability of the system. It should be noted that in this embodiment, only the write operation to the buffer is locked, rather than a global lock, thereby reducing the probability of multi-thread contention.

[0026] In one embodiment, the above thread lock can be implemented using a lightweight spin lock (Spinlock) and a mutex lock (Mutex). For example, if the service thread is a real-time task, a spin lock can be used to avoid task delay caused by context switching. If the service thread is a non-real-time task, a mutex lock can be used to reduce the waste of CPU idle resources.

[0027] In one embodiment, the steps for determining the print log output by a service thread may include: when a log is generated by any service thread, obtaining the print level of the log and the identifier of the associated print module, and determining whether the log meets the print condition based on the print level and the identifier. If so, the log is determined to be a print log. Specifically, the print levels of the above-mentioned logs may include DEBUG (debugging), INFO (information), WARN (warning), ERROR (error), FATAL (fatal), etc. Different print levels correspond to different log contents. For example, logs at the DEBUG level usually contain a large amount of debugging information for troubleshooting problems during the development stage; while logs at the ERROR level record error information that occurs in the system. In addition, there are multiple different functional modules in the system, and each module generates corresponding logs. To distinguish the logs generated by different modules, a unique identifier is assigned to each print module.

[0028] Furthermore, different print level thresholds can be set according to the system configuration or operating environment. For example, in the development environment, the print level threshold can be set to DEBUG, so that all logs at the DEBUG level and above will be printed; while in the production environment, to reduce system overhead and the amount of logs, the threshold can be set to WARN, and only logs at the WARN level and above will be printed. In addition to the print level, the printing of logs can also be controlled according to the identifier of the print module. For example, in some cases, it may be only necessary to pay attention to the logs of specific modules. At this time, it can be set to only print the logs generated by these modules. By determining whether the identifier of the print module associated with the log is in the list of allowed print modules, it is determined whether the print module identifier condition is met. If the log meets the print condition after the above judgment, then the log is determined to be a print log.

[0029] 102. Allocate the string corresponding to the print log to the buffer area, record the address information corresponding to the buffer area in the circular queue, and release the thread lock.

[0030] In a multi-threaded system, the print log strings generated by each service thread need to be stored in the buffer area first and wait for subsequent processing by the print thread. The buffer area is a pre-allocated memory area that can avoid the blocking problem that occurs when directly printing logs, thereby improving the concurrency performance of the system. When a service thread obtains the access permission to the buffer area (the lock is successfully acquired), it will copy the print log string into the buffer area. When allocating, the size of the buffer area and the length of the log string can also be considered. If the buffer area is large enough, the log string can be directly copied into it; if it is not large enough, the log can be truncated or a larger buffer area can be re-allocated.

[0031] The circular queue belongs to a data structure that can recycle storage space. Its function is to record the address information of the buffer area, so that the printing thread can process the logs in these buffer areas sequentially. In this embodiment, after the log string is allocated to the buffer area, the business thread will record the address information of the buffer area at the tail of the circular queue. The circular queue manages the buffer area addresses according to the first-in-first-out (FIFO) principle, ensuring that the printing thread can process the logs in order and preventing out-of-order printing.

[0032] In one embodiment, after the allocation of the log string and the recording of the buffer area address information are completed, the business thread can release the thread lock it previously acquired. Releasing the thread lock means that other business threads now have the opportunity to acquire the lock and access the buffer area, which can improve the system's concurrent processing ability and ensure that the printing tasks of different threads can be queued in an orderly manner.

[0033] 103. Access the address information in the circular queue through the printing thread to obtain the printing logs in the buffer area.

[0034] In one embodiment, the printing thread is a thread dedicated to outputting the printing logs in the buffer area to the target serial port. It first accesses the circular queue, which records the address information of each buffer area. The printing thread sequentially obtains the addresses of the buffer areas according to the order of the address information in the queue. Through these addresses, the printing thread can accurately find the buffer area storing the printing logs. For example, the first address recorded in the circular queue points to the buffer area storing the printing logs of thread A, and the printing thread will read the logs from this buffer area according to this address. This method ensures that the printing thread can process the logs in the order of the submission of the printing tasks by the business thread, avoiding the problem of out-of-order printing. Different from the traditional multi-threaded independent printing method, this centralized printing thread processing method makes the execution of the printing tasks more orderly and efficient, reduces the chaos of the printing results, and improves the readability and analysis value of the debugging information.

[0035] In one embodiment, the printing thread will continuously execute the above steps, continuously obtain the address information from the circular queue, access the buffer area and obtain the printing logs until the circular queue is empty. When the circular queue is empty, the printing thread can enter the sleep state, wait for new log address information to be added to the circular queue, or check the queue again at a certain time interval.

[0036] 104. Send the printing logs to the target serial port to complete the printing task.

[0037] In one embodiment, after the printing thread obtains the printing log from the buffer, it will send it to the target serial port. During the sending process, it is necessary to follow the relevant protocols and specifications of serial communication to ensure that the data can be transmitted to the serial device accurately and without error. For example, serial communication may involve setting parameters such as baud rate, data bits, and stop bits. The printing thread will format the printing log according to these parameters and then send the data bit by bit. After successfully sending the printing log to the target serial port, a complete printing task is completed. In this way, the complete process from the business thread generating the printing log to the final output on the serial device is realized. The whole process is uniformly scheduled and managed, effectively avoiding problems such as printing conflicts and garbled codes in the traditional method, improving the stability and printing efficiency of the system, and meeting the high requirements of the multi-threaded system for printing scheduling in a complex environment.

[0038] In one embodiment, when there are multiple address information in the circular queue, the priority information of each address information can also be determined, and then multiple printing logs are sent to the target serial port in sequence according to the priority information. Specifically, in the actual application scenario, the printing logs generated by different services may have different importance. For example, system error logs are usually more important than general debugging logs. When there are multiple address information in the circular queue, it is necessary to determine the priority for the printing log corresponding to each address. For example, when the business thread stores the log in the buffer, the priority information of the log is recorded in the circular queue together with the address information, or the priority is dynamically determined according to predefined rules such as the type and source module of the printing log. Next, after sorting these address information according to the priority, the printing thread can access the buffer in sequence according to the sorted address information order, obtain the corresponding printing log, and send it to the target serial port. This can ensure that important logs can be output in time and avoid being blocked by low-priority logs.

[0039] In summary, the multi-threaded printing scheduling method proposed in the embodiment of the present application can, when any business thread outputs a printing log, lock the buffer through a thread lock, allocate the string corresponding to the printing log to the buffer, record the address information corresponding to the buffer in the circular queue, and release the thread lock. The printing thread accesses the address information in the circular queue to obtain the printing log in the buffer and sends the printing log to the target serial port to complete the printing task. The embodiment of the present application manages the printing tasks of different threads through a unified interface for caching and hands them over to an independent printing thread for actual output, which not only ensures the integrity of the output information but also improves the printing efficiency.

[0040] According to the method described in the previous embodiments, the following will be further described in detail.

[0041] Please refer to Figure 2, Figure 2 This is the second schematic flowchart of the multi-threaded printing scheduling method provided by the embodiments of this application. The method includes: 201. When any business thread outputs a printing log, lock the buffer area through a thread lock.

[0042] In one embodiment, in a multi-threaded environment, multiple business threads may attempt to operate on the buffer area simultaneously. To avoid data competition and inconsistency issues, a thread lock is needed to ensure that only one thread can access the buffer area at the same time. When a certain business thread wants to output a printing log, it will first acquire the thread lock, so that other threads must wait for the thread to release the lock before they can access the buffer area, thus ensuring the integrity of the buffer area data.

[0043] 202. Combine the original data of the printing log with a preset format template to generate a complete log text.

[0044] Among them, the original data of the printing log contains key information. To make the log more readable and standardized, there is usually a preset format template. For example, the format template can stipulate that the log should contain information such as a timestamp, a log level, and a thread name. Combining the original data with the format template can generate a complete log text that meets specific format requirements. Such a log will be more convenient for subsequent viewing and analysis.

[0045] 203. Determine the length of the string corresponding to the printing log.

[0046] Among them, the length of the log string is crucial for subsequent buffer area allocation. Log strings of different lengths require different sizes of buffer spaces to store. By determining the length of the string, a basis can be provided for selecting a suitable buffer area.

[0047] 204. Select an idle area from multiple pre-allocated buffer pools of different specifications according to the length, so as to cache the string in the idle area and add printing parameters.

[0048] In one embodiment, to improve the utilization efficiency of the buffer area, multiple buffer pools of different specifications can also be pre-allocated. Each buffer pool contains multiple buffer areas of the same size. According to the length of the log string determined in the above steps, select an idle area of a suitable size from these buffer pools. Store the generated log string in this idle area, and at the same time add printing parameters such as printing speed and font. This can ensure that each log can be stored in a buffer area of a suitable size, avoiding waste or insufficiency caused by using too large or too small buffer spaces.

[0049] 205. Record the address information corresponding to the buffer area in the circular queue and release the thread lock.

[0050] In one embodiment, after caching the log string in the free area and adding the printing parameters, the address information of the buffer can be recorded in the circular queue. The circular queue can manage the buffer addresses in the order in which the logs enter. Then, release the thread lock obtained previously so that other business threads can continue to access the buffer.

[0051] 206. Access the address information in the circular queue through the printing thread to obtain the printing logs in the buffer.

[0052] In one embodiment, the step of accessing the address information in the circular queue through the printing thread may include: initializing the buffer and the circular queue, and detecting the state of the circular queue through the printing thread. When it is detected that there is address information in the circular queue, lock the buffer again through the thread lock, and release the thread lock after completing the printing task. Among them, initializing the buffer means allocating a certain amount of memory space for it and setting its initial state to free or unused. When initializing the circular queue, it is necessary to determine its maximum capacity and set the initial state of the queue to empty. After the printing thread is started, the printing thread can implement state detection by periodically checking the length of the circular queue or whether it is empty. If the circular queue is empty, the printing thread can enter the sleep state or wait briefly to reduce the consumption of CPU resources. When the printing thread detects that there is address information in the circular queue, it indicates that a business thread has already stored the printing logs in the buffer and recorded the address information of the buffer in the circular queue. To ensure that no other business thread modifies the buffer simultaneously when the printing thread accesses the buffer, it is necessary to lock the buffer again using the thread lock and release the previously obtained thread lock after completing the printing task. After releasing the thread lock, other business threads can access the buffer again and continue to store new printing logs in the buffer.

[0053] In one embodiment, the step of locking the buffer through a thread lock may include: obtaining the tag information of the current business thread or printing thread, and using the thread lock to lock the buffer according to the tag information. Specifically, in a multi-threaded environment, there are business threads and printing threads. The business threads are responsible for generating printing logs, and the printing threads are responsible for outputting the logs in the buffer to the target serial port. When a certain thread (business thread or printing thread) needs to operate on the buffer, it first needs to obtain its own tag information. This tag information can be the name, ID of the thread, or other custom identifiers. For example, in an e-commerce system, business threads can include user business threads, order business threads, etc., and the printing thread is specifically responsible for printing various types of logs. After obtaining the tag information of the thread, it will determine how to use the thread lock to lock the buffer based on this information. Among them, different types of threads may have different priorities or restrictions on the operation of the buffer. Through the tag information, the thread lock can perform differential locking processing according to the thread type. For example, the printing thread needs to obtain the access right of the buffer first because it is responsible for outputting the logs to the target serial port in a timely manner. When the printing thread requests to lock, the thread lock can respond preferentially; for business threads, they may need to obtain the lock when the printing thread is idle.

[0054] 207. Send the printing log and printing parameters to the target serial port to complete the printing task.

[0055] After the printing thread obtains the printing log in the buffer, it will send the log and printing parameters to the target serial port to complete the printing task. After completing the printing task, it is necessary to release the previously obtained thread lock. After releasing the thread lock, other business threads can access the buffer again and continue to store new printing logs in the buffer. This can ensure the concurrency performance of the system, enabling multiple threads to alternately operate on the buffer.

[0056] As described above, the multi-threaded printing scheduling method proposed in the embodiment of the present application can, when any business thread outputs a printing log, lock the buffer through a thread lock, combine the original data of the printing log with a preset format template to generate a complete log text, determine the length of the string corresponding to the printing log, select an idle area from multiple pre-allocated buffer pools of different specifications according to the length to cache the string in the idle area, add printing parameters, record the address information corresponding to the buffer in the circular queue, and release the thread lock. The printing thread accesses the address information in the circular queue to obtain the printing log in the buffer, and sends the printing log and printing parameters to the target serial port to complete the printing task. The embodiment of the present application manages the caching of the printing tasks of different threads through a unified interface and hands it over to an independent printing thread for actual output, which not only ensures the integrity of the output information but also improves the printing efficiency.

[0057] To implement the above method, an embodiment of the present application further provides a multi-threaded printing scheduling device, which can be specifically integrated into terminal devices such as mobile phones and tablet computers.

[0058] For example, as Figure 3 shown, it is a schematic structural diagram of a multi-threaded printing scheduling device provided by an embodiment of the present application. The multi-threaded printing scheduling device may include: An output module 301, configured to lock the buffer through a thread lock when any service thread outputs a print log; An allocation module 302, configured to allocate the string corresponding to the print log to the buffer, record the address information corresponding to the buffer in a circular queue, and release the thread lock; An acquisition module 303, configured to access the address information in the circular queue through a printing thread to acquire the print log in the buffer; A sending module 304, configured to send the print log to a target serial port to complete a printing task.

[0059] As can be seen from the above, the multi-threaded printing scheduling device proposed by the embodiment of the present application can lock the buffer through a thread lock when any service thread outputs a print log, allocate the string corresponding to the print log to the buffer, record the address information corresponding to the buffer in a circular queue, and release the thread lock, access the address information in the circular queue through a printing thread to acquire the print log in the buffer, and send the print log to a target serial port to complete a printing task. The embodiment of the present application manages the printing tasks of different threads through a unified interface for caching and hands them over to an independent printing thread to be responsible for actual output, which not only ensures the integrity of the output information but also improves the printing efficiency.

[0060] All the above technical solutions can be combined arbitrarily to form optional embodiments of the present application, which will not be elaborated here one by one.

[0061] Those of ordinary skill in the art can understand that all or part of the steps in the above various methods can be completed through instructions or by controlling related hardware through instructions. The instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0062] Therefore, an embodiment of the present application provides a computer-readable storage medium, in which multiple computer programs are stored. The computer programs can be loaded by a processor to execute the steps in any one of the multi-threaded printing scheduling methods provided by the embodiment of the present application. For example, the computer program can execute the following steps: When any service thread outputs a print log, lock the buffer through a thread lock; Allocate the string corresponding to the print log to a buffer area, record the address information corresponding to the buffer area in a circular queue, and release the thread lock; Access the address information in the circular queue through a printing thread to obtain the print log in the buffer area; Send the print log to a target serial port to complete a printing task.

[0063] For the specific implementation of each of the above operations, reference may be made to the previous embodiments and will not be elaborated herein.

[0064] Among them, the storage medium may include: read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disc, etc.

[0065] Since the computer program stored in the storage medium can execute the steps in any of the multi-threaded printing scheduling methods provided by the embodiments of the present application, the beneficial effects achievable by any of the multi-threaded printing scheduling methods provided by the embodiments of the present application can be realized. For details, reference may be made to the previous embodiments and will not be elaborated herein.

[0066] The embodiments of the present application further provide an electronic device, including a memory and a processor. The memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, so that the device equipped with the chip executes the methods in the above various possible implementation manners.

[0067] For example, the above computer device may be a terminal device with corresponding functions such as a mobile phone, a tablet computer, a personal computer, a cloud computer, etc. Please refer to Figure 4 , Figure 4 which is a schematic structural diagram of a computer provided by the embodiments of the present application.

[0068] The computer device 400 may include components such as a memory 401 and a processor 402. Those skilled in the art can understand that Figure 4 the structural diagram of the computer device shown in

[0069] does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0070] The processor 402 is the control center of the computer device, connecting various parts of the entire computer device through various interfaces and circuits. By running or executing application programs stored in the memory 401 and calling data stored in the memory 401, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole.

[0071] In this embodiment, the processor 402 in the computer device will load the executable code corresponding to the processes of one or more application programs into the memory 401 according to the following instructions, and the processor 402 will run the application programs stored in the memory 401 to execute: When any service thread outputs a print log, lock the buffer through a thread lock; Allocate the string corresponding to the print log to the buffer, record the address information corresponding to the buffer in the circular queue, and release the thread lock; Access the address information in the circular queue through the print thread to obtain the print log in the buffer; Send the print log to the target serial port to complete the printing task.

[0072] It can be understood that the above scenarios are only examples and do not constitute a limitation on the application scenarios of the technical solutions provided in the embodiments of the present application. The technical solutions of the present application can also be applied to other scenarios. For example, as known to those of ordinary skill in the art, with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are equally applicable to similar technical problems.

[0073] The steps in the method of the embodiments of the present application can be adjusted, combined, and deleted according to actual needs. The modules in the devices of the embodiments of the present application can be combined, divided, and deleted according to actual needs.

[0074] In the present application, for the description of the same or similar term concepts, technical solutions, and / or application scenarios, generally only a detailed description is given when it appears for the first time. When it appears repeatedly later, for the sake of brevity, it is generally not described again. When understanding the technical solutions and other contents of the present application, for the same or similar term concepts, technical solutions, and / or application scenarios that are not described in detail later, reference can be made to the relevant detailed descriptions before.

[0075] In the present application, the descriptions of each embodiment have their own emphases. For parts not described or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0076] The technical features of the technical solution of this application can be combined arbitrarily. For the sake of concise description, not all possible combinations of the various technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered to be within the scope recorded in this application.

[0077] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of this application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, storage disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk Solid State Disk), etc.

[0078] The above has introduced in detail a multi-threaded printing scheduling method, device, electronic device, and storage medium provided by the embodiments of this application. Specific examples are used in this article to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those skilled in the art, according to the idea of this application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to this invention.

Claims

1. A multi-threaded printing scheduling method, characterized in that: include: When any business thread outputs a print log, the buffer area is locked through a thread lock; Allocate the character string corresponding to the print log to a buffer area, record the address information corresponding to the buffer area into a ring queue, and release the thread lock; Accessing the address information in the circular queue through the printing thread to obtain the printing log in the buffer area; The print log is sent to the target serial port to complete the print task.

2. The multi-threaded printing scheduling method according to claim 1, characterized in that: The steps for determining the business thread to output the print log include: When any business thread generates a log, obtain the print level of the log and the identifier of the associated print module; Determining whether the log meets the printing condition according to the printing level and the identifier; If so, it is determined that the log is a print log.

3. The multi-threaded printing scheduling method according to claim 1, characterized in that: The step of allocating the character string corresponding to the print log to the buffer area comprises: Combining the original data of the printed log with a preset format template to generate a complete log text; The character string corresponding to the log text is allocated to the buffer area, and printing parameters are added.

4. The multi-threaded printing scheduling method according to claim 1, characterized in that: The step of allocating the character string corresponding to the print log to the buffer area comprises: Determine the length of the string corresponding to the print log; A free area is selected from a plurality of pre-allocated buffer pools of different specifications according to the length, so as to cache the character string in the free area.

5. The multi-threaded printing scheduling method according to claim 1, characterized in that: The step of accessing the address information in the circular queue through the printing thread comprises: Initializing the buffer area and the circular queue, and detecting the state of the circular queue through a printing thread; When it is detected that the ring queue has the address information, the buffer area is locked again by a thread lock, and the thread lock is released after the printing task is completed.

6. The multi-threaded printing scheduling method according to any one of claims 1 to 5, characterized in that: The steps of locking the cache area through a thread lock include: Get the label information of the current business thread or printing thread; The thread lock is enabled to lock the cache area according to the tag information.

7. The multi-threaded printing scheduling method according to any one of claims 1 to 5, characterized in that: The method further comprises: When the ring queue contains multiple address information, determining priority information of each of the multiple address information; The plurality of print logs are sent to the target serial port in sequence according to the priority information.

8. A multi-threaded printing scheduling device, characterized in that: include: The output module is used to lock the buffer area through the thread lock when any business thread outputs the print log; An allocation module, used for allocating the character string corresponding to the print log to a buffer area, recording the address information corresponding to the buffer area into a circular queue, and releasing the thread lock; An acquisition module, used for accessing the address information in the circular queue through a printing thread to obtain the printing log in the buffer area; The sending module is used to send the printing log to the target serial port to complete the printing task.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein a computer program is stored in the memory, and the processor executes the steps in the multi-threaded printing scheduling method according to any one of claims 1 to 7 by calling the computer program stored in the memory.

10. A storage medium, characterized in that: The storage medium stores a computer program, and the computer program is suitable for being loaded by a processor to execute the steps in the multi-threaded printing scheduling method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Multi-thread log output method and device

    CN108205476A

  • Log processing method and terminal equipment

    CN112306980A

  • Data caching device and method and electronic equipment

    CN115757305A

  • Asynchronous log processing method for naked run program of relay protection device

    CN116048914A

  • Driver log management method, device and system, electronic equipment and storage medium

    CN117407249A