Printing implementation method and system of production consumer buffer area based on shared memory

By implementing a synchronization mechanism and optimizing the buffer within the producer-consumer buffer, the problem of chaotic printing data under multi-process concurrency was solved, achieving the integrity and orderly transmission of printing data, and improving the accuracy of anomaly monitoring and data transmission efficiency.

CN121858049APending Publication Date: 2026-04-14SICON CHAT UNION ELECTRIC CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-11
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

When multiple processes or threads write print data to the output terminal simultaneously, the lack of an effective synchronization mechanism causes information fragments to interweave and overwrite each other, destroying the readability of real-time print data and affecting the remote monitoring platform's accurate identification of equipment operating status and fault prompts.

Method used

A producer-consumer buffer mechanism based on shared memory is adopted. After the producer completes the data import, it releases the mutex semaphore and updates the full semaphore to ensure the integrity and order of the printed data. Furthermore, the buffer partitioning strategy is optimized by predicting the import information to reduce data chaos and missing data.

Benefits of technology

It improves the integrity and orderliness of printed data, reduces data disorder or missing data, enhances the accuracy of anomaly monitoring results, ensures data is quickly transmitted to the security monitoring stage, and reduces the risk of misjudgment or omission due to data distortion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121858049A_ABST
    Figure CN121858049A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of printing strategy optimization, in particular to a printing implementation method and system for a production consumer buffer area based on a shared memory, and the method comprises the steps: obtaining the import information provided by a target producer, and updating the semaphore information corresponding to the production consumer buffer area based on the import information, the import information comprises to-be-imported printing data and a to-be-imported buffer space, and the to-be-imported buffer space is a buffer space in a production consumer buffer area; when it is detected that the import information is imported, the mutual exclusion semaphore is restored, and the consumer is reminded to read the imported printing data from the production consumer buffer area based on the updated full semaphore; and real-time safety monitoring analysis is carried out based on the imported printing data. According to the method, the import integrity of the printing data can be improved, so that the accuracy of the abnormal monitoring result is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of printing strategy optimization technology, and in particular to a printing implementation method and system based on a shared memory producer-consumer buffer. Background Technology

[0002] Driven by societal development needs and the growing trend of the new energy industry, embedded devices are becoming increasingly common. During long-term field operation, these devices may experience numerous anomalies or require regular maintenance. Currently, the primary method for identifying the source of problems is by retrieving logs. However, real-time print data during program execution provides a more accurate reflection of the actual situation. Therefore, there is an urgent need to upload real-time print data to a remote location as required for immediate monitoring and analysis, enabling remote maintenance and monitoring.

[0003] However, when multiple processes or threads write print data to the output terminal at the same time, the lack of an effective synchronization mechanism may cause information fragments from different sources to interweave and overwrite each other. This kind of data chaos not only seriously damages the readability of real-time print data, but may also cause the remote monitoring platform to fail to accurately identify the device's operating status or miss the real fault prompts, ultimately increasing the difficulty of anomaly monitoring and even delaying the time for fault handling, which is seriously out of touch with the needs of remote real-time operation and maintenance. Summary of the Invention

[0004] To improve the integrity of imported print data and thus enhance the accuracy of anomaly monitoring results, this application provides a printing implementation method and system based on a shared memory producer-consumer buffer.

[0005] Firstly, this application provides a printing implementation method for a producer-consumer buffer based on shared memory, employing the following technical solution: A method for printing producer-consumer buffers based on shared memory includes: Obtain import information provided by the target producer, and update the semaphore information corresponding to the producer-consumer buffer based on the import information. The import information includes the data to be imported and the buffer space to be imported. The buffer space to be imported is the buffer space within the producer-consumer buffer. Once the import information is detected to be complete, the mutex semaphore is restored, and the consumer is reminded to read the imported print data from the producer-consumer buffer based on the updated full semaphore. Real-time security monitoring and analysis are performed based on the imported print data.

[0006] By adopting the above technical solution, by requesting corresponding buffer space in the producer-consumer buffer and releasing the mutex semaphore and updating the full semaphore only after the printing data to be imported is written, it is easy to ensure that a single piece of printing data to be imported is not interrupted or overwritten by other producers during the import process. That is, it avoids the problem of information fragmentation and interleaving chaos caused by multi-process concurrent import from the root, thus ensuring the integrity and order of the printing data to be imported. By establishing a real-time linkage mechanism between producer import and consumer reading, it is easy to trigger the consumer's reading action immediately after the producer completes the data import, thus avoiding the delay of imported data in the producer-consumer buffer. This ensures that the printing data can be quickly transmitted to the subsequent security monitoring stage. By reducing the occurrence of data chaos or missing data during the import and reading process, it is easy to reduce the misjudgment or missed judgment caused by data distortion, thus improving the accuracy of anomaly monitoring results.

[0007] In one possible implementation, before updating the semaphore information corresponding to the producer-consumer buffer based on the imported information, the method further includes: Obtain historical import information corresponding to a preset analysis time period, and determine the predicted import information corresponding to a preset prediction time period based on the historical import information. The historical import information includes historical import print data and the amount of historical import data corresponding to each historical import print data. Based on the predicted import information, a buffer partitioning strategy is determined, and the producer-consumer buffer is spatially partitioned based on the buffer partitioning strategy to obtain multiple buffer spaces.

