CN109783142B - Multithreading synchronization method based on POS machine and POS machine - Google Patents
Multithreading synchronization method based on POS machine and POS machine Download PDFInfo
- Publication number
- CN109783142B CN109783142B CN201811572525.7A CN201811572525A CN109783142B CN 109783142 B CN109783142 B CN 109783142B CN 201811572525 A CN201811572525 A CN 201811572525A CN 109783142 B CN109783142 B CN 109783142B
- Authority
- CN
- China
- Prior art keywords
- printing
- thread
- queue
- vector font
- font processing
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Abstract
The invention discloses a multi-thread synchronization method based on a POS machine and the POS machine. Wherein the method comprises the following steps: the POS machine decomposes the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread, synchronizes the vector font processing thread and the printing thread, controls the vector font processing thread to place the printing data into a printing queue after the vector font processing thread processes the vector font data, and controls the printing thread to print the information of the printing queue. By the method, the POS machine can be introduced into a multithreading synchronization mechanism to optimize the vector font printing mode, printing is smooth, and printing speed is high.
Description
Technical Field
The invention relates to the technical field of POS machines, in particular to a multithreading synchronization method based on a POS machine and the POS machine.
Background
A POS (Point Of Sale) machine, which is a terminal reader equipped with bar code or OCR (Optical Character Recognition) code technology, and has cash or barter function.
The basic principle of the POS machine comprises:
the POS machine firstly creates commodity data in a computer file, and through the online framework of the computer cash register, after bar codes on commodities can be directly read in through an optical reading device on the cash register device, the information of the commodities can be displayed immediately to accelerate the cash register speed and the correctness. Each commodity selling detail data in POS machine is automatically recorded, then the data is transferred back to computer by means of on-line structure, and through the calculation and processing of computer various selling statistical analysis information can be produced, and can be used as basis for management and management.
The existing POS machine mainly uses a thermal printer, and can print by adopting a dot matrix font printing mode or a vector font printing mode. However, the dot matrix font is difficult to scale, and a specific dot matrix font can only be clearly displayed under a corresponding font size, and forced scaling can cause character distortion and deformation and generate edge sawtooth. When the existing dot matrix font printing mode is used for printing characters with different font sizes and different languages, a plurality of font files need to be stored according to the specific language and the font sizes, so that the use is very inflexible, and the storage space is wasted. In the existing vector font printing mode, the same font file of the vector font can contain a plurality of different languages, the size of the vector font can be freely set, and a plurality of vector font files do not need to be stored or a forced scaling algorithm is not used.
However, the inventors found that at least the following problems exist in the prior art:
when the existing POS machine adopts a vector font printing mode to print, the vector font printing mode needs to be rendered through a large amount of mathematical operations, and the problems of low printing speed and unsmooth printing process exist.
Disclosure of Invention
In view of this, the present invention provides a method for multithread synchronization based on a POS machine and a POS machine, which can optimize a vector font printing manner by introducing a multithread synchronization mechanism to the POS machine, and have smooth printing and fast printing speed.
According to one aspect of the invention, a multithreading synchronization method based on a POS machine is provided, which comprises the following steps:
the POS machine decomposes the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread;
synchronizing the vector font processing thread and the print thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global zone bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, a printing width, a printing height and printing offset information;
after the vector font processing thread finishes processing the vector font data, controlling the vector font processing thread to place the printing data into a printing queue;
and controlling the printing thread to print the information of the printing queue.
Wherein, the POS machine synchronizes the vector font processing thread and the printing thread, comprising:
and the POS machine adopts a mutual exclusion lock, a condition variable and a global flag bit mode to synchronize the vector font processing thread and the printing thread.
Wherein, the synchronizing the vector font processing thread by the POS machine comprises:
the POS machine controls the vector font processing thread to try to acquire a mutual exclusion lock when printing data is put into a printing queue, and blocks the vector font processing thread if the mutual exclusion lock cannot be acquired, and at the moment, the printing thread occupies the mutual exclusion lock until the printing thread actively releases the mutual exclusion lock, and wakes up the vector font processing thread;
the POS machine controls the vector font processing thread to judge whether the printing queue is full, and if the printing queue is not full, printing data is stored in the tail of the printing queue;
the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, and the method comprises the following steps:
the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, if the current printing queue is judged not to have only one element, then whether the printing data is processed is judged, if the printing data is judged to be processed, a global flag bit is set, the printing thread is informed to exit after the printing work is finished, and meanwhile, a mutual exclusion lock is released;
and the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, if so, the printing thread is awakened through a readable condition variable of the printing queue, then, whether the printing data is processed is judged, if so, a global flag bit is set to inform the printing thread to quit after the printing work is finished, and meanwhile, a mutual exclusion lock is released.
Wherein the POS synchronizing the print thread comprises:
the POS machine controls the printing thread to acquire printing data from the printing queue, tries to acquire a mutual exclusion lock, blocks the printing thread if the mutual exclusion lock cannot be acquired, and occupies the mutual exclusion lock until the vector font processing thread actively releases the mutual exclusion lock to awaken the printing thread;
the POS machine controls the printing thread to judge whether the printing queue is empty or not, and the method comprises the following steps:
the POS machine controls the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, the printing thread takes out printing data from the printing queue head and executes printing operation, then the printing thread judges whether the current printing queue only has one vacancy or not, if the current printing queue only has one vacancy, the printing thread wakes up the vector font processing thread through a printing queue writable condition variable, then the printing thread judges whether the state of a global flag bit of the printing data is processed or not, whether the printing thread quits or not is determined according to the state of the global flag bit, and when the state of the global flag bit of the printing data is judged to be processed or not is judged to be processed, the printing thread quits after the printing operation is finished, and simultaneously, the exclusive lock is released;
the POS machine controls the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged to be empty, the printing thread is blocked, the vector font processing thread is waited to be awakened through the readable condition variable of the printing queue until the vector font processing thread is awakened and releases the exclusive lock, the printing thread takes out printing data from the head of the printing queue and executes printing operation, then the printing thread judges whether the current printing queue only has one vacancy or not, if the current printing queue only has one vacancy, the printing thread can awaken the vector font processing thread through the writable condition variable of the printing queue, then the printing thread judges whether the state of the global flag bit of the printing data is processed or not, determines whether the printing thread exits according to the state of the global flag bit, and when the state of the global flag bit of the printing data is judged to be processed or not is processed, and the printing thread exits after the printing work is finished, and simultaneously releases the mutual exclusion lock.
Wherein after the POS machine prints the information of the print queue, the method further comprises:
and the POS machine backs up the printing queue.
According to another aspect of the present invention, there is provided a POS machine comprising:
the printing system comprises a decomposition module, a synchronization module, a placement module and a printing module;
the decomposition module is used for decomposing the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread;
the synchronization module is used for synchronizing the vector font processing thread and the printing thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global zone bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, a printing width, a printing height and printing offset information;
the placement module is used for controlling the vector font processing thread to place the printing data into a printing queue after the vector font processing thread processes the vector font data;
and the printing module is used for controlling a printing thread to print the information of the printing queue.
Wherein, the synchronization module is specifically configured to:
and synchronizing the vector font processing thread and the printing thread by adopting a mutual exclusion lock, a condition variable and a global flag bit mode.
Wherein, the synchronization module is specifically configured to:
when the vector font processing thread is controlled to put printing data into a printing queue, trying to acquire a mutual exclusion lock, if the mutual exclusion lock cannot be acquired, blocking the vector font processing thread, and occupying the mutual exclusion lock by the printing thread till the printing thread actively releases the mutual exclusion lock to awaken the vector font processing thread;
controlling the vector font processing thread to judge whether the printing queue is full, and if the printing queue is not full, storing printing data into the tail of the printing queue;
controlling the vector font processing thread to determine whether the current print queue has only one element, including:
controlling the vector font processing thread to judge whether the current printing queue only has one element, judging whether the printing data is processed or not if the current printing queue is judged to not have only one element, setting a global flag bit if the printing data is processed, informing the printing thread to quit after the printing work is finished, and releasing a mutual exclusion lock;
and controlling the vector font processing thread to judge whether the current printing queue only has one element, if so, awakening the printing thread through a readable condition variable of the printing queue, then judging whether the printing data is processed completely, if so, setting a global flag bit, informing the printing thread to quit after the printing work is finished, and simultaneously releasing the mutual exclusion lock.
Wherein, the synchronization module is specifically configured to:
controlling the printing thread to acquire printing data from the printing queue, trying to acquire a mutual exclusion lock, and if the mutual exclusion lock cannot be acquired, blocking the printing thread, wherein the vector font processing thread occupies the mutual exclusion lock until the vector font processing thread actively releases the mutual exclusion lock, and awakening the printing thread;
controlling the print thread to determine whether the print queue is empty comprises:
controlling the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, taking out printing data from the printing queue head by the printing thread and executing printing operation, judging whether the current printing queue only has one vacancy or not by the printing thread, if the current printing queue only has one vacancy, awakening the vector font processing thread by the printing queue writable condition variable, judging whether the printing thread is in the state of a global flag bit for finishing the processing of the printing data or not by the printing thread, determining whether the printing thread is quitted or not according to the state of the global flag bit, and when the global flag bit for finishing the processing of the printing data is judged to be in the state of the global flag bit for finishing the processing, quitting the printing thread after the printing operation is finished and releasing a mutual exclusion lock;
controlling the printing thread to judge whether the printing queue is empty or not, if so, blocking the printing thread, waiting for the vector font processing thread to wake up through a readable condition variable of the printing queue until the vector font processing thread wakes up and releases a mutual exclusion lock, taking out printing data from the head of the printing queue by the printing thread and executing printing operation, then judging whether the current printing queue only has one vacancy or not by the printing thread, if so, waking up the vector font processing thread through the writable condition variable of the printing queue, then judging whether the printing data is in a state of a global flag bit after the printing data is processed or not by the printing thread, determining whether the printing thread exits according to the state of the global flag bit, and when judging that the state of the global flag bit after the printing data is processed or not is processed, and the printing thread exits after the printing work is finished, and simultaneously releases the mutual exclusion lock.
Wherein, POS machine still includes:
and the backup module is used for backing up the printing queue.
It can be found that, above scheme, POS machine can be with the processing of vector font and printing process decompose into vector font processing thread and printing thread two mutually independent threads altogether, and then this vector font processing thread and this printing thread of synchronization, and then after vector font processing thread has handled vector font data, control this vector font processing thread and place print data to the print queue, and then control the information that this print queue was printed to the print thread, can realize that POS machine introduces multithread synchronization mechanism and optimizes vector font printing mode, print smoothly, print fastly.
Furthermore, according to the scheme, the POS machine can back up the printing queue, and the printing queue can be restored from the backup data when the printing queue needs to be applied, so that the printing queue is convenient for a user to use, and the user experience is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flow chart of an embodiment of a multi-thread synchronization method based on a POS machine according to the present invention;
FIG. 2 is a flow chart of another embodiment of the multi-thread synchronization method based on POS machine according to the present invention;
FIG. 3 is a schematic structural diagram of an embodiment of a POS machine according to the present invention;
FIG. 4 is a schematic structural diagram of another embodiment of a POS machine according to the present invention;
FIG. 5 is a schematic structural diagram of another embodiment of the POS device of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be noted that the following examples are only illustrative of the present invention, and do not limit the scope of the present invention. Similarly, the following examples are only some but not all examples of the present invention, and all other examples obtained by those skilled in the art without any inventive work are within the scope of the present invention.
The invention provides a multi-thread synchronization method based on a POS machine, which can realize that the POS machine introduces a multi-thread synchronization mechanism to optimize a vector font printing mode, and has smooth printing and high printing speed.
Referring to fig. 1, fig. 1 is a schematic flow chart of an embodiment of a multi-thread synchronization method based on a POS machine according to the invention. It should be noted that the method of the present invention is not limited to the flow sequence shown in fig. 1 if the results are substantially the same. As shown in fig. 1, the method comprises the steps of:
s101: the POS machine decomposes the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread.
S102: the POS machine synchronizes the vector font processing thread and the printing thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global flag bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, printing width, printing height, printing offset information and the like.
Wherein, the synchronizing the vector font processing thread and the printing thread by the POS machine may include:
the POS machine adopts a mutual exclusion lock, a condition variable and a global flag bit mode to synchronize the vector font processing thread and the printing thread.
The synchronizing the vector font processing thread by the POS machine may include:
the POS machine controls the vector font processing thread to try to acquire a mutual exclusion lock when printing data is put into a printing queue, if the mutual exclusion lock cannot be acquired, the vector font processing thread is blocked, and at the moment, the printing thread occupies the mutual exclusion lock until the printing thread actively releases the mutual exclusion lock, and the vector font processing thread is awakened;
the POS machine controls the vector font processing thread to judge whether the printing queue is full, if the printing queue is not full, printing data is stored in the tail of the printing queue;
the POS controlling the vector font processing thread to determine whether the current print queue has only one element may include:
the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, if the current printing queue is judged not to have only one element, then whether the printing data is processed is judged, if the printing data is judged to be processed, a global flag bit is set, the printing thread is informed to exit after the printing work is finished, and simultaneously, a mutual exclusion lock is released;
and the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, if so, the printing thread is awakened through a readable condition variable of the printing queue, then, whether the printing data is processed is judged, if so, a global flag bit is set to inform the printing thread to quit after the printing work is finished, and meanwhile, a mutual exclusion lock is released.
Wherein, the POS synchronizing the print thread may include:
the POS machine controls the printing thread to acquire printing data from the printing queue, tries to acquire a mutual exclusion lock, blocks the printing thread if the mutual exclusion lock cannot be acquired, and occupies the mutual exclusion lock until the vector font processing thread actively releases the mutual exclusion lock to awaken the printing thread;
the controlling, by the POS machine, the print thread to determine whether the print queue is empty may include:
the POS machine controls the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, the printing thread takes out printing data from the printing queue head and executes printing operation, the printing thread then judges whether the current printing queue only has one vacancy or not, if the current printing queue only has one vacancy, the printing thread wakes up the vector font processing thread through a printing queue writable condition variable, the printing thread then judges whether the state of the global flag bit of the printing data is processed or not, whether the printing thread quits or not is determined according to the state of the global flag bit, and when the state of the global flag bit of the printing data is judged to be processed or not is judged to be processed, the printing thread quits after the printing operation is finished, and simultaneously, the exclusive lock is released;
the POS machine controls the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged to be empty, the printing thread is blocked, the vector font processing thread is waited to be awakened through the readable condition variable of the printing queue until the vector font processing thread is awakened and releases the exclusive lock, the printing thread takes out printing data from the head of the printing queue and executes printing operation, the printing thread then judges whether the current printing queue only has one vacancy or not, if the current printing queue only has one vacancy, the printing thread awakens the vector font processing thread through the writable condition variable of the printing queue, the printing thread then judges whether the state of the global flag bit of the printing data is processed or not, whether the printing thread quits or not is determined according to the state of the global flag bit, and when the state of the global flag bit of the printing data is judged to be processed or not is processed, the printing thread exits after the printing work is finished, and simultaneously, the mutual exclusion lock is released.
In this embodiment, the mutex lock is used to ensure that only one thread accesses the print queue at the same time.
In this embodiment, the condition variables may include a readable condition variable for controlling a read operation of the print queue and a writable condition variable for controlling a write operation of the print queue.
In this embodiment, the global flag is used to determine whether the print thread needs to be exited.
S103: and after the vector font processing thread processes the vector font data, the POS machine controls the vector font processing thread to place the printing data into a printing queue.
S104: the POS machine controls the printing thread to print the information of the printing queue.
After the POS machine prints the information of the print queue, the method may further include:
and the POS machine backs up the printing queue.
It can be found that, in this embodiment, the processing and printing process of the vector font can be decomposed into two mutually independent threads of the vector font processing thread and the printing thread by the POS machine, and then the vector font processing thread and the printing thread are synchronized, and then after the vector font processing thread finishes processing the vector font data, the vector font processing thread is controlled to place the printing data into the printing queue, and then the printing thread is controlled to print the information of the printing queue, so that the POS machine can introduce a multithread synchronization mechanism to optimize the vector font printing mode, the printing is smooth, and the printing speed is high.
Referring to fig. 2, fig. 2 is a flow chart illustrating another embodiment of the multi-thread synchronization method based on the POS machine according to the present invention. In this embodiment, the method includes the steps of:
s201: the POS machine decomposes the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread.
S202: the POS machine synchronizes the vector font processing thread and the printing thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global flag bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, printing width, printing height, printing offset information and the like.
As described above in S102, further description is omitted here.
S203: and after the vector font processing thread processes the vector font data, the POS machine controls the vector font processing thread to place the printing data into a printing queue.
S204: the POS machine controls the printing thread to print the information of the printing queue.
S205: and the POS machine backs up the printing queue.
It can be found that, in this embodiment, the POS machine can backup the print queue, and can realize that the POS machine can backup the print queue, and when the print queue needs to be applied to, the print queue can be restored from the backup data, which is convenient for the user to use the print queue, and improves the user experience.
The invention also provides a POS machine, which can optimize the vector font printing mode by introducing a multithreading synchronization mechanism into the POS machine, and has smooth printing and high printing speed.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a POS machine according to an embodiment of the invention. In this embodiment, the POS machine 30 is the POS machine in the above embodiment, and the POS machine 30 includes a decomposition module 31, a synchronization module 32, a placement module 33, and a printing module 34.
The decomposition module 31 is configured to decompose the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread.
The synchronization module 32, configured to synchronize the vector font processing thread and the print thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global flag bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, printing width, printing height, printing offset information and the like.
The placing module 33 is configured to control the vector font processing thread to place the print data into the print queue after the vector font processing thread has processed the vector font data.
The print module 34 is configured to control the print thread to print the information of the print queue.
Optionally, the synchronization module 32 may be specifically configured to:
and synchronizing the vector font processing thread and the printing thread by adopting a mutual exclusion lock, a condition variable and a global flag bit mode.
Optionally, the synchronization module 32 may be specifically configured to:
when the vector font processing thread is controlled to put printing data into a printing queue, trying to acquire a mutual exclusion lock, if the mutual exclusion lock cannot be acquired, blocking the vector font processing thread, occupying the mutual exclusion lock by the printing thread at the moment, and awakening the vector font processing thread until the printing thread actively releases the mutual exclusion lock;
controlling the vector font processing thread to judge whether the printing queue is full, and if the printing queue is not full, storing printing data into the tail of the printing queue;
controlling the vector font processing thread to determine whether the current print queue has only one element may include:
controlling the vector font processing thread to judge whether the current printing queue only has one element, judging whether the printing data is processed or not if the current printing queue is judged to not have only one element, setting a global flag bit if the printing data is processed, informing the printing thread to quit after the printing work is finished, and releasing a mutual exclusion lock;
and controlling the vector font processing thread to judge whether the current printing queue only has one element, if so, awakening the printing thread through a readable condition variable of the printing queue, then judging whether the printing data is processed completely, if so, setting a global flag bit, informing the printing thread to quit after the printing work is finished, and simultaneously releasing the mutex lock.
Optionally, the synchronization module 32 may be specifically configured to:
controlling the printing thread to acquire printing data from the printing queue, trying to acquire a mutual exclusion lock, if the mutual exclusion lock cannot be acquired, blocking the printing thread, occupying the mutual exclusion lock by the vector font processing thread at the moment, and awakening the printing thread until the vector font processing thread actively releases the mutual exclusion lock;
controlling the print thread to determine whether the print queue is empty may include:
controlling the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, taking out printing data from the printing queue head by the printing thread and executing printing operation, judging whether the current printing queue only has one vacancy or not by the printing thread, if the current printing queue only has one vacancy, awakening the vector font processing thread by the printing queue writable condition variable, judging whether the printing thread is in the state of the global flag bit which is processed or not by the printing thread, determining whether the printing thread is quitted or not according to the state of the global flag bit, and when the global flag bit which is processed or not is judged to be processed, quitting the printing thread after the printing operation is finished and releasing the exclusive lock;
controlling the printing thread to judge whether the printing queue is empty, if so, blocking the printing thread, waiting for the vector font processing thread to wake up through a readable condition variable of the printing queue until the vector font processing thread wakes up and releases a mutual exclusion lock, taking out printing data from the head of the printing queue by the printing thread and executing printing operation, then judging whether the current printing queue only has one vacancy, if so, waking up the vector font processing thread through the writable condition variable of the printing queue, then judging whether the printing data is processed or not by the printing thread, determining whether the printing thread exits according to the state of the global flag bit, and if so, judging whether the state of the global flag bit is processed or not, the printing thread exits after the printing work is finished, and simultaneously, the mutual exclusion lock is released.
Referring to fig. 4, fig. 4 is a schematic structural diagram of another embodiment of a POS machine according to the invention. Different from the previous embodiment, the POS machine 40 of this embodiment further includes: the backup module 41.
The backup module 41 is configured to backup the print queue.
Each unit module of the POS 30/40 can respectively execute the corresponding steps in the above method embodiments, and therefore, the detailed description of each unit module is omitted here, and please refer to the description of the corresponding steps above.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a POS machine according to another embodiment of the invention. Each unit module of the POS machine may respectively perform the corresponding steps in the above method embodiments. For a detailed description of the above method, please refer to the above method, which is not repeated herein.
In this embodiment, the POS machine includes: a processor 51, a memory 52 coupled to the processor 51, a printer 53, a backup 54.
The processor 51 is configured to decompose the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread, synchronize the vector font processing thread and the printing thread, and control the vector font processing thread to place the printing data in the printing queue after the vector font processing thread processes the vector font data; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global flag bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, printing width, printing height, printing offset information and the like.
The memory 52 is used for storing an operating system, instructions executed by the processor 51, and the like.
The printer 53 is configured to control the print thread to print the information of the print queue.
The backup 54 is used for backing up the print queue.
Optionally, the processor 51 may be specifically configured to:
and synchronizing the vector font processing thread and the printing thread by adopting a mutual exclusion lock, a condition variable and a global flag bit mode.
Optionally, the processor 51 may be specifically configured to:
when the vector font processing thread is controlled to put printing data into a printing queue, trying to acquire a mutual exclusion lock, if the mutual exclusion lock cannot be acquired, blocking the vector font processing thread, occupying the mutual exclusion lock by the printing thread at the moment, and awakening the vector font processing thread until the printing thread actively releases the mutual exclusion lock;
controlling the vector font processing thread to judge whether the printing queue is full, and if the printing queue is not full, storing printing data into the tail of the printing queue;
controlling the vector font processing thread to determine whether the current print queue has only one element may include:
controlling the vector font processing thread to judge whether the current printing queue only has one element, judging whether the printing data is processed or not if the current printing queue is judged to not have only one element, setting a global flag bit if the printing data is processed, informing the printing thread to quit after the printing work is finished, and releasing a mutual exclusion lock;
and controlling the vector font processing thread to judge whether the current printing queue only has one element, if so, awakening the printing thread through a readable condition variable of the printing queue, then judging whether the printing data is processed completely, if so, setting a global flag bit, informing the printing thread to quit after the printing work is finished, and simultaneously releasing the mutex lock.
Optionally, the processor 51 may be specifically configured to:
controlling the printing thread to acquire printing data from the printing queue, trying to acquire a mutual exclusion lock, if the mutual exclusion lock cannot be acquired, blocking the printing thread, occupying the mutual exclusion lock by the vector font processing thread at the moment, and awakening the printing thread until the vector font processing thread actively releases the mutual exclusion lock;
controlling the print thread to determine whether the print queue is empty may include:
controlling the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, taking out printing data from the printing queue head by the printing thread and executing printing operation, judging whether the current printing queue only has one vacancy or not by the printing thread, if the current printing queue only has one vacancy, awakening the vector font processing thread by the printing queue writable condition variable, judging whether the printing thread is in the state of the global flag bit which is processed or not by the printing thread, determining whether the printing thread is quitted or not according to the state of the global flag bit, and when the global flag bit which is processed or not is judged to be processed, quitting the printing thread after the printing operation is finished and releasing the exclusive lock;
controlling the printing thread to judge whether the printing queue is empty, if so, blocking the printing thread, waiting for the vector font processing thread to wake up through a readable condition variable of the printing queue until the vector font processing thread wakes up and releases a mutual exclusion lock, taking out printing data from the head of the printing queue by the printing thread and executing printing operation, then judging whether the current printing queue only has one vacancy, if so, waking up the vector font processing thread through the writable condition variable of the printing queue, then judging whether the printing data is processed or not by the printing thread, determining whether the printing thread exits according to the state of the global flag bit, and if so, judging whether the state of the global flag bit is processed or not, the printing thread exits after the printing work is finished, and simultaneously, the mutual exclusion lock is released.
Can discover, above scheme, POS machine can be with the processing and the printing process of vector font decompose into vector font processing thread and printing thread totally two mutually independent threads, and then this vector font processing thread and this printing thread of synchronization, and then after this vector font processing thread has handled vector font data, control this vector font processing thread and place print data to the print queue, and then control the information that this print queue was printed to the print thread, can realize that POS machine introduces multithread synchronization mechanism and optimizes vector font printing mode, print smoothly, print fastly.
Furthermore, according to the scheme, the POS machine can back up the printing queue, and the printing queue can be restored from the backup data when the printing queue needs to be applied, so that the printing queue is convenient for a user to use, and the user experience is improved.
In the several embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a module or a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be substantially or partially implemented in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only a part of the embodiments of the present invention, and not intended to limit the scope of the present invention, and all equivalent devices or equivalent processes performed by the present invention through the contents of the specification and the drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.
Claims (8)
1. A multi-thread synchronization method based on a POS machine is characterized by comprising the following steps:
the POS machine decomposes the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread;
synchronizing the vector font processing thread and the print thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global zone bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, a printing width, a printing height and printing offset information;
after the vector font processing thread finishes processing the vector font data, controlling the vector font processing thread to place the printing data into a printing queue;
controlling a printing thread to print the information of the printing queue;
the POS machine synchronizes the vector font processing thread, and the method comprises the following steps:
the POS machine controls the vector font processing thread to try to acquire a mutual exclusion lock when printing data is put into a printing queue, and blocks the vector font processing thread if the mutual exclusion lock cannot be acquired, and at the moment, the printing thread occupies the mutual exclusion lock until the printing thread actively releases the mutual exclusion lock, and wakes up the vector font processing thread;
the POS machine controls the vector font processing thread to judge whether the printing queue is full, and if the printing queue is not full, printing data is stored in the tail of the printing queue;
the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, and the method comprises the following steps:
the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, if the current printing queue is judged not to have only one element, then whether the printing data is processed is judged, if the printing data is judged to be processed, a global flag bit is set, the printing thread is informed to exit after the printing work is finished, and meanwhile, a mutual exclusion lock is released;
and the POS machine controls the vector font processing thread to judge whether the current printing queue only has one element, if so, the printing thread is awakened through a readable condition variable of the printing queue, then, whether the printing data is processed is judged, if so, a global flag bit is set to inform the printing thread to quit after the printing work is finished, and meanwhile, a mutual exclusion lock is released.
2. The POS-based multithread synchronization method of claim 1, wherein the POS synchronizing the vector font processing thread and the print thread comprises:
and the POS machine adopts a mutual exclusion lock, a condition variable and a global flag bit mode to synchronize the vector font processing thread and the printing thread.
3. The POS-based multithreading synchronization method of claim 1, wherein the POS synchronizing the print threads comprises:
the POS machine controls the printing thread to acquire printing data from the printing queue, tries to acquire a mutual exclusion lock, blocks the printing thread if the mutual exclusion lock cannot be acquired, and occupies the mutual exclusion lock until the vector font processing thread actively releases the mutual exclusion lock to awaken the printing thread;
the POS machine controls the printing thread to judge whether the printing queue is empty or not, and the method comprises the following steps:
the POS machine controls the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, the printing thread takes out printing data from the printing queue head and executes printing operation, then the printing thread judges whether the current printing queue only has one vacancy or not, if the current printing queue only has one vacancy, the printing thread wakes up the vector font processing thread through a printing queue writable condition variable, then the printing thread judges whether the printing data is processed or not according to the state of the global flag bit, whether the printing thread quits or not is determined according to the state of the global flag bit, and when the state of the global flag bit, which judges whether the printing data is processed or not, is processed, the printing thread quits after the printing operation is finished and simultaneously releases the exclusive lock;
the POS machine controls the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged to be empty, the printing thread is blocked, the vector font processing thread is waited to be awakened through the readable condition variable of the printing queue until the vector font processing thread is awakened and releases the exclusive lock, the printing thread takes out printing data from the head of the printing queue and executes printing operation, then the printing thread judges whether the current printing queue only has one vacancy or not, if the current printing queue only has one vacancy, the printing thread awakens the vector font processing thread through the writable condition variable of the printing queue, then the printing thread judges whether the printing data is processed or not according to the state of the global flag bit, determines whether the printing thread exits according to the state of the global flag bit, and when the state of the global flag bit for judging whether the printing data is processed or not is processed, and the printing thread exits after the printing work is finished, and simultaneously releases the mutual exclusion lock.
4. The POS-based multithreading synchronization method of claim 3, further comprising, after the POS printing the print queue information:
and the POS machine backs up the printing queue.
5. A POS machine, comprising:
the printing system comprises a decomposition module, a synchronization module, a placement module and a printing module;
the decomposition module is used for decomposing the processing and printing process of the vector font into two mutually independent threads, namely a vector font processing thread and a printing thread;
the synchronization module is used for synchronizing the vector font processing thread and the printing thread; the vector font processing thread and the printing thread are synchronized through a mutual exclusion lock, a condition variable and a global zone bit, print data are shared through a circular queue, and each element in the circular queue comprises bitmap data to be printed, a printing width, a printing height and printing offset information;
the placement module is used for controlling the vector font processing thread to place the printing data into a printing queue after the vector font processing thread processes the vector font data;
the printing module is used for controlling a printing thread to print the information of the printing queue;
the synchronization module is further configured to:
when the vector font processing thread is controlled to put printing data into a printing queue, trying to acquire a mutual exclusion lock, if the mutual exclusion lock cannot be acquired, blocking the vector font processing thread, and occupying the mutual exclusion lock by the printing thread till the printing thread actively releases the mutual exclusion lock to awaken the vector font processing thread;
controlling the vector font processing thread to judge whether the printing queue is full, and if the printing queue is not full, storing printing data into the tail of the printing queue;
controlling the vector font processing thread to determine whether the current print queue has only one element, including:
controlling the vector font processing thread to judge whether the current printing queue only has one element, judging whether the printing data is processed or not if the current printing queue is judged to not have only one element, setting a global flag bit if the printing data is processed, informing the printing thread to quit after the printing work is finished, and releasing a mutual exclusion lock;
and controlling the vector font processing thread to judge whether the current printing queue only has one element, if so, awakening the printing thread through a readable condition variable of the printing queue, then judging whether the printing data is processed completely, if so, setting a global flag bit, informing the printing thread to quit after the printing work is finished, and simultaneously releasing the mutual exclusion lock.
6. The POS of claim 5, wherein the synchronization module is to:
and synchronizing the vector font processing thread and the printing thread by adopting a mutual exclusion lock, a condition variable and a global flag bit mode.
7. The POS of claim 6, wherein the synchronization module is to:
controlling the printing thread to acquire printing data from the printing queue, trying to acquire a mutual exclusion lock, and if the mutual exclusion lock cannot be acquired, blocking the printing thread, wherein the vector font processing thread occupies the mutual exclusion lock until the vector font processing thread actively releases the mutual exclusion lock, and awakening the printing thread;
controlling the print thread to determine whether the print queue is empty comprises:
controlling the printing thread to judge whether the printing queue is empty or not, if the printing queue is judged not to be empty, taking out printing data from the printing queue head by the printing thread and executing printing operation, judging whether the current printing queue only has one vacancy or not by the printing thread, if the current printing queue only has one vacancy, awakening the vector font processing thread by the printing queue writable condition variable, judging whether the printing data is processed or not by the printing thread according to the state of the global flag bit, determining whether the printing thread is quitted according to the state of the global flag bit, and when the state of the global flag bit, which is judged whether the printing data is processed or not, is processed, quitting after the printing operation is finished and releasing the exclusive lock;
controlling the printing thread to judge whether the printing queue is empty or not, if so, blocking the printing thread, waiting for the vector font processing thread to wake up through a readable condition variable of the printing queue until the vector font processing thread is woken up and releases a mutual exclusion lock, taking out printing data from the head of the printing queue by the printing thread and executing printing operation, then judging whether the current printing queue only has one vacancy or not by the printing thread, if so, waking up the vector font processing thread through the writable condition variable of the printing queue, judging whether the printing data is processed or not according to the state of the global flag bit, determining whether the printing thread exits according to the state of the global flag bit, and when the state of the global flag bit for judging whether the printing data is processed or not is processed, and the printing thread exits after the printing work is finished, and simultaneously releases the mutual exclusion lock.
8. The POS of claim 7, further comprising: and the backup module is used for backing up the printing queue.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811572525.7A CN109783142B (en) | 2018-12-21 | 2018-12-21 | Multithreading synchronization method based on POS machine and POS machine |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811572525.7A CN109783142B (en) | 2018-12-21 | 2018-12-21 | Multithreading synchronization method based on POS machine and POS machine |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109783142A CN109783142A (en) | 2019-05-21 |
CN109783142B true CN109783142B (en) | 2021-02-12 |
Family
ID=66497592
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811572525.7A Active CN109783142B (en) | 2018-12-21 | 2018-12-21 | Multithreading synchronization method based on POS machine and POS machine |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109783142B (en) |
Family Cites Families (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050179936A1 (en) * | 2004-02-13 | 2005-08-18 | Microsoft Corporation | Scalable print spooler |
JP4164467B2 (en) * | 2004-03-26 | 2008-10-15 | キヤノン株式会社 | Image processing apparatus, image processing control method, and program |
EP3175744B1 (en) * | 2010-12-16 | 2023-11-29 | Briggo, LLC | Apparatus and method for brewed and espresso drink generation |
CN102693100B (en) * | 2011-02-10 | 2015-06-24 | 精工爱普生株式会社 | Network system, interface board, method of controlling printing on network system |
JP5909871B2 (en) * | 2011-04-28 | 2016-04-27 | セイコーエプソン株式会社 | Recording device |
JP5810609B2 (en) * | 2011-04-28 | 2015-11-11 | セイコーエプソン株式会社 | RECORDING DEVICE, RECORDING DEVICE CONTROL METHOD, AND PROGRAM |
CN103488441B (en) * | 2013-09-06 | 2016-05-11 | 深圳市新国都技术股份有限公司 | The implementation method that a kind of Arabic is printed on POS machine |
CN103631665B (en) * | 2013-12-12 | 2017-11-07 | 北京奇安信科技有限公司 | A kind of method and system of the inter-thread communication based on message queue |
CN105139060B (en) * | 2015-09-15 | 2018-05-22 | 歌尔股份有限公司 | Generation, the method for inspection and the system of bar code based on more printing devices |
CN105607904B (en) * | 2015-12-18 | 2019-04-16 | 南京熊猫电子股份有限公司 | The Quick Development Framework and its application method of communication software based on Linux platform |
CN107678701A (en) * | 2017-06-12 | 2018-02-09 | 平安科技(深圳)有限公司 | Device, method and the computer-readable recording medium of document printing |
CN107562480B (en) * | 2017-09-05 | 2021-03-09 | 深圳市新国都支付技术有限公司 | Method and system for realizing multilingual of POS machine |
-
2018
- 2018-12-21 CN CN201811572525.7A patent/CN109783142B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN109783142A (en) | 2019-05-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP3158463A1 (en) | Annotation preservation as comments | |
WO2011136937A2 (en) | Multi-threaded sort of data items in spreadsheet tables | |
CN109783142B (en) | Multithreading synchronization method based on POS machine and POS machine | |
CN111144804A (en) | Order processing method, device and system | |
CN104169981B (en) | POS terminal | |
CN114872449B (en) | Label printing method and device and electronic equipment | |
CN115454360A (en) | Label printing method, device and medium capable of flexibly adjusting printing format | |
US6771171B2 (en) | Atomic virtual document generation and tagging | |
CN102968284B (en) | printer and print processing method | |
CN106557225B (en) | Operation interface display and control method and device | |
JP5987421B2 (en) | Printing device | |
EP0327780B1 (en) | Bounded word replace function for an electronic typewriter | |
US9542569B2 (en) | Information processing system, information processing apparatus, storage medium having stored therein information processing program, and method of storing saved data | |
JP6828958B2 (en) | Ticket management system and ticket management method | |
US5404434A (en) | Document processor having identification display control means | |
JPH1110962A (en) | Printer and printing method | |
JP5057483B2 (en) | Information processing apparatus, control method therefor, and program | |
JPS6168631A (en) | Document print processing system | |
CN116467075A (en) | Multi-process processing method, device, server, storage medium and program product | |
CN117140964A (en) | Model part neglecting method, slicing method and device, electronic equipment and medium | |
CN115373824A (en) | Conflict detection method, device, computing equipment and computer readable storage medium | |
JP2002150211A (en) | Bar code printing system | |
JPH05266345A (en) | Printing system in medium issuing device | |
CN117057853A (en) | Electronic ticket issuing control method, device, equipment and storage medium | |
CN114861613A (en) | Method, apparatus, device, and medium for managing annotations in electronic books |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |