[go: up one dir, main page]

CN109783142A - A kind of Multithread Synchronization Program and POS machine based on POS machine - Google Patents

A kind of Multithread Synchronization Program and POS machine based on POS machine Download PDF

Info

Publication number
CN109783142A
CN109783142A CN201811572525.7A CN201811572525A CN109783142A CN 109783142 A CN109783142 A CN 109783142A CN 201811572525 A CN201811572525 A CN 201811572525A CN 109783142 A CN109783142 A CN 109783142A
Authority
CN
China
Prior art keywords
thread
printing
print
vector fonts
print queue
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.)
Granted
Application number
CN201811572525.7A
Other languages
Chinese (zh)
Other versions
CN109783142B (en
Inventor
许世杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
FUJIAN NEWLAND PAYMENT TECHNOLOGY Co Ltd
Original Assignee
FUJIAN NEWLAND PAYMENT TECHNOLOGY Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by FUJIAN NEWLAND PAYMENT TECHNOLOGY Co Ltd filed Critical FUJIAN NEWLAND PAYMENT TECHNOLOGY Co Ltd
Priority to CN201811572525.7A priority Critical patent/CN109783142B/en
Publication of CN109783142A publication Critical patent/CN109783142A/en
Application granted granted Critical
Publication of CN109783142B publication Critical patent/CN109783142B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Record Information Processing For Printing (AREA)
  • Cash Registers Or Receiving Machines (AREA)

Abstract

The invention discloses a kind of Multithread Synchronization Program and POS machine based on POS machine.Wherein, the described method includes: the processing of vector fonts and print procedure are resolved into vector fonts processing thread and printing thread totally two mutually independent threads by POS machine, synchronize vector fonts processing thread and the printing thread, after the vector fonts handles the complete vector fonts data of thread process, it controls vector fonts processing thread and print data is placed into print queue, control printing thread prints the information of the print queue.By the above-mentioned means, can be realized POS machine introduces Synchronized Mechanism for Multithread to optimize vector fonts printing type, printing is smooth, and print speed is fast.

Description

A kind of Multithread Synchronization Program and POS machine based on POS machine
Technical field
The present invention relates to POS machine technical field more particularly to a kind of Multithread Synchronization Programs and POS machine based on POS machine.
Background technique
POS (Point Of Sale, point-of-sale terminal) machine is a kind of equipped with bar code or OCR (Optical Character Recognition, optical character identification) code technology terminal reader, have the function of cash or the amount cashier that barters.
The basic principle of POS machine, comprising:
Commodity profile is first created in computer documents by POS machine, through the online framework of computer cash register, on commodity it After bar code can directly be read in through optical read device on cash register, can be accelerated at once with display of commodity information cash register speed and Correctness.Every merchandise sales detail data in POS machine automatically records, then passes computer back by online framework, via Computer calculation processing can generate various sale result analysis information and work as management foundation.
Thermal printer is mainly used in existing POS machine, using raster font printing type or can use vector font Body printing type is printed.But raster font is difficult to zoom in and out, specific raster font can only be most clearly shown in phase Under the font size answered, scaling will lead to text distorting transformation by force, generate edge sawtooth.Existing raster font printing type is being beaten Print different fonts size, different language text when, need to store more parts of font files for specific language and font size, Using upper very inflexible, and waste memory space.And in existing vector fonts printing type, the same word of vector fonts Body file may include a variety of different languages, and the size of vector fonts can be freely arranged, without storing more parts of vector fonts texts Part uses pressure scaling algorithm.
But at least there are the following problems in the prior art for inventor's discovery:
When existing POS machine is printed using vector fonts printing type, vector fonts printing type is needed through excessive The mathematical operation of amount is rendered, and it is slow that there are print speed, print procedure have Caton the problem of.
Summary of the invention
In view of this, it is an object of the invention to propose a kind of Multithread Synchronization Program and POS machine based on POS machine, energy Enough realize that POS machine introduces Synchronized Mechanism for Multithread and optimizes vector fonts printing type, printing is smooth, and print speed is fast.
According to an aspect of the present invention, a kind of Multithread Synchronization Program based on POS machine is provided, comprising:
The processing of vector fonts and print procedure are resolved into vector fonts processing thread and printing thread totally two by POS machine Mutually independent thread;
Synchronize the vector fonts processing thread and the printing thread;Wherein, the vector fonts processing thread and institute It states between printing thread through mutual exclusion lock, conditional-variable, global flag bit synchronization, print data is shared by round-robin queue, institute Stating each element in round-robin queue includes bitmap data to be printed, print span, printing height and printing offset information;
After the vector fonts handles the complete vector fonts data of thread process, controlling the vector fonts processing thread will Print data is placed into print queue;
Control printing thread prints the information of the print queue.
Wherein, the POS machine synchronous vector Font processing thread and the printing thread, comprising:
POS machine synchronizes the vector fonts processing thread using mutual exclusion lock and conditional-variable and global flag position mode With the printing thread.
Wherein, the POS machine synchronizes the vector fonts processing thread, comprising:
When the POS machine control vector fonts processing thread is put into print data into print queue, attempt to obtain mutual exclusion Lock blocks vector fonts processing thread if mutual exclusion lock can not be obtained, and the printing thread occupies mutual exclusion lock at this time, until The printing thread actively discharges mutual exclusion lock, wakes up the vector fonts processing thread;
POS machine controls the vector fonts processing thread and judges whether print queue has expired, past if print queue is less than Print data is stored in print queue tail;
POS machine controls the vector fonts processing thread and judges whether correct print queue only has an element, comprising:
POS machine controls the vector fonts processing thread and judges whether correct print queue only has an element, if judgement Correct print queue is not an only element out, then then judges whether print data has been disposed, if judging to beat Printing is then arranged global flag position, notifies the printing thread to terminate backed off after random in print job, simultaneously according to being disposed Discharge mutual exclusion lock;
POS machine controls the vector fonts processing thread and judges whether correct print queue only has an element, if judgement Correct print queue only has an element out, then by the readable conditional-variable of print queue by the printing thread wakening, then Judge whether print data has been disposed, print data has been disposed if judging, global flag position is arranged, and leads to Know that the printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
Wherein, the POS machine synchronizes the printing thread, comprising:
POS machine controls the printing thread and obtains print data from the print queue, attempts to obtain mutual exclusion lock, if nothing Method obtains mutual exclusion lock, then blocks the printing thread, and the vector fonts processing thread occupies mutual exclusion lock at this time, until the vector Font processing thread actively discharges mutual exclusion lock, wakes up the printing thread;
POS machine controls the printing thread and judges whether the print queue is empty, comprising:
POS machine controls the printing thread and judges whether the print queue is sky, if judging the print queue not When for sky, then the printing thread takes out print data from the print queue head and executes printing, the printing thread Then judge whether correct print queue only remains a vacancy, correct print queue only remains a vacancy if judging, described It prints thread and the vector fonts processing thread is waken up by the writeable conditional-variable of print queue, the printing thread then judges Whether print data handles the state of the global flag position of completion, decides whether to exit according to the state of the global flag position Print thread, judge print data whether handle the global flag position of completion state be processing complete when, the printing Thread terminates backed off after random in print job, while discharging mutual exclusion lock;
POS machine controls the printing thread and judges whether the print queue is sky, if judging, the print queue is When empty, then block the printing thread, waits the vector fonts to handle thread wakening by the readable conditional-variable of print queue, directly Thread wakening is handled to the vector fonts and discharges mutual exclusion lock, then the printing thread takes out from the print queue head and prints Data simultaneously execute printing, and the printing thread then judges whether correct print queue only remains a vacancy, if judging Correct print queue only remains a vacancy, then the printing thread wakes up the vector font by the writeable conditional-variable of print queue Body handles thread, and the printing thread then judges whether print data handles the state of the global flag position of completion, according to institute The state of global flag position is stated to decide whether to exit printing thread, is judging whether print data handles the global mark of completion When the state of will position is that processing is completed, the printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
Wherein, after the information that the POS machine prints the print queue, further includes:
POS machine backs up the print queue.
According to another aspect of the present invention, a kind of POS machine is provided, comprising:
Decomposing module, synchronization module, placement module and print module;
The decomposing module, for vector fonts processing thread to be resolved into the processing of vector fonts and print procedure and beaten Print thread totally two mutually independent threads;
The synchronization module, for synchronizing the vector fonts processing thread and the printing thread;Wherein, the vector By mutual exclusion lock, conditional-variable, global flag bit synchronization between Font processing thread and the printing thread, pass through round-robin queue Shared print data, each element in the round-robin queue include bitmap data to be printed, print span, printing height and Print offset information;
The placement module is used for after the vector fonts handles the complete vector fonts data of thread process, described in control Vector fonts handles thread and print data is placed into print queue;
The print module prints the information of the print queue for controlling printing thread.
Wherein, the synchronization module, is specifically used for:
Using mutual exclusion lock and conditional-variable and global flag position mode, the vector fonts processing thread and described is synchronized Print thread.
Wherein, the synchronization module, is specifically used for:
When controlling vector fonts processing thread and being put into print data into print queue, attempt to obtain mutual exclusion lock, if Mutual exclusion lock can not be obtained, then blocks vector fonts processing thread, the printing thread occupies mutual exclusion lock at this time, beats until described Print thread actively discharges mutual exclusion lock, wakes up the vector fonts processing thread;
It controls the vector fonts processing thread and judges whether print queue has expired, if print queue is less than, toward printing Print data is stored in rear of queue;
It controls the vector fonts processing thread and judges whether correct print queue only has an element, comprising:
It controls the vector fonts processing thread and judges whether correct print queue only has an element, if judging current Print queue is not an only element, then then judges whether print data has been disposed, if judging print data It has been be disposed that, then global flag position is set, the printing thread is notified to terminate backed off after random in print job, while having discharged mutual Reprimand lock;
It controls the vector fonts processing thread and judges whether correct print queue only has an element, if judging current Print queue only has an element, then by the readable conditional-variable of print queue by the printing thread wakening, then judgement is beaten Whether printing is according to being disposed, if judging, print data has been disposed, and is arranged global flag position, described in notice Printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
Wherein, the synchronization module, is specifically used for:
It controls the printing thread and obtains print data from the print queue, attempt to obtain mutual exclusion lock, if can not obtain Mutual exclusion lock is taken, then blocks the printing thread, the vector fonts processing thread occupies mutual exclusion lock at this time, until the vector fonts Processing thread actively discharges mutual exclusion lock, wakes up the printing thread;
It controls the printing thread and judges whether the print queue is empty, comprising:
It controls the printing thread and judges whether the print queue is empty, if it is empty for judging the print queue not When, then the printing thread takes out print data from the print queue head and executes printing, and the printing thread is then Judge whether correct print queue only remains a vacancy, correct print queue only remains a vacancy, the printing if judging Thread wakes up the vector fonts by the writeable conditional-variable of print queue and handles thread, and the printing thread then judges to print Whether data handle the state of the global flag position of completion, decide whether to exit printing according to the state of the global flag position Thread, judge print data whether handle the global flag position of completion state be processing complete when, the printing thread Terminate backed off after random in print job, while discharging mutual exclusion lock;
It controls the printing thread and judges whether the print queue is empty, if judge that the print queue is empty, Then block the printing thread, waits the vector fonts to handle thread wakening, Zhi Daosuo by the readable conditional-variable of print queue It states vector fonts processing thread wakening and discharges mutual exclusion lock, then the printing thread takes out print data from the print queue head And printing is executed, the printing thread then judges whether correct print queue only remains a vacancy, if judging current Print queue only remains a vacancy, then the printing thread is waken up at the vector fonts by the writeable conditional-variable of print queue Lineation journey, the printing thread then judge whether print data handles the state of the global flag position of completion, according to described complete The state of office's flag bit decides whether to exit printing thread, is judging whether print data handles the global flag position of completion State be processing complete when, the printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
Wherein, the POS machine, further includes:
Backup module, for backing up the print queue.
It can be found that above scheme, POS machine can be resolved into the processing of vector fonts and print procedure at vector fonts Lineation journey and printing thread totally two mutually independent threads, and then vector fonts processing thread and the printing thread are synchronized, And then after vector fonts handles the complete vector fonts data of thread process, controls vector fonts processing thread and put print data Print queue is set, and then controls the information that printing thread prints the print queue, POS machine is can be realized and introduces Multi-thread synchronization Mechanism optimization vector fonts printing type, printing is smooth, and print speed is fast.
Further, above scheme, POS machine can be realized POS machine energy backup print queue with backup print queue, When needing to be applied to the print queue, the print queue, the user-friendly printing can be restored from the Backup Data Queue improves user experience.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this Some embodiments of invention for those of ordinary skill in the art without creative efforts, can be with It obtains other drawings based on these drawings.
Fig. 1 is the flow diagram of one embodiment of Multithread Synchronization Program the present invention is based on POS machine;
Fig. 2 is that the present invention is based on the flow diagrams of another embodiment of the Multithread Synchronization Program of POS machine;
Fig. 3 is the structural schematic diagram of one embodiment of POS machine of the present invention;
Fig. 4 is the structural schematic diagram of another embodiment of POS machine of the present invention;
Fig. 5 is the structural schematic diagram of the another embodiment of POS machine of the present invention.
Specific embodiment
With reference to the accompanying drawings and examples, the present invention is described in further detail.It is emphasized that following implement Example is merely to illustrate the present invention, but is not defined to the scope of the present invention.Likewise, following embodiment is only portion of the invention Point embodiment and not all embodiments, institute obtained by those of ordinary skill in the art without making creative efforts There are other embodiments, shall fall within the protection scope of the present invention.
The present invention provides a kind of Multithread Synchronization Program based on POS machine, can be realized POS machine and introduces Multi-thread synchronization machine System optimization vector fonts printing type, printing is smooth, and print speed is fast.
Referring to Figure 1, Fig. 1 is the flow diagram of one embodiment of Multithread Synchronization Program the present invention is based on POS machine.It needs It is noted that if having substantially the same as a result, method of the invention is not limited with process sequence shown in FIG. 1.Such as Fig. 1 institute Show, this method comprises the following steps:
The processing of vector fonts and print procedure are resolved into vector fonts processing thread and printing thread by S101:POS machine Totally two mutually independent threads.
S102:POS machine synchronizes vector fonts processing thread and the printing thread;Wherein, which handles thread By mutual exclusion lock, conditional-variable, global flag bit synchronization between the printing thread, print data is shared by round-robin queue, Each element in the round-robin queue includes bitmap data to be printed, print span, printing height and printing offset information etc..
Wherein, which synchronizes vector fonts processing thread and the printing thread, may include:
POS machine is made vector fonts processing thread and is somebody's turn to do using mutual exclusion lock and conditional-variable and global flag position mode Print thread synchronization.
Wherein, POS machine synchronizes vector fonts processing thread, may include:
POS machine controls the vector fonts processing thread when being put into print data into print queue, attempts to obtain mutual exclusion lock, If mutual exclusion lock can not be obtained, block vector fonts processing thread, the printing thread occupies mutual exclusion lock at this time, until the printing Thread actively discharges mutual exclusion lock, wakes up vector fonts processing thread;
POS machine controls vector fonts processing thread and judges whether print queue has expired, past to beat if print queue is less than Print data is stored in print rear of queue;
POS machine controls vector fonts processing thread and judges whether correct print queue only has an element, may include:
POS machine controls vector fonts processing thread and judges whether correct print queue only has an element, if judging Correct print queue is not an only element, then then judges whether print data has been disposed, if judging to print Data have been disposed, then global flag position is arranged, and notify the printing thread to terminate backed off after random in print job, discharge simultaneously Mutual exclusion lock;
POS machine controls vector fonts processing thread and judges whether correct print queue only has an element, if judging Correct print queue only has an element, then is then judged the printing thread wakening by the readable conditional-variable of print queue Whether print data has been disposed, if judging, print data has been disposed, and global flag position is arranged, and notice should Printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
Wherein, POS machine synchronizes the printing thread, may include:
POS machine controls the printing thread and obtains print data from the print queue, attempts to obtain mutual exclusion lock, if can not obtain Mutual exclusion lock is taken, then blocks the printing thread, the thread of vector fonts processing at this time occupies mutual exclusion lock, until vector fonts processing Thread actively discharges mutual exclusion lock, wakes up the printing thread;
POS machine controls the printing thread and judges whether the print queue is sky, may include:
POS machine controls the printing thread and judges whether the print queue is empty, if to judge the print queue not be sky, Then the printing thread takes out print data from the print queue head and executes printing, which then judges currently to beat Print whether queue only remains a vacancy, correct print queue only remains a vacancy if judging, which passes through printing The writeable conditional-variable of queue wakes up vector fonts processing thread, which then judges whether print data handles completion Global flag position state, decided whether to exit printing thread according to the state of the global flag position, judging to print The state whether data handle the global flag position of completion is when handling to complete, which terminates to retreat in print job Out, while mutual exclusion lock is discharged;
POS machine controls the printing thread and judges whether the print queue is empty, if judge that the print queue is empty, Block the printing thread, waits the vector fonts to handle thread wakening by the readable conditional-variable of print queue, until the vector Font processing thread wakening simultaneously discharges mutual exclusion lock, then the printing thread takes out print data from the print queue head and executes printing Operation, the printing thread then judge whether correct print queue only remains a vacancy, if judging, correct print queue is only remained One vacancy, then the printing thread wakes up the vector fonts by the writeable conditional-variable of print queue and handles thread, the print wire Journey then judges whether print data handles the state of the global flag position of completion, is determined according to the state of the global flag position Whether exit printing thread, judge print data whether handle the global flag position of completion state be processing complete when, The printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
In the present embodiment, mutual exclusion lock, for guaranteeing only one the thread accesses print queue of same time.
In the present embodiment, which may include readable conditional-variable and writeable conditional-variable, the readable condition Variable is used to control the read operation of print queue, which is used to control the write operation of print queue.
In the present embodiment, the global flag position prints whether thread needs to exit for judging.
S103:POS machine controls vector fonts processing after the vector fonts handles the complete vector fonts data of thread process Print data is placed into print queue by thread.
S104:POS machine control printing thread prints the information of the print queue.
Wherein, after the POS machine prints the information of the print queue, can also include:
POS machine backs up the print queue.
It can be found that in the present embodiment, the processing of vector fonts and print procedure can be resolved into vector font by POS machine Body handles thread and printing thread totally two mutually independent threads, and then synchronizes vector fonts processing thread and the print wire Journey, and then after the vector fonts handles the complete vector fonts data of thread process, controlling vector fonts processing thread will print Data are placed into print queue, and then control the information that printing thread prints the print queue, and it is multi-thread to can be realized POS machine introducing Journey synchronization mechanism optimizes vector fonts printing type, and printing is smooth, and print speed is fast.
Fig. 2 is referred to, Fig. 2 is that the present invention is based on the flow diagrams of another embodiment of the Multithread Synchronization Program of POS machine. In the present embodiment, method includes the following steps:
The processing of vector fonts and print procedure are resolved into vector fonts processing thread and printing thread by S201:POS machine Totally two mutually independent threads.
S202:POS machine synchronizes vector fonts processing thread and the printing thread;Wherein, which handles thread By mutual exclusion lock, conditional-variable, global flag bit synchronization between the printing thread, print data is shared by round-robin queue, Each element in the round-robin queue includes bitmap data to be printed, print span, printing height and printing offset information etc..
Can be as above described in S102, therefore not to repeat here.
S203:POS machine controls vector fonts processing after the vector fonts handles the complete vector fonts data of thread process Print data is placed into print queue by thread.
S204:POS machine control printing thread prints the information of the print queue.
S205:POS machine backs up the print queue.
It can be found that in the present embodiment, POS machine can be with backup print queue, and can be realized POS machine can back up printing team Column, when needing to be applied to the print queue, can restore the print queue, this user-friendly dozen from the Backup Data Queue is printed, user experience is improved.
The present invention also provides a kind of POS machine, can be realized POS machine and introduce Synchronized Mechanism for Multithread optimization vector fonts printing Mode, printing is smooth, and print speed is fast.
Fig. 3 is referred to, Fig. 3 is the structural schematic diagram of one embodiment of POS machine of the present invention.In the present embodiment, which is POS machine in above-described embodiment, the POS machine 30 include decomposing module 31, synchronization module 32, placement module 33 and print module 34。
The decomposing module 31, for vector fonts processing thread to be resolved into the processing of vector fonts and print procedure and beaten Print thread totally two mutually independent threads.
The synchronization module 32, for synchronizing vector fonts processing thread and the printing thread;Wherein, at the vector fonts By mutual exclusion lock, conditional-variable, global flag bit synchronization between lineation journey and the printing thread, pass through the shared printing of round-robin queue Data, each element in the round-robin queue include bitmap data to be printed, print span, printing height and printing offset letter Breath etc..
The placement module 33, for controlling the vector after the vector fonts handles the complete vector fonts data of thread process Print data is placed into print queue by Font processing thread.
The print module 34 prints the information of the print queue for controlling printing thread.
Optionally, the synchronization module 32, can be specifically used for:
Using mutual exclusion lock and conditional-variable and global flag position mode, vector fonts processing thread and the printing are synchronized Thread.
Optionally, the synchronization module 32, can be specifically used for:
Vector fonts processing thread is controlled when being put into print data into print queue, attempts to obtain mutual exclusion lock, if nothing Method obtains mutual exclusion lock, then blocks vector fonts processing thread, the printing thread occupies mutual exclusion lock at this time, until the printing thread Mutual exclusion lock is actively discharged, vector fonts processing thread is waken up;
It controls vector fonts processing thread and judges whether print queue has expired, if print queue is less than, toward printing team Print data is stored in column tail;
It controls vector fonts processing thread and judges whether correct print queue only has an element, may include:
It controls vector fonts processing thread and judges whether correct print queue only has an element, if judging currently to beat Printing queue is not an only element, then then judges whether print data has been disposed, if judging print data Through being disposed, then global flag position is set, notifies the printing thread to terminate backed off after random in print job, while discharging mutual exclusion Lock;
It controls vector fonts processing thread and judges whether correct print queue only has an element, if judging currently to beat Print queue only has an element, then by the readable conditional-variable of print queue by the printing thread wakening, then judgement prints number Whether according to being disposed, if judging, print data has been disposed, and global flag position is arranged, and notifies the print wire Journey terminates backed off after random in print job, while discharging mutual exclusion lock.
Optionally, the synchronization module 32, can be specifically used for:
It controls the printing thread and obtains print data from the print queue, attempt to obtain mutual exclusion lock, if can not obtain mutually Reprimand lock, then block the printing thread, and the thread of vector fonts processing at this time occupies mutual exclusion lock, until the vector fonts handles thread Mutual exclusion lock is actively discharged, the printing thread is waken up;
It controls the printing thread and judges whether the print queue is sky, may include:
It controls the printing thread and judges whether the print queue is empty, it, should if to judge the print queue not be sky Printing thread takes out print data from the print queue head and executes printing, which then judges currently to print team Whether column only remain a vacancy, if judging, correct print queue only remains a vacancy, which passes through print queue Writeable conditional-variable wakes up vector fonts processing thread, which then judges whether print data handles the complete of completion The state of office's flag bit, decides whether to exit printing thread according to the state of the global flag position, is judging print data When whether the state for the global flag position that processing is completed is processing completion, which terminates backed off after random in print job, together When discharge mutual exclusion lock;
It controls the printing thread and judges whether the print queue is empty, if judge that the print queue is empty, block The printing thread waits the vector fonts to handle thread wakening, until the vector fonts by the readable conditional-variable of print queue Processing thread wakening simultaneously discharges mutual exclusion lock, then the printing thread takes out print data from the print queue head and executes printing behaviour Make, which then judges whether correct print queue only remains a vacancy, if judging, correct print queue only remains one A vacancy, then the printing thread wakes up the vector fonts by the writeable conditional-variable of print queue and handles thread, the printing thread Then judge whether print data handles the state of the global flag position of completion, determined according to the state of the global flag position be It is no to exit printing thread, judge print data whether handle the global flag position of completion state be processing complete when, should Printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
Fig. 4 is referred to, Fig. 4 is the structural schematic diagram of another embodiment of POS machine of the present invention.It is different from an embodiment, this POS machine 40 described in embodiment further include: backup module 41.
The backup module 41, for backing up the print queue.
Each unit module of the POS machine 30/40 can execute respectively and correspond to step in above method embodiment, therefore herein not Each unit module is repeated, the explanation of the above corresponding step is referred to.
Fig. 5 is referred to, Fig. 5 is the structural schematic diagram of the another embodiment of POS machine of the present invention.Each unit mould of the POS machine Block can execute respectively and correspond to step in above method embodiment.Related content refers to the detailed description in the above method, This no longer goes to live in the household of one's in-laws on getting married and chats.
In the present embodiment, the POS machine include: processor 51, the memory 52 coupled with the processor 51, printer 53, Backup device 54.
The processor 51, for vector fonts processing thread and printing to be resolved into the processing of vector fonts and print procedure Thread totally two mutually independent threads, and vector fonts processing thread and the printing thread are synchronized, and in the vector font After body handles the complete vector fonts data of thread process, vector fonts processing thread is controlled by print data and is placed into printing team Column;Wherein, pass through mutual exclusion lock, conditional-variable, global flag bit synchronization between vector fonts processing thread and the printing thread, Share print data by round-robin queue, each element in the round-robin queue include bitmap data to be printed, print span, Printing height and printing offset information etc..
The memory 52, the instruction etc. executed for storage program area, the processor 51.
The printer 53 prints the information of the print queue for controlling printing thread.
The backup device 54, for backing up the print queue.
Optionally, the processor 51, can be specifically used for:
Using mutual exclusion lock and conditional-variable and global flag position mode, vector fonts processing thread and the printing are synchronized Thread.
Optionally, the processor 51, can be specifically used for:
Vector fonts processing thread is controlled when being put into print data into print queue, attempts to obtain mutual exclusion lock, if nothing Method obtains mutual exclusion lock, then blocks vector fonts processing thread, the printing thread occupies mutual exclusion lock at this time, until the printing thread Mutual exclusion lock is actively discharged, vector fonts processing thread is waken up;
It controls vector fonts processing thread and judges whether print queue has expired, if print queue is less than, toward printing team Print data is stored in column tail;
It controls vector fonts processing thread and judges whether correct print queue only has an element, may include:
It controls vector fonts processing thread and judges whether correct print queue only has an element, if judging currently to beat Printing queue is not an only element, then then judges whether print data has been disposed, if judging print data Through being disposed, then global flag position is set, notifies the printing thread to terminate backed off after random in print job, while discharging mutual exclusion Lock;
It controls vector fonts processing thread and judges whether correct print queue only has an element, if judging currently to beat Print queue only has an element, then by the readable conditional-variable of print queue by the printing thread wakening, then judgement prints number Whether according to being disposed, if judging, print data has been disposed, and global flag position is arranged, and notifies the print wire Journey terminates backed off after random in print job, while discharging mutual exclusion lock.
Optionally, the processor 51, can be specifically used for:
It controls the printing thread and obtains print data from the print queue, attempt to obtain mutual exclusion lock, if can not obtain mutually Reprimand lock, then block the printing thread, and the thread of vector fonts processing at this time occupies mutual exclusion lock, until the vector fonts handles thread Mutual exclusion lock is actively discharged, the printing thread is waken up;
It controls the printing thread and judges whether the print queue is sky, may include:
It controls the printing thread and judges whether the print queue is empty, it, should if to judge the print queue not be sky Printing thread takes out print data from the print queue head and executes printing, which then judges currently to print team Whether column only remain a vacancy, if judging, correct print queue only remains a vacancy, which passes through print queue Writeable conditional-variable wakes up vector fonts processing thread, which then judges whether print data handles the complete of completion The state of office's flag bit, decides whether to exit printing thread according to the state of the global flag position, is judging print data When whether the state for the global flag position that processing is completed is processing completion, which terminates backed off after random in print job, together When discharge mutual exclusion lock;
It controls the printing thread and judges whether the print queue is empty, if judge that the print queue is empty, block The printing thread waits the vector fonts to handle thread wakening, until the vector fonts by the readable conditional-variable of print queue Processing thread wakening simultaneously discharges mutual exclusion lock, then the printing thread takes out print data from the print queue head and executes printing behaviour Make, which then judges whether correct print queue only remains a vacancy, if judging, correct print queue only remains one A vacancy, then the printing thread wakes up the vector fonts by the writeable conditional-variable of print queue and handles thread, the printing thread Then judge whether print data handles the state of the global flag position of completion, determined according to the state of the global flag position be It is no to exit printing thread, judge print data whether handle the global flag position of completion state be processing complete when, should Printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
It can be found that above scheme, POS machine can be resolved into the processing of vector fonts and print procedure at vector fonts Lineation journey and printing thread totally two mutually independent threads, and then vector fonts processing thread and the printing thread are synchronized, And then after the vector fonts handles the complete vector fonts data of thread process, vector fonts processing thread is controlled by print data It is placed into print queue, and then controls the information that printing thread prints the print queue, it is same to can be realized POS machine introducing multithreading Mechanism optimization vector fonts printing type is walked, printing is smooth, and print speed is fast.
Further, above scheme, POS machine can be realized POS machine energy backup print queue with backup print queue, When needing to be applied to the print queue, the print queue, the user-friendly printing can be restored from the Backup Data Queue improves user experience.
In several embodiments provided by the present invention, it should be understood that disclosed system, device and method can To realize by another way.For example, device embodiments described above are only schematical, for example, module or The division of unit, only a kind of logical function partition, there may be another division manner in actual implementation, such as multiple units Or component can be combined or can be integrated into another system, or some features can be ignored or not executed.Another point, institute Display or the mutual coupling, direct-coupling or communication connection discussed can be through some interfaces, device or unit Indirect coupling or communication connection can be electrical property, mechanical or other forms.
Unit may or may not be physically separated as illustrated by the separation member, shown as a unit Component may or may not be physical unit, it can and it is in one place, or may be distributed over multiple networks On unit.It can select some or all of unit therein according to the actual needs to realize the mesh of present embodiment scheme 's.
In addition, each functional unit in each embodiment of the present invention can integrate in one processing unit, it can also To be that each unit physically exists alone, can also be integrated in one unit with two or more units.It is above-mentioned integrated Unit both can take the form of hardware realization, can also realize in the form of software functional units.
It, can if integrated unit is realized in the form of SFU software functional unit and when sold or used as an independent product To be stored in a computer readable storage medium.Based on this understanding, technical solution of the present invention substantially or Say that all or part of the part that contributes to existing technology or the technical solution can embody in the form of software products Out, which is stored in a storage medium, including some instructions are used so that a computer equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute each implementation of the present invention The all or part of the steps of methods.And storage medium above-mentioned include: USB flash disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic or disk etc. it is various It can store the medium of program code.
The foregoing is merely section Examples of the invention, are not intended to limit protection scope of the present invention, all utilizations Equivalent device made by description of the invention and accompanying drawing content or equivalent process transformation are applied directly or indirectly in other correlations Technical field, be included within the scope of the present invention.

Claims (10)

1. a kind of Multithread Synchronization Program based on POS machine characterized by comprising
POS machine by the processing of vector fonts and print procedure resolve into vector fonts processing thread and printing thread totally two mutually Independent thread;
Synchronize the vector fonts processing thread and the printing thread;Wherein, it vector fonts processing thread and described beats It prints between thread through mutual exclusion lock, conditional-variable, global flag bit synchronization, print data is shared by round-robin queue, it is described to follow Each element in ring queue includes bitmap data to be printed, print span, printing height and printing offset information;
After the vector fonts handles the complete vector fonts data of thread process, controlling the vector fonts processing thread will be printed Data are placed into print queue;
Control printing thread prints the information of the print queue.
2. as described in claim 1 based on the Multithread Synchronization Program of POS machine, which is characterized in that the POS machine synchronizes described Vector fonts handles thread and the printing thread, comprising:
POS machine is using mutual exclusion lock vector fonts processing thread synchronous with conditional-variable and global flag position mode and described Print thread.
3. as claimed in claim 1 or 2 based on the Multithread Synchronization Program of POS machine, which is characterized in that the POS machine is synchronous The vector fonts handles thread, comprising:
When the POS machine control vector fonts processing thread is put into print data into print queue, attempt to obtain mutual exclusion lock, if Mutual exclusion lock can not be obtained, then blocks vector fonts processing thread, the printing thread occupies mutual exclusion lock at this time, beats until described Print thread actively discharges mutual exclusion lock, wakes up the vector fonts processing thread;
POS machine controls the vector fonts processing thread and judges whether print queue has expired, if print queue is less than, toward printing Print data is stored in rear of queue;
POS machine controls the vector fonts processing thread and judges whether correct print queue only has an element, comprising:
POS machine controls the vector fonts processing thread and judges whether correct print queue only has an element, if judging to work as Preceding print queue is not an only element, then then judges whether print data has been disposed, if judging to print number According to being disposed, then global flag position is set, notifies the printing thread to terminate backed off after random in print job, discharges simultaneously Mutual exclusion lock;
POS machine controls the vector fonts processing thread and judges whether correct print queue only has an element, if judging to work as Preceding print queue only has an element, then is then judged the printing thread wakening by the readable conditional-variable of print queue Whether print data has been disposed, if judging, print data has been disposed, and global flag position is arranged, and notifies institute Stating printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
4. as claimed in claim 3 based on the Multithread Synchronization Program of POS machine, which is characterized in that the POS machine synchronizes described Print thread, comprising:
POS machine controls the printing thread and obtains print data from the print queue, attempts to obtain mutual exclusion lock, if can not obtain Mutual exclusion lock is taken, then blocks the printing thread, the vector fonts processing thread occupies mutual exclusion lock at this time, until the vector fonts Processing thread actively discharges mutual exclusion lock, wakes up the printing thread;
POS machine controls the printing thread and judges whether the print queue is empty, comprising:
POS machine controls the printing thread and judges whether the print queue is empty, if it is empty for judging the print queue not When, then the printing thread takes out print data from the print queue head and executes printing, and the printing thread is then Judge whether correct print queue only remains a vacancy, correct print queue only remains a vacancy, the printing if judging Thread wakes up the vector fonts by the writeable conditional-variable of print queue and handles thread, and the printing thread then judges to print Whether data handle the state of the global flag position of completion, decide whether to exit printing according to the state of the global flag position Thread, judge print data whether handle the global flag position of completion state be processing complete when, the printing thread Terminate backed off after random in print job, while discharging mutual exclusion lock;
POS machine controls the printing thread and judges whether the print queue is empty, if judge that the print queue is empty, Then block the printing thread, waits the vector fonts to handle thread wakening, Zhi Daosuo by the readable conditional-variable of print queue It states vector fonts processing thread wakening and discharges mutual exclusion lock, then the printing thread takes out print data from the print queue head And printing is executed, the printing thread then judges whether correct print queue only remains a vacancy, if judging current Print queue only remains a vacancy, then the printing thread handles line by vector fonts described in the writeable conditional-variable of print queue Journey, the printing thread then judge whether print data handles the state of the global flag position of completion, according to the global mark The state of will position decides whether to exit printing thread, is judging whether print data handles the shape of the global flag position of completion When state is that processing is completed, the printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
5. as claimed in claim 4 based on the Multithread Synchronization Program of POS machine, which is characterized in that print institute in the POS machine After the information for stating print queue, further includes:
POS machine backs up the print queue.
6. a kind of POS machine characterized by comprising
Decomposing module, synchronization module, placement module and print module;
The decomposing module, for vector fonts processing thread and print wire to be resolved into the processing of vector fonts and print procedure Journey totally two mutually independent threads;
The synchronization module, for synchronizing the vector fonts processing thread and the printing thread;Wherein, the vector fonts It handles by mutual exclusion lock, conditional-variable, global flag bit synchronization between thread and the printing thread, it is shared by round-robin queue Print data, each element in the round-robin queue include bitmap data to be printed, print span, printing height and printing Offset information;
The placement module, for controlling the vector after the vector fonts handles the complete vector fonts data of thread process Print data is placed into print queue by Font processing thread;
The print module prints the information of the print queue for controlling printing thread.
7. POS machine as claimed in claim 6, which is characterized in that the synchronization module is specifically used for:
Using mutual exclusion lock and conditional-variable and global flag position mode, the vector fonts processing thread and the printing are synchronized Thread.
8. POS machine as claimed in claims 6 or 7, which is characterized in that the synchronization module is specifically used for:
When controlling vector fonts processing thread and being put into print data into print queue, attempt to obtain mutual exclusion lock, if can not Mutual exclusion lock is obtained, then blocks vector fonts processing thread, the printing thread occupies mutual exclusion lock at this time, until the print wire Journey actively discharges mutual exclusion lock, wakes up the vector fonts processing thread;
It controls the vector fonts processing thread and judges whether print queue has expired, if print queue is less than, toward print queue Print data is stored in tail;
It controls the vector fonts processing thread and judges whether correct print queue only has an element, comprising:
It controls the vector fonts processing thread and judges whether correct print queue only has an element, if judging currently to print Queue is not an only element, then then judges whether print data has been disposed, if judging print data It is disposed, then global flag position is set, notify the printing thread to terminate backed off after random in print job, while discharging mutual exclusion Lock;
It controls the vector fonts processing thread and judges whether correct print queue only has an element, if judging currently to print Queue only has an element, then by the readable conditional-variable of print queue by the printing thread wakening, then judgement prints number Whether according to being disposed, if judging, print data has been disposed, and global flag position is arranged, and notifies the printing Thread terminates backed off after random in print job, while discharging mutual exclusion lock.
9. POS machine as claimed in claim 8, which is characterized in that the synchronization module is specifically used for:
It controls the printing thread and obtains print data from the print queue, attempt to obtain mutual exclusion lock, if can not obtain mutually Reprimand lock, then block the printing thread, and the vector fonts processing thread occupies mutual exclusion lock at this time, until vector fonts processing Thread actively discharges mutual exclusion lock, wakes up the printing thread;
It controls the printing thread and judges whether the print queue is empty, comprising:
It controls the printing thread and judges whether the print queue is empty, if to judge the print queue not be sky, The printing thread takes out print data from the print queue head and executes printing, and the printing thread then judges to work as Whether preceding print queue only remains a vacancy, if judging, correct print queue only remains a vacancy, and the printing thread is logical It crosses the writeable conditional-variable of print queue and wakes up the vector fonts processing thread, the printing thread then judges that print data is The state for the global flag position that no processing is completed, decides whether to exit printing thread according to the state of the global flag position, Judge print data whether handle the global flag position of completion state be processing complete when, the printing thread is printing Work terminates backed off after random, while discharging mutual exclusion lock;
It controls the printing thread and judges whether the print queue is empty, if judge that the print queue is empty, hinder The printing thread is filled in, waits the vector fonts to handle thread wakening by the readable conditional-variable of print queue, until the arrow Amount Font processing thread wakening simultaneously discharges mutual exclusion lock, then the printing thread takes out print data from the print queue head and holds Row printing, the printing thread then judge whether correct print queue only remains a vacancy, if judging currently to print Queue only remains a vacancy, then the printing thread wakes up the vector fonts by the writeable conditional-variable of print queue and handles line Journey, the printing thread then judge whether print data handles the state of the global flag position of completion, according to the global mark The state of will position decides whether to exit printing thread, is judging whether print data handles the shape of the global flag position of completion When state is that processing is completed, the printing thread terminates backed off after random in print job, while discharging mutual exclusion lock.
10. POS machine as claimed in claim 9, which is characterized in that the POS machine, further includes:
Backup module, for backing up the print queue.
CN201811572525.7A 2018-12-21 2018-12-21 Multithreading synchronization method based on POS machine and POS machine Active CN109783142B (en)

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 true CN109783142A (en) 2019-05-21
CN109783142B 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)

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1658145A (en) * 2004-02-13 2005-08-24 微软公司 Scalable print spooler
CN1934531A (en) * 2004-03-26 2007-03-21 佳能株式会社 Image processing apparatus, image processing control method, program, and storage medium
US20120156339A1 (en) * 2010-12-16 2012-06-21 Studor Charles F Apparatus and Method for Brewed and Espresso Drink Generation
CN102756572A (en) * 2011-04-28 2012-10-31 精工爱普生株式会社 Recording device, recording device control method, and storage medium storing a program
CN102922887A (en) * 2011-04-28 2013-02-13 精工爱普生株式会社 Recording device, recording device control method
CN103488441A (en) * 2013-09-06 2014-01-01 深圳市新国都技术股份有限公司 Implementation method for printing Arabic on POS (point-of-sale) terminals
CN103631665A (en) * 2013-12-12 2014-03-12 北京奇虎科技有限公司 Method and system for cross-thread communication based on message queue
CN105045545A (en) * 2011-02-10 2015-11-11 精工爱普生株式会社 Control method for network system, client terminal and device server
CN105139060A (en) * 2015-09-15 2015-12-09 歌尔声学股份有限公司 Generation and testing method and system of bar codes based on a plurality of print devices
CN105607904A (en) * 2015-12-18 2016-05-25 南京熊猫电子股份有限公司 Linux platform-based rapid development framework of communication software and using method thereof
CN107562480A (en) * 2017-09-05 2018-01-09 深圳市新国都支付技术有限公司 A kind of POS multi-lingual implementation method and its system
CN107678701A (en) * 2017-06-12 2018-02-09 平安科技(深圳)有限公司 Device, method and the computer-readable recording medium of document printing

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1658145A (en) * 2004-02-13 2005-08-24 微软公司 Scalable print spooler
CN1934531A (en) * 2004-03-26 2007-03-21 佳能株式会社 Image processing apparatus, image processing control method, program, and storage medium
US20120156339A1 (en) * 2010-12-16 2012-06-21 Studor Charles F Apparatus and Method for Brewed and Espresso Drink Generation
CN105045545A (en) * 2011-02-10 2015-11-11 精工爱普生株式会社 Control method for network system, client terminal and device server
CN102756572A (en) * 2011-04-28 2012-10-31 精工爱普生株式会社 Recording device, recording device control method, and storage medium storing a program
CN102922887A (en) * 2011-04-28 2013-02-13 精工爱普生株式会社 Recording device, recording device control method
CN103488441A (en) * 2013-09-06 2014-01-01 深圳市新国都技术股份有限公司 Implementation method for printing Arabic on POS (point-of-sale) terminals
CN103631665A (en) * 2013-12-12 2014-03-12 北京奇虎科技有限公司 Method and system for cross-thread communication based on message queue
CN105139060A (en) * 2015-09-15 2015-12-09 歌尔声学股份有限公司 Generation and testing method and system of bar codes based on a plurality of print devices
CN105607904A (en) * 2015-12-18 2016-05-25 南京熊猫电子股份有限公司 Linux platform-based rapid development framework of communication software and using method thereof
CN107678701A (en) * 2017-06-12 2018-02-09 平安科技(深圳)有限公司 Device, method and the computer-readable recording medium of document printing
CN107562480A (en) * 2017-09-05 2018-01-09 深圳市新国都支付技术有限公司 A kind of POS multi-lingual implementation method and its system