[0008] By adopting the above technical solution, historical import information for a preset analysis period is obtained and predicted import information for a preset prediction period is determined accordingly. This facilitates the prediction of the import characteristics of print data that needs to be imported in the future based on historical import patterns. The buffer partitioning strategy is determined based on the prediction results, which helps to avoid the buffer partitioning from deviating from actual data needs. By formulating a buffer partitioning strategy based on the predicted import information and dividing multiple buffer spaces, the space allocation of the producer and consumer buffers can be accurately matched with the predicted print data import needs.

[0009] One possible implementation also includes: Obtain the actual imported data volume of each buffer space within the producer-consumer buffer during the preset prediction time period, and determine the space idle rate of each buffer space based on the allocated data volume and the actual imported data volume corresponding to each buffer space. The space idle rate curve is determined based on the space idle rate corresponding to each buffer space and the buffer position of each buffer space in the producer-consumer buffer. Idle peaks and idle peak positions are identified from the space idle rate curve based on a preset peak threshold, and idle buffer segments are determined based on each idle peak and idle peak position. Identify the idle rate fluctuation data corresponding to the idle buffer segment from the idle rate curve, and determine the circular buffer parameters corresponding to the idle buffer segment based on the idle rate fluctuation data; Based on the idle buffer segment and the circular buffer parameters, optimize the buffer partitioning strategy corresponding to the next preset prediction time period.

[0010] By adopting the above technical solution, and by obtaining the actual imported data volume of each buffer space within a preset prediction time period, and calculating the space idle rate in conjunction with the allocated data volume, it is easy to accurately identify the resource utilization efficiency of the buffer space, and precisely avoid long-term resource waste caused by the rigidity of the initial partitioning strategy. By generating a space idle rate curve in conjunction with each buffer location, it is easy to intuitively present the overall idle distribution characteristics of the buffer zone, providing a visual basis for accurately locating inefficient spaces. In addition, by analyzing the idle peak and corresponding position in the space idle rate curve and determining the idle buffer segment, it is easy to focus on the continuous spatial area with the most prominent resource waste, and avoid... The handling of scattered idle space involves extracting idle rate fluctuation data of idle buffer segments and determining the parameters of the circular buffer to improve the compatibility of the newly configured circular buffer with the actual import needs of the idle buffer segment. This facilitates the improvement of resource utilization of the idle buffer segment. Finally, based on the parameters of the idle buffer segment and the circular buffer, the spatial partitioning strategy corresponding to the next preset prediction time period is optimized, so that the buffer space allocation can continuously adapt to the actual import pattern of the printed data. This ensures the continuity of data import while minimizing memory resource idleness, providing dynamically adapted spatial support for the efficient operation of the producer-consumer model.

[0011] In one possible implementation, when the number of producers is at least two, the process of determining the target producer includes: Obtain the application import information for each producer, which includes the application timestamp and import information; The application order of all producers is sorted according to the application timestamp to obtain an initial sorted list; Identify the imported data features contained in each imported message, and determine the data importance level corresponding to each imported message based on the preset data importance level mapping relationship; Based on the data importance level of each imported information, the sorting position of the corresponding producer in the initial sorting list is adjusted to obtain the target sorting list; The target producer is determined based on the target sorting list.

[0012] By adopting the above technical solution, the application import information of each producer, which includes the application timestamp and import information, is obtained. This provides a dual basis for judging the scheduling of multiple producers based on both time sequence and data attributes, avoiding priority imbalance caused by single-dimensional scheduling. First, an initial sorting list is generated based on the application timestamp to ensure the basic fairness of multiple producer applications and prevent some producers from being ignored due to long queues. Then, by identifying the data importance level of each import information, it is easy to accurately distinguish the priority of different application import information. This solves the problem that the traditional first-come, first-served strategy cannot adapt to the urgency of critical data, and facilitates the synergy between time fairness and importance priority. This makes it easier to ensure the import order of printed data and the timeliness of critical data in a multi-producer environment.

[0013] In one possible implementation, the step of alerting the consumer to read imported print data from the producer-consumer buffer based on the updated full semaphore includes: When the updated full semaphore is greater than 0, obtain the current read pointer corresponding to the producer-consumer buffer; A consumption prompt instruction is generated based on the current read pointer. The consumption prompt instruction is used to remind the consumer to read the import print data corresponding to the read pointer from the producer-consumer buffer.

[0014] By adopting the above technical solution, subsequent read reminder actions are only triggered when the updated full semaphore is greater than 0, which helps to avoid consumers making invalid read attempts when the producer-consumer buffer is empty. In addition, by obtaining the current read pointer corresponding to the producer-consumer buffer, the location of the buffer space where the data to be read is located can be directly located without the consumer traversing the entire buffer to find valid data, which helps to improve the location efficiency and reading accuracy of data reading.

[0015] In one possible implementation, when the full semaphore is greater than a preset semaphore threshold, the method further includes: Obtain the print verification code from the buffer space corresponding to the current read pointer, wherein the print verification code contains multiple print verification characters; The system obtains real-time read data during the process of the consumer reading the corresponding imported print data based on the current read pointer, and identifies whether the real-time read data contains the print verification character corresponding to the print verification code. If so, then identify the reading order of each printed verification character in the real-time read data; When the reading order is consistent with the standard order of the printed verification characters in the printed verification code, it is determined that the consumer's reading is normal.

[0016] By adopting the above technical solution, when the full semaphore exceeds the preset semaphore threshold, the verification code printed in the buffer space corresponding to the current read pointer is obtained for reading verification. This helps to avoid reading misalignment, fragment loss, or data tampering problems that may occur when the data volume is large. By acquiring real-time reading data during the consumer's reading process and verifying whether it contains all the verification characters of the printed verification code, it is easy to filter out abnormal reading data that is missing key verification information. This eliminates invalid monitoring and analysis caused by reading interruption or data omission from the basic level. Furthermore, by identifying the reading order of the printed verification characters in the real-time reading data and comparing it with the standard order of printed verification characters, it is easy to accurately determine whether there is a character order disorder in the reading data. This helps to ensure that the reading data is consistent with the original data written by the producer in terms of logical structure, which helps to reduce the risk of monitoring misjudgment caused by abnormal data reading. It provides highly reliable data input for subsequent real-time security monitoring and analysis, and further enhances the accuracy of remote operation and maintenance in judging the equipment operating status.

[0017] Secondly, this application provides a printing implementation system, which adopts the following technical solution: A printing implementation system, the printing implementation system comprising: At least one processor; Memory; At least one application, wherein the at least one application is stored in memory and configured to be executed by at least one processor, the at least one application being configured to: execute the above-described printing implementation method of the production consumer buffer based on shared memory.

[0018] Thirdly, this application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium includes: a computer program that can be loaded by a processor and execute the above-described printing implementation method of a shared memory-based producer-consumer buffer.

[0019] Fourthly, this application provides a computer program product, which adopts the following technical solution: A computer program product includes a computer program that, when executed by a processor, implements the above-described printing implementation method for a shared memory-based producer-consumer buffer.

[0020] In summary, this application includes at least one of the following beneficial technical effects: By allocating corresponding buffer space within the producer-consumer buffer and releasing the mutex semaphore and updating the full semaphore only after the imported print data has been written, it is easy to ensure that a single piece of imported print data is not interrupted or overwritten by other producers during the import process. That is, it avoids the problems of information fragmentation and interleaving caused by concurrent import of multiple processes from the root, thus ensuring the integrity and order of the imported print data. By establishing a real-time linkage mechanism between producer import and consumer reading, it is easy to trigger the consumer's reading action immediately after the producer completes the data import, thus avoiding the delay of imported data in the producer-consumer buffer. This ensures that the print data can be quickly transmitted to the subsequent security monitoring stage. By reducing the occurrence of data disorder or missing data during the import and reading process, it is easy to reduce the misjudgment or missed judgment caused by data distortion, thus improving the accuracy of anomaly monitoring results.

[0021] By acquiring historical import information for a preset analysis period and determining the predicted import information for a preset prediction period, it is easy to predict the import characteristics of print data that needs to be imported in the future based on historical import patterns. Based on the prediction results, a buffer partitioning strategy is determined to avoid buffer partitioning from actual data needs. By formulating a buffer partitioning strategy based on the predicted import information and dividing multiple buffer spaces, it is easy to ensure that the space allocation of the producer and consumer buffers is accurately matched with the predicted print data import needs. Attached Figure Description

[0022] Figure 1 This is a flowchart illustrating a printing implementation method for a shared memory-based producer-consumer buffer in an embodiment of this application. Figure 2 This is a flowchart illustrating a buffer space partitioning method in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a printing implementation system according to an embodiment of this application. Detailed Implementation

[0023] The following is in conjunction with the appendix Figures 1 to 3 This application will be described in further detail.

[0024] After reading this specification, those skilled in the art may make modifications to this embodiment without contributing any inventive step, but such modifications are protected by patent law as long as they fall within the scope of the claims of this application.

[0025] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0026] It should be noted that, in the optional embodiments of this application, the data related to object information, when applied to specific products or technologies, requires the permission or consent of the object. Furthermore, the collection, use, and processing of this data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. In other words, if the embodiments of this application involve data related to an object, it must be obtained with the object's authorization and consent, the authorization and consent of relevant departments, and in accordance with the relevant laws, regulations, and standards of the country and region. If the embodiments involve personal information, the acquisition of all personal information requires the individual's consent. If sensitive information is involved, the separate consent of the information subject is required. The embodiments also need to be implemented with the object's authorization and consent.

[0027] Specifically, this application provides a printing implementation method based on a shared memory producer-consumer buffer, executed by a printing implementation system. This system can be a server or a terminal device. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smartphone, tablet, laptop, desktop computer, etc., but is not limited to these. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and this application does not impose any limitations on this connection.

[0028] refer to Figure 1 , Figure 1 This is a flowchart illustrating a printing implementation method for a shared memory-based producer-consumer buffer according to an embodiment of this application. The method includes steps S110-S130, wherein: Step S110: Obtain the import information provided by the target producer, and update the semaphore information corresponding to the producer-consumer buffer based on the import information. The import information includes the data to be imported and the buffer space to be imported. The buffer space to be imported is the buffer space in the producer-consumer buffer.