Also Published As

Publication number Publication date
CN109783142B (en) 2021-02-12

Similar Documents

Publication Publication Date Title
JP5839845B2 (en) Printing apparatus, printing method, and program
EP2426593A1 (en) Function expansion method using print data, function expansion device, and recording medium
US9058139B2 (en) Function expansion method using print data, and function expansion device
EP2383643B1 (en) Information processing apparatus, information processing method and program
US8659788B2 (en) Reduced printing width printer, printer control method, and operation control method
US9898691B2 (en) Control device, control system, and control method of a control device
EP2144185B1 (en) Printing control device, control method for a printing device, and a control program
CN106055282A (en) System, printing apparatus, control method thereof, post-processing apparatus and control method thereof
CN109783142A (en) A kind of Multithread Synchronization Program and POS machine based on POS machine
US10089046B2 (en) Receipt printing system, control method of a receipt printing system, and control device
CN101901341B (en) Method and equipment for extracting raster image from transportable electronic document
JP5867564B2 (en) Print data processing program for distributing output destinations, print data processing apparatus, and print data processing method
US10692257B2 (en) Process management apparatus, process management method, and storage medium
CN102378005B (en) Motion picture processing device and motion image processing method
CN102825925A (en) Duplex printing control method and device and duplex printing system
CN109887197A (en) A kind of vector fonts Method of printing and POS machine based on POS machine
CN115454360A (en) Label printing method, device and medium capable of flexibly adjusting printing format
US20030142353A1 (en) Printing device having memory usage indicator
CN109816896A (en) A kind of multithreading Method of printing and POS machine based on POS machine
JP2012058846A (en) Print data processing program for distributing output destination, print data processing device, and print data processing method
JP5736851B2 (en) Sales analysis program using print data, sales information acquisition device, and sales information acquisition method
JP3771418B2 (en) Print control apparatus and recording medium
Fernandes et al. Job profiling and queue management in high performance printing
CN112183040B (en) Voucher generation method and related device
JP4594812B2 (en) Printing system, printing request apparatus control method, program, and printing request apparatus

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