[0029] Specifically, the target producer is the producer that successfully applies to import print data. When there is only one producer, after detecting or receiving the application information submitted by that producer, the producer can be directly identified as the target producer. However, when there are at least two producers, the application information provided by each producer needs to be analyzed, and finally, the target producer is selected from at least two producers. The process of determining the target producer when there are at least two producers includes: Obtain the application import information for each producer, which includes an application timestamp and import information; sort all producers' application order according to the application timestamp to obtain an initial sorting list; identify the import data features contained in each import information and determine the data importance level corresponding to each import information based on a preset data importance level mapping relationship; adjust the sorting position of the corresponding producer in the initial sorting list based on the data importance level of each import information to obtain a target sorting list; determine the target producer based on the target sorting list.

[0030] Specifically, the producer's application import information includes an application timestamp and import information. The application timestamp is the moment when the corresponding producer submits the import application to the printing implementation system. All application import information can be sorted according to the application timestamp to obtain an initial sorted list for all producers. Then, the import data features in each import information are identified according to a preset feature recognition algorithm. Different import data features may correspond to different data importance levels. The data importance level corresponding to each import data feature can be determined through a preset data importance level mapping relationship. The preset data importance level mapping relationship includes multiple import data features and the data importance level corresponding to each import data feature. The specific content is not specifically limited in this application embodiment, and the specific preset feature recognition algorithm is also not specifically limited in this application embodiment.

[0031] After determining the data importance level corresponding to each imported information, the importance level can be converted into an adjusted ranking according to a preset ranking transformation mapping relationship. Finally, based on the adjusted ranking corresponding to the imported information of each producer, the list position of each producer in the initial sorting list is updated to obtain the target sorting list, and the first position of the target sorting list is determined as the target producer. By providing dual judgment criteria of time order and data attributes for the scheduling of multiple producers, priority imbalance caused by single-dimensional scheduling can be avoided.

[0032] The data to be imported for printing is crucial information reflecting the real-time operating status of relevant equipment. After obtaining the import information provided by the target producer, the data to be imported from the import information can be written into the import buffer space to complete the import operation. The import buffer space is an independent buffer space within the producer-consumer buffer. The import buffer space corresponding to each target producer can be allocated by the printing implementation system according to the writing order of the producer-consumer buffer. That is, after responding to the target producer's request for import information, the printing implementation system will determine the import buffer space corresponding to the current target producer according to the writing order of the producer-consumer buffer. For example, if the producer-consumer buffer contains free buffer spaces a, b, and c, and the import pointer at the current moment points to space a, then space a is allocated to the target producer at the current moment as the corresponding import buffer space. After the import operation of the data to be imported for the target producer at the current moment is completed, space b is allocated to the target producer at the next moment as its corresponding import buffer space.

[0033] Semaphore information includes, but is not limited to, empty semaphores, full semaphores, and mutex semaphores. An empty semaphore represents the amount of idle buffer space in the producer-consumer buffer at the current moment, while a full semaphore represents the amount of buffer space in the producer-consumer buffer currently being used to write print data. The empty and full semaphores can be updated based on the real-time import status of the print data to be imported. A mutex semaphore represents the operational state of the producer-consumer buffer at the current moment, including import and read states.

[0034] Step S120: When the import information is detected to be complete, restore the mutex semaphore and remind the consumer to read the imported print data from the producer-consumer buffer based on the updated full semaphore.

[0035] Specifically, after the data to be imported is completely entered into the corresponding import buffer space, a completion import signal is generated. The printing implementation system can detect whether the import information has been successfully imported by capturing the completion import signal. The method for detecting whether the import information has been successfully imported is not specifically limited in this embodiment. To avoid cross-importing between multiple processes or threads, in addition to allocating an independent import buffer space for each piece of import information, a mutex semaphore can be introduced. When a target producer requests to write the data to be imported into a certain import buffer space, it must first acquire the exclusive mutex semaphore corresponding to that buffer space. Only after successful acquisition, i.e., the mutex semaphore changes from 1 to 0 and enters a locked state, can the import begin. If the mutex semaphore is already occupied by another producer, i.e., the mutex semaphore is in a 0 state, the current producer must enter a waiting queue until the mutex semaphore is released, i.e., restored to 1 and enters an unlocked state, before the import can begin. Restoring the mutex semaphore means changing the mutex semaphore in a 0 state to a 1 state.

[0036] During the consumer read phase, read operations need to be performed based on the updated full semaphore. When the full semaphore is not 0, reads can be performed based on the current position of the read pointer. Furthermore, to improve the positioning efficiency and accuracy of data reads, the consumer is prompted to read and import print data from the producer-consumer buffer based on the updated full semaphore. Specifically, this may include: When the updated full semaphore is greater than 0, obtain the current read pointer corresponding to the producer-consumer buffer; generate a consumption prompt instruction based on the current read pointer, which is used to remind the consumer to read the import print data corresponding to the read pointer from the producer-consumer buffer.

[0037] Specifically, when the updated full semaphore is greater than 0, it indicates that the consumer can perform a read operation on the producer-consumer buffer. Since the buffer space is allocated sequentially, the reading phase also proceeds sequentially to avoid read anomalies or deviations. When the updated full semaphore is greater than 0, the current read pointer is directly obtained, and the relevant consumer is guided to read the relevant imported print data from the producer-consumer buffer based on the current read pointer. The current read pointer is the read pointer corresponding to the current moment, and it is an index value that records the position of the next piece of imported print data to be read in the producer-consumer buffer. After the consumer successfully reads a piece of imported print data, it needs to return a read completion signal to the print implementation system. Upon receiving the signal, the print implementation system automatically updates the read pointer to the position of the next piece of imported print data to be read, such as from B064 to B065, to ensure the continuity of sequential reading.

[0038] If an abnormal full semaphore value is detected, such as a negative full semaphore value, it may be due to a full semaphore synchronization error. In this case, the semaphore repair mechanism needs to be triggered immediately, and the read pointer acquisition process should be paused to prevent erroneous guidance. After receiving a consumption prompt instruction, the consumer needs to return an instruction reception confirmation to the printing implementation system. The printing implementation system can record the generation time, distribution time, and reception confirmation time of the consumption prompt instruction in the consumption scheduling log to facilitate subsequent troubleshooting.

[0039] Furthermore, to reduce the risk of monitoring misjudgment due to abnormal data reading, the method provided in this application embodiment may further include the following when the full semaphore is greater than a preset semaphore threshold: Obtain the printed verification code in the buffer space corresponding to the current read pointer. The printed verification code contains multiple printed verification characters. Obtain the real-time read data of the consumer during the process of reading the corresponding imported printed data based on the current read pointer, and identify whether the real-time read data contains the printed verification characters corresponding to the printed verification code. If so, identify the reading order of each printed verification character in the real-time read data. When the reading order is consistent with the standard order of the printed verification characters in the printed verification code, it is determined that the consumer's reading is normal.

[0040] Specifically, in most cases, the import process corresponds to the read process. For example, after importing data 'a' into the buffer space corresponding to the producer-consumer buffer, the consumer will read data 'a'. However, since the consumer faces different forwarding or uploading operations after reading different imported data, the consumer's read efficiency may be lower than the producer's import efficiency. Since the core function of a full semaphore is to record the amount of imported but unread data in the producer-consumer buffer, when the read efficiency is lower than the import efficiency, the data indicating completed import operations cannot be promptly read and cleared from the producer-consumer buffer. The full semaphore will gradually increase from a state greater than 0 to a state equal to the total space of the producer-consumer buffer. In this state, the read object no longer possesses uniqueness. Furthermore, there may be some imported data stored across different spaces, increasing the difficulty of the read process. That is, problems such as read misalignment, fragment loss, or data tampering may occur during the read process. Therefore, when the full semaphore exceeds a preset semaphore threshold, a read verification operation needs to be added to improve the integrity and security of the read process.

[0041] The specific read verification operation can be as follows: Based on the buffer space corresponding to the current read pointer and the preset verification code check table, determine the printed verification code for the buffer space corresponding to the current read pointer. The printed verification code consists of multiple printed verification characters in a fixed order. These multiple printed verification characters can be extracted from the corresponding data to be imported for printing. The preset verification check table contains the printed verification codes corresponding to each buffer space, which can be entered by relevant personnel. The printed verification code can be #VER-2024#. The specific printed verification characters and their order are not specifically limited in this embodiment. During the process of the consumer reading the corresponding imported printed data based on the current read pointer, the consumer's real-time read data is acquired in real time, and the printed verification characters contained in the real-time read data are identified from the real-time read data according to the preset feature recognition algorithm. If the real-time read data contains all the printed verification characters, it is determined that the verification characters exist completely, and the next step of sequence verification is entered. Based on the reading time of each printed verification character, it is verified whether the reading order of each printed verification character in the real-time read data is consistent with the standard order of the printed verification characters in the printed verification code. If they are consistent, it is determined that the consumer's reading is normal, and a notification of verification success is returned to the relevant consumer, allowing the consumer to use the reading result for subsequent security monitoring and analysis. If at least one position of the printed verification character does not match, it is determined that the data reading order is misaligned. At this time, the reading operation of the relevant consumer can be paused and the read pointer calibration can be triggered.

[0042] By acquiring real-time read data during the consumer's reading process and verifying whether it contains all the verification characters of the printed verification code, it is easy to filter out abnormal read data that lacks key verification information. This eliminates invalid monitoring and analysis caused by read interruptions or data omissions at the basic level. Furthermore, by identifying the reading order of the printed verification characters in the real-time read data and comparing it with the standard order of printed verification characters, it is easy to accurately determine whether there is a disorder in the character order of the read data. This helps to ensure that the read data is consistent with the original data written by the producer in terms of logical structure, which helps to reduce the risk of monitoring misjudgment caused by abnormal data reading. It provides highly reliable data input for subsequent real-time security monitoring and analysis, and further enhances the accuracy of remote operation and maintenance in judging the equipment's operating status.

[0043] Step S130: Perform real-time security monitoring and analysis based on the imported print data.

[0044] Specifically, after detecting that the consumer has completed the reading operation, the imported printing data read by the consumer can be directly forwarded or sent to relevant remote monitoring platforms, remote operation and maintenance alarm devices, etc., for security monitoring of the operation process of relevant devices.

[0045] In this embodiment of the application, by allocating corresponding buffer space in the producer-consumer buffer and releasing the mutex semaphore and updating the full semaphore only after the printing data to be imported is written, it is easy to ensure that a single piece of printing data to be imported is not interrupted or overwritten by other producers during the import process. That is, it avoids the problem of information fragmentation and interleaving chaos caused by concurrent import of multiple processes from the root, thereby ensuring the integrity and order of the printing data to be imported. By establishing a real-time linkage mechanism between producer import and consumer reading, it is easy to trigger the consumer's reading action immediately after the producer completes the data import, thereby avoiding the delay of imported data in the producer-consumer buffer. This makes it easier to ensure that the printing data can be quickly transmitted to the subsequent security monitoring stage. By reducing the occurrence of data chaos or missing data during the import and reading process, it is easier to reduce misjudgment or missed judgment caused by data distortion, thereby improving the accuracy of anomaly monitoring results.

[0046] Furthermore, to facilitate precise matching between the space allocation of the producer-consumer buffer and the predicted print data import demand, the technical method provided in this application may further include steps S210 and S220 before updating the semaphore information corresponding to the producer-consumer buffer based on the import information, such as... Figure 2 As shown, where: Step S210: Obtain historical import information corresponding to the preset analysis time period, and determine the predicted import information corresponding to the preset prediction time period based on the historical import information. The historical import information includes historical import print data and the amount of historical import data corresponding to each historical import print data.

[0047] Specifically, the preset analysis time period is a period of time preceding the current moment. The duration of the preset analysis time period can be 24 hours or 12 hours, and the specific duration is not specifically limited in this embodiment. The historical import information includes, but is not limited to, the historical import time, the historical imported print data, and the historical import data volume. By analyzing the historical import information corresponding to the preset analysis time period, it is convenient to predict the import print data that may need to be imported in the future. The preset prediction time period is a period of time following the current moment. The prediction duration corresponding to the preset prediction time period can be 24 hours or 12 hours, and the specific duration is not specifically limited in this embodiment. One preset prediction time period can be regarded as one import cycle.

[0048] Step S220: Determine the buffer partitioning strategy based on the predicted import information, and partition the producer and consumer buffers according to the buffer partitioning strategy to obtain multiple buffer spaces.

[0049] Specifically, the producer-consumer buffer can be divided based on a preset data volume. For example, the producer-consumer buffer can be divided into a 512-byte buffer space or a 256-byte buffer space. However, the amount of data that can be imported into the buffer space obtained after dividing the producer-consumer buffer based on the preset data volume is fixed. In order to avoid deviations during the import or reading process, this application sets different print data to be imported into different buffer spaces. In this case, it is easy to waste buffer space. For example, if the buffer space has a data storage capacity of 512 bytes and the print data to be imported at the current moment is 513 bytes, in order to import the print data completely and avoid confusion with other print data to be imported, two buffer spaces need to be allocated for the print data to be imported. This will result in wasted buffer space.

[0050] The buffer partitioning strategy is used to divide the producer-consumer buffer space. The buffer partitioning strategy is determined based on the predicted import information, which helps to improve the adaptability between the partitioning results and the import demand, thereby reducing the situation of large-scale idle buffer space. Specifically, the preset prediction time period can be divided into multiple prediction time periods first. Then, the amount of predicted import data faced by each prediction time period can be determined according to the predicted import information. Finally, the producer-consumer buffer corresponding to the preset prediction time period is partitioned based on the predicted import data volume corresponding to each prediction time period. The resulting multiple buffer spaces correspond to each prediction time period.

[0051] In this embodiment of the application, by obtaining historical import information for a preset analysis period and determining the predicted import information for a preset prediction period, it is easy to predict the import characteristics of the print data that needs to be imported in the future based on the historical import patterns. Based on the prediction results, a buffer partitioning strategy is determined to avoid the buffer partitioning from deviating from the actual data requirements. By formulating a buffer partitioning strategy based on the predicted import information and dividing multiple buffer spaces, it is easy to make the space allocation of the producer and consumer buffers accurately match the predicted print data import requirements.

[0052] Furthermore, to improve the compatibility between the buffer space and the data to be imported for printing, the method provided in this application also includes: Obtain the actual imported data volume of each buffer space within the producer-consumer buffer for a preset forecast time period. Determine the space idle rate of each buffer space based on the allocated data volume and the actual imported data volume. Determine the space idle rate curve based on the space idle rate of each buffer space and the buffer position of each buffer space in the producer-consumer buffer. Identify the idle peak and idle peak position from the space idle rate curve based on a preset peak threshold, and determine the idle buffer segment based on each idle peak and idle peak position. Identify the idle rate fluctuation data corresponding to the idle buffer segment from the space idle rate curve, and determine the circular buffer parameter corresponding to the idle buffer segment based on the idle rate fluctuation data. Optimize the buffer partitioning strategy for the next preset forecast time period based on the idle buffer segment and the circular buffer parameter.

[0053] Specifically, after an import cycle ends, the buffer space and the corresponding actual imported data volume of the previous import cycle can be analyzed to evaluate the buffer space utilization rate of the previous import cycle. This provides data support for optimizing the buffer allocation strategy of the next import cycle and improves resource utilization. The allocated data volume and the corresponding actual imported data volume of each buffer space are obtained. The space idle rate of each buffer space can be determined based on a preset space idle rate calculation formula: Space idle rate = (Allocated data volume - Actual imported data volume) / Allocated data volume × 100%. The specific calculation process is not specifically limited in this embodiment. For example, if the allocated data volume of a buffer space is 512 bytes and the actual imported data volume is 256 bytes, the space idle rate of this buffer space can be determined to be 50%. The method for determining the space idle rate of each buffer space based on the allocated data volume and the actual imported data volume is not specifically limited in this embodiment.

[0054] After determining the idle rate of each buffer space, the buffer position of each buffer space is bound to the corresponding idle rate. A visualization curve is used to display the idle distribution of each buffer space within the producer-consumer buffer zone. Specifically, an idle distribution coordinate system is constructed with the buffer position as the horizontal axis and the idle rate of each buffer space as the vertical axis. The buffer position and the coordinate points corresponding to the idle rate of each buffer space are marked in this coordinate system, and connected by a line to form an idle rate curve. Since different idle spaces may correspond to different idle rates, the idle rate curve may exhibit a continuous fluctuation pattern, with local high values ​​representing severely idle spaces. The idle rate curve is iterated through according to a preset peak threshold. Idle peaks with idle rates higher than the preset peak threshold are identified, and the buffer position corresponding to the idle peak is determined as the idle peak position. The number of idle peaks is not specifically limited in this embodiment. The preset peak threshold can be 90% or 85%, and the specific value can be set by relevant technical personnel according to actual needs.

[0055] By analyzing idle peak values ​​and their locations, it is determined whether the space idle rate curve contains an idle buffer segment that meets preset conditions. These preset conditions include: an average idle rate higher than a preset average value; and a space idle density higher than a preset density value. The average idle rate is the average of all idle peak values ​​corresponding to all idle peak positions within the idle buffer segment, and the space idle density is the distribution density of all idle peak positions within the idle buffer segment. The specific preset average value and preset density value are not specifically limited in this embodiment and can be determined by relevant personnel based on historical experimental data and uploaded to the printing implementation system.

[0056] The idle rate fluctuation data corresponding to the idle buffer segment can be identified from the idle rate curve based on a preset feature recognition algorithm. The idle rate fluctuation data includes, but is not limited to, fluctuation amplitude and fluctuation period. The parameters of the circular buffer include, but are not limited to, the total buffer capacity, the minimum unit size, and the read / write pointer step size. The total buffer capacity corresponding to the circular buffer can be determined based on a preset total capacity calculation formula. The preset total capacity calculation formula is: Total buffer capacity = Original allocated data amount of idle buffer segment × (1 - Average idle rate) × (1 + Fluctuation redundancy coefficient). The fluctuation redundancy coefficient is related to the fluctuation amplitude corresponding to the idle buffer segment. The larger the fluctuation amplitude, the higher the fluctuation redundancy coefficient. For example, when the fluctuation amplitude is 15%, the corresponding fluctuation redundancy coefficient is 0.2, and when the fluctuation amplitude is 20%, the corresponding fluctuation redundancy coefficient is 0.5. The correspondence between fluctuation amplitude and fluctuation redundancy coefficient is not specifically limited in this embodiment of the application. Based on a preset feature recognition algorithm, the distribution characteristics of historical imported data volume are determined from the historical import records corresponding to the idle buffer segment. The minimum unit size is then determined based on these distribution characteristics. For example, if 80% of the data volume is concentrated between 32 and 48 bytes, the minimum unit size is set to the upper limit of this range, such as 48 bytes, ensuring that a single unit can accommodate the vast majority of data. The buffer depth corresponding to the circular buffer can be determined based on a preset buffer depth calculation formula: Buffer Depth = Total Buffer Capacity / Minimum Unit Size. The read / write pointer step size corresponding to the circular buffer can be determined based on the fluctuation period corresponding to the idle buffer segment: Read / write pointer step size = Minimum Unit Size × Fluctuation Period.

[0057] When optimizing the buffer partitioning strategy for the next preset prediction time period based on the parameters of idle buffer segments and circular buffers, the fixed buffer space corresponding to the idle buffer segments can be released directly within the next preset prediction time period. Based on the parameters of the circular buffers, they can be merged into a continuous circular buffer. The hybrid architecture of fixed buffer space + circular buffer provided by this application facilitates both efficient access to stable data and flexible storage of fluctuating data, thereby improving the overall resource utilization of the producer-consumer buffer. In addition, the dynamic adaptation mechanism ensures that the optimization strategy can be continuously adjusted with changes in the operating status of the equipment, avoiding the problem of idleness again after one-time optimization, and providing a guarantee for long-term efficient operation.

[0058] By pre-dividing the producer-consumer buffer into multiple buffer spaces, it's easy to pre-allocate fixed physical addresses for each buffer space. During the import process, the producer doesn't need to calculate and locate currently free buffer spaces; the printing implementation system allocates them sequentially based on the actual usage of the producer-consumer buffers. Therefore, the import process time can be reduced to microseconds. Furthermore, during reading, the consumer only needs to directly point to the fixed buffer space using the read pointer provided by the printing implementation system, without needing to resolve the read / write pointer offset relationship of the circular buffer, resulting in extremely low read latency. This immediate efficiency advantage is crucial for scenarios with high real-time requirements. If a circular buffer were used entirely, the additional pointer management logic could double the read / write latency, causing critical monitoring opportunities to be missed.

[0059] This application provides a printing implementation system, such as... Figure 3 As shown, Figure 3 The illustrated printing implementation system 300 includes a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, for example, via a bus 302. Optionally, the printing implementation system 300 may further include a transceiver 304. It should be noted that in practical applications, the transceiver 304 is not limited to one type, and the structure of this printing implementation system 300 does not constitute a limitation on the embodiments of this application.

[0060] Processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0061] Bus 302 may include a pathway for transmitting information between the aforementioned components. Bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 302 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 3 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.

[0062] The memory 303 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.

[0063] The memory 303 is used to store application code that executes the solution of this application, and its execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the content shown in the foregoing method embodiments.

[0064] The printing implementation system includes, but is not limited to: mobile terminals such as mobile phones, laptops, digital radio 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. It can also be used for servers, etc. Figure 3 The illustrated printing implementation system is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0065] This application provides a computer-readable storage medium storing a computer program that, when run on a computer, enables the computer to execute the corresponding content in the aforementioned method embodiments.

[0066] This application provides a computer program product including a computer program that, when executed by a processor, implements the methods described in any of the above embodiments.

[0067] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0068] The above description is only a partial embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. A method for printing a producer-consumer buffer based on shared memory, characterized in that, include: Obtain import information provided by the target producer, and update the semaphore information corresponding to the producer-consumer buffer based on the import information. The import information includes the data to be imported and the buffer space to be imported. The buffer space to be imported is the buffer space within the producer-consumer buffer. Once the import information is detected to be complete, the mutex semaphore is restored, and the consumer is reminded to read the imported print data from the producer-consumer buffer based on the updated full semaphore. Real-time security monitoring and analysis are performed based on the imported print data.

2. The printing implementation method of a producer-consumer buffer based on shared memory according to claim 1, characterized in that, Before updating the semaphore information corresponding to the producer-consumer buffer based on the imported information, the method further includes: Obtain historical import information corresponding to a preset analysis time period, and determine the predicted import information corresponding to a preset prediction time period based on the historical import information. The historical import information includes historical import print data and the amount of historical import data corresponding to each historical import print data. Based on the predicted import information, a buffer partitioning strategy is determined, and the producer-consumer buffer is spatially partitioned based on the buffer partitioning strategy to obtain multiple buffer spaces.

3. The printing implementation method of a producer-consumer buffer based on shared memory according to claim 2, characterized in that, Also includes: Obtain the actual imported data volume of each buffer space within the producer-consumer buffer during the preset prediction time period, and determine the space idle rate of each buffer space based on the allocated data volume and the actual imported data volume corresponding to each buffer space. The space idle rate curve is determined based on the space idle rate corresponding to each buffer space and the buffer position of each buffer space in the producer-consumer buffer. Idle peaks and idle peak positions are identified from the space idle rate curve based on a preset peak threshold, and idle buffer segments are determined based on each idle peak and idle peak position. Identify the idle rate fluctuation data corresponding to the idle buffer segment from the idle rate curve, and determine the circular buffer parameters corresponding to the idle buffer segment based on the idle rate fluctuation data; Based on the idle buffer segment and the circular buffer parameters, optimize the buffer partitioning strategy corresponding to the next preset prediction time period.

4. The printing implementation method of a producer-consumer buffer based on shared memory according to claim 1, characterized in that, When there are at least two producers, the process of determining the target producer includes: Obtain the application import information for each producer, which includes the application timestamp and import information; The application order of all producers is sorted according to the application timestamp to obtain an initial sorted list; Identify the imported data features contained in each imported message, and determine the data importance level corresponding to each imported message based on the preset data importance level mapping relationship; Based on the data importance level of each imported information, the sorting position of the corresponding producer in the initial sorting list is adjusted to obtain the target sorting list; The target producer is determined based on the target sorting list.

5. The printing implementation method of a producer-consumer buffer based on shared memory according to claim 1, characterized in that, The step of reminding the consumer to read and import print data from the producer-consumer buffer based on the updated full semaphore includes: When the updated full semaphore is greater than 0, obtain the current read pointer corresponding to the producer-consumer buffer; A consumption prompt instruction is generated based on the current read pointer. The consumption prompt instruction is used to remind the consumer to read the import print data corresponding to the read pointer from the producer-consumer buffer.

6. The printing implementation method of a producer-consumer buffer based on shared memory according to claim 5, characterized in that, When the full semaphore is greater than a preset semaphore threshold, the following is also included: Obtain the print verification code from the buffer space corresponding to the current read pointer, wherein the print verification code contains multiple print verification characters; The system obtains real-time read data during the process of the consumer reading the corresponding imported print data based on the current read pointer, and identifies whether the real-time read data contains the print verification character corresponding to the print verification code. If so, then identify the reading order of each printed verification character in the real-time read data; When the reading order is consistent with the standard order of the printed verification characters in the printed verification code, it is determined that the consumer's reading is normal.

7. A printing implementation system, characterized in that, The printing implementation system includes: At least one processor; Memory; At least one application, wherein the at least one application is stored in memory and configured to be executed by at least one processor, the at least one application being configured to: perform a printing implementation method for a shared memory-based producer-consumer buffer according to any one of claims 1-6.

8. A computer-readable storage medium, characterized in that, include: The computer program stores a method for printing a shared memory-based producer-consumer buffer that can be loaded by a processor and executed as described in any one of claims 1-6.

9. A computer program product, characterized in that, The method includes a computer program that, when executed by a processor, implements the steps of a printing implementation method for a shared memory-based producer-consumer buffer according to any one of claims 1-6.