CN106802833A - A kind of producer consumer model-based optimization method and system - Google Patents

A kind of producer consumer model-based optimization method and system Download PDF

Info

Publication number
CN106802833A
CN106802833A CN201710042278.9A CN201710042278A CN106802833A CN 106802833 A CN106802833 A CN 106802833A CN 201710042278 A CN201710042278 A CN 201710042278A CN 106802833 A CN106802833 A CN 106802833A
Authority
CN
China
Prior art keywords
producer
consumer
data
message
buffer cell
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.)
Pending
Application number
CN201710042278.9A
Other languages
Chinese (zh)
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.)
Zhengzhou Yunhai Information Technology Co Ltd
Original Assignee
Zhengzhou Yunhai Information 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 Zhengzhou Yunhai Information Technology Co Ltd filed Critical Zhengzhou Yunhai Information Technology Co Ltd
Priority to CN201710042278.9A priority Critical patent/CN106802833A/en
Publication of CN106802833A publication Critical patent/CN106802833A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/543User-generated data transfer, e.g. clipboards, dynamic data exchange [DDE], object linking and embedding [OLE]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

This application discloses a kind of producer consumer model-based optimization method and system, the method includes:If producer's process attempts write-in new data, then determine whether possess null message buffer cell in current producer's process, if current producer's process possesses null message buffer cell, then by producer's process to writing new data in null message buffer cell, corresponding data-message is obtained, and the data-message that will be obtained is sent to consumer process;If consumer process attempts taking out data, then determine whether possess the data-message that producer's process sends in current consumer's process, if current consumer's process possesses the data-message of producer's process transmission, corresponding data are then extracted from data-message by consumer process, and corresponding null message buffer cell is obtained, the null message buffer cell that then will be obtained is transferred to producer's process.The application can be prevented effectively from producer consumer pattern the data access anomaly caused by contention for resource.

Description

A kind of producer consumer model-based optimization method and system
Technical field
The present invention relates to data access technology field, more particularly to a kind of producer consumer model-based optimization method and it is System.
Background technology
Currently, in producer consumer pattern, the producer is used to place the message in buffering area, and consumer be then used for from Message is taken out in buffering area.That is, in producer consumer pattern, the DAO of producers and consumers is same One buffering area.Producer's process and consumer process when data write operation is carried out to buffering area or data take out operation, Corresponding operating result depends on above two process relative time in the process of implementation, namely depends on above-mentioned two process Instruction execution sequence, in this process, it is easy to occur because producer's process and consumer process in buffering area to providing The data access anomaly that source is fought for and triggered.
To sum up, how to avoid the data access anomaly in producer consumer pattern caused by contention for resource is There is problem to be solved at present.
The content of the invention
In view of this, it is an object of the invention to provide a kind of producer consumer model-based optimization method and system, can Avoid the data access anomaly caused by contention for resource in producer consumer pattern.Its concrete scheme is as follows:
A kind of producer consumer model-based optimization method, including:
If producer's process attempts write-in new data, it is determined that whether possess null message buffering in current producer's process single Unit, if current producer's process possesses null message buffer cell, is write by producer's process in null message buffer cell New data, obtains corresponding data-message, and the data-message that will be obtained is sent to consumer process;
If consumer process attempts taking out data, it is determined that whether possess the transmission of producer's process in current consumer's process Data-message, if current consumer's process possess the producer's process transmission data-message, by consumer process from number According to extracting corresponding data in message, and corresponding null message buffer cell is obtained, the null message buffering that then will be obtained is single Unit is transferred to producer's process;
Wherein, in initial phase, all null message buffer cells in destination buffer are passed by consumer process It is handed to producer's process.
Optionally, the null message buffer cell for determining whether to possess consumer process's transmission in current producer's process Process after, also include:
If current producer's process does not possess null message buffer cell, control producer's process enters waiting process, with Consumer process is waited to transmit null message buffer cell to producer's process.
Optionally, the mistake of the data-message for determining whether to possess the transmission of producer's process in current consumer's process Journey, including:
If current consumer's process does not possess the data-message of producer's process transmission, control consumer process to enter etc. Process is treated, to wait producer's process to send data-message to consumer process.
The present invention further correspondingly discloses a kind of producer consumer model-based optimization system, including:
Producer's management module, for attempting write-in new data when producer's process, it is determined that in current producer's process Whether possess null message buffer cell, if current producer's process possesses null message buffer cell, by producer's process to New data is write in null message buffer cell, corresponding data-message is obtained, and the data-message that will be obtained is sent to consumer Process;
Consumer's management module, for attempting taking out data as consumer process, it is determined that be in current consumer's process The no data-message for possessing the transmission of producer's process, if current consumer's process possesses the data-message of producer's process transmission, Corresponding data are then extracted from data-message by consumer process, and obtains corresponding null message buffer cell, then The null message buffer cell that will be obtained is transferred to producer's process;
Wherein, consumer's management module, is additionally operable in initial phase, by consumer process by destination buffer In all null message buffer cells be transferred to producer's process.
Optionally, producer's management module, is additionally operable in the case where producer's process attempts write-in new data, if Current producer's process does not possess null message buffer cell, then control producer's process to enter waiting process, to wait consumer Process transmits null message buffer cell to producer's process.
Optionally, consumer's management module, is additionally operable in the case where consumer process attempts taking out data, if working as Preceding consumer process does not possess the data-message of producer's process transmission, then control consumer process to enter waiting process, with etc. Person's process to be produced sends data-message to consumer process.
In the present invention, producer consumer model-based optimization method, including:If producer's process attempts write-in new data, It is determined that whether possess null message buffer cell in current producer's process, if current producer's process possesses null message buffering list Unit, then by producer's process to new data is write in null message buffer cell, obtain corresponding data-message, and will obtain Data-message is sent to consumer process;If consumer process attempt take out data, it is determined that in current consumer's process whether Possess the data-message of producer's process transmission, if current consumer's process possesses the data-message of producer's process transmission, Corresponding data are extracted from data-message by consumer process, and obtains corresponding null message buffer cell, then will The null message buffer cell for obtaining is transferred to producer's process;Wherein, in initial phase, target is delayed by consumer process The all null message buffer cells rushed in area are transferred to producer's process.
It can be seen that, the present invention is buffered all null messages in destination buffer by consumer process in initial phase single Unit is transferred to producer's process, and then attempts write-in new data in producer's process, and current producer's process possesses sky and disappears In the case of breath buffer cell, by producer's process to new data is write in null message buffer cell, corresponding data are obtained Message, and the data-message that will be obtained sent to consumer process;And attempt taking out data in consumer process, and currently disappear In the case that expense person's process possesses the data-message of producer's process transmission, extracted from data-message by consumer process Corresponding data, and corresponding null message buffer cell is obtained, the null message buffer cell that then will be obtained is transferred to the producer Process, by said process, can be prevented effectively from producer consumer pattern the data access caused by contention for resource Anomaly.
Brief description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing The accompanying drawing to be used needed for having technology description is briefly described, it should be apparent that, drawings in the following description are only this Inventive embodiment, for those of ordinary skill in the art, on the premise of not paying creative work, can also basis The accompanying drawing of offer obtains other accompanying drawings.
Fig. 1 is a kind of producer consumer model-based optimization method flow diagram disclosed in the embodiment of the present invention;
Fig. 2 is a kind of producer consumer model-based optimization system structure diagram disclosed in the embodiment of the present invention.
Specific embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out clear, complete Site preparation is described, it is clear that described embodiment is only a part of embodiment of the invention, rather than whole embodiments.It is based on Embodiment in the present invention, it is every other that those of ordinary skill in the art are obtained under the premise of creative work is not made Embodiment, belongs to the scope of protection of the invention.
It is shown in Figure 1 the embodiment of the invention discloses a kind of producer consumer model-based optimization method, the method bag Include:
Step S11:If producer's process attempts write-in new data, it is determined that whether possess sky in current producer's process and disappear Breath buffer cell, if current producer's process possesses null message buffer cell, is buffered single by producer's process to null message New data is write in unit, corresponding data-message is obtained, and the data-message that will be obtained is sent to consumer process;
Step S12:If whether consumer process attempts taking out data, it is determined that possess the producer in current consumer's process The data-message that process sends, if current consumer's process possesses the data-message of producer's process transmission, by consumer Process extracts corresponding data from data-message, and obtains corresponding null message buffer cell, and the sky that then will be obtained disappears Breath buffer cell is transferred to producer's process;
Wherein, in initial phase, all null message buffer cells in destination buffer are passed by consumer process It is handed to producer's process.
It should be noted that the entire message buffer cell in initial phase, above-mentioned destination buffer is empty, Namely, it is assumed that the quantity of the message format unit in above-mentioned destination buffer is N, then in initial phase, destination buffer The quantity of null message buffer cell is N.It is understood that during the reading and writing data of the present embodiment, null message buffering The quantity sum of unit and the message format unit for having been written to data is constant, equal to N.
It can be seen that, the embodiment of the present invention passes through consumer process by all null messages in destination buffer in initial phase Buffer cell is transferred to producer's process, and then attempts write-in new data in producer's process, and current producer's process is gathered around In the case of being free message format unit, by producer's process to new data is write in null message buffer cell, obtain corresponding Data-message, and the data-message that will be obtained sent to consumer process;And attempt taking out data in consumer process, and In the case that current consumer's process possesses the data-message of producer's process transmission, by consumer process from data-message Corresponding data are extracted, and obtains corresponding null message buffer cell, the null message buffer cell that then will be obtained is transferred to Producer's process, by said process, can be prevented effectively from producer consumer pattern the number caused by contention for resource According to access exception phenomenon.
The embodiment of the invention discloses a kind of specific producer consumer model-based optimization method, implement relative to upper one Example, the present embodiment has made further instruction and optimization to technical scheme.Specifically:
In upper embodiment step S11, in the case where producer's process attempts write-in new data, it is thus necessary to determine that work as previous existence Whether possess null message buffer cell in product person's process, wherein, if current producer's process does not possess null message buffer cell, Producer's process can be then controlled to enter waiting process, to wait consumer process single to producer's process transmission null message buffering Unit.It is understood that after producer's process enters waiting process, if consumer process delivers sky to producer's process Message format unit, then can terminate the waiting process of producer's process, and allow producer's process to write new data.
In addition, in upper embodiment step S12, in the case where consumer process attempts taking out data, it is thus necessary to determine that when Whether the data-message of producer process transmission is possessed on preceding consumer process, wherein, if current consumer's process does not possess Producer's process send data-message, then consumer process can be controlled to enter waiting process, with wait producer's process to Consumer process sends data-message.It is understood that after consumer process enters waiting process, if producer's process Data-message is have sent to consumer process, then can terminate the waiting process of consumer process, and allow consumer process to take out Data.
It is accordingly, shown in Figure 2 the embodiment of the invention also discloses a kind of producer consumer model-based optimization system, The system includes:
Producer's management module 11, for attempting write-in new data when producer's process, it is determined that current producer's process On whether possess null message buffer cell, if current producer's process possesses null message buffer cell, by producer's process To new data is write in null message buffer cell, corresponding data-message is obtained, and the data-message that will be obtained is sent to consumption Person's process;
Consumer's management module 12, for attempting taking out data as consumer process, it is determined that in current consumer's process Whether the data-message of producer process transmission is possessed, if the data that current consumer's process possesses the transmission of producer's process disappear Breath, then extract corresponding data by consumer process from data-message, and obtains corresponding null message buffer cell, so The null message buffer cell that will be obtained afterwards is transferred to producer's process;
Wherein, above-mentioned consumer's management module 12, is additionally operable in initial phase, by consumer process by Target buffer All null message buffer cells in area are transferred to producer's process.
It should be noted that the entire message buffer cell in initial phase, above-mentioned destination buffer is empty, Namely, it is assumed that the quantity of the message format unit in above-mentioned destination buffer is N, then in initial phase, destination buffer The quantity of null message buffer cell is N.It is understood that during the reading and writing data of the present embodiment, null message buffering The quantity sum of unit and the message format unit for having been written to data is constant, equal to N.
Further, in the present embodiment, above-mentioned producer's management module can be also used for attempting writing in producer's process In the case of new data, if current producer's process does not possess null message buffer cell, control producer process enters wait Process, to wait consumer process to transmit null message buffer cell to producer's process.It is understood that in producer's process Into after waiting process, if consumer process delivers null message buffer cell to producer's process, the producer can be terminated The waiting process of process, and allow producer's process to write new data.
Further, in the present embodiment, above-mentioned consumer's management module can be also used for attempting taking out in consumer process In the case of data, if current consumer's process does not possess the data-message of producer's process transmission, consumer process is controlled Into waiting process, to wait producer's process to send data-message to consumer process.It is understood that entering in consumer After journey enters waiting process, if producer's process have sent data-message to consumer process, consumer process can be terminated Waiting process, and allow consumer process take out data.
It can be seen that, the embodiment of the present invention passes through consumer process by all null messages in destination buffer in initial phase Buffer cell is transferred to producer's process, and then attempts write-in new data in producer's process, and current producer's process is gathered around In the case of being free message format unit, by producer's process to new data is write in null message buffer cell, obtain corresponding Data-message, and the data-message that will be obtained sent to consumer process;And attempt taking out data in consumer process, and In the case that current consumer's process possesses the data-message of producer's process transmission, by consumer process from data-message Corresponding data are extracted, and obtains corresponding null message buffer cell, the null message buffer cell that then will be obtained is transferred to Producer's process, by said process, can be prevented effectively from producer consumer pattern the number caused by contention for resource According to access exception phenomenon.
Finally, in addition it is also necessary to explanation, herein, such as first and second or the like relational terms be used merely to by One entity or operation make a distinction with another entity or operation, and not necessarily require or imply these entities or operation Between there is any this actual relation or order.And, term " including ", "comprising" or its any other variant meaning Covering including for nonexcludability, so that process, method, article or equipment including a series of key elements not only include that A little key elements, but also other key elements including being not expressly set out, or also include for this process, method, article or The intrinsic key element of equipment.In the absence of more restrictions, the key element limited by sentence "including a ...", does not arrange Except also there is other identical element in the process including the key element, method, article or equipment.
A kind of producer consumer model-based optimization method and system provided by the present invention is described in detail above, Specific case used herein is set forth to principle of the invention and implementation method, and the explanation of above example is use Understand the method for the present invention and its core concept in help;Simultaneously for those of ordinary skill in the art, according to of the invention Thought, will change in specific embodiments and applications, and in sum, this specification content should not be construed as Limitation of the present invention.

Claims (6)

1. a kind of producer consumer model-based optimization method, it is characterised in that including:
If producer's process attempts write-in new data, it is determined that whether possess null message buffer cell in current producer's process, If current producer's process possesses null message buffer cell, by producer's process to the new number of write-in in null message buffer cell According to, corresponding data-message is obtained, and the data-message that will be obtained is sent to consumer process;
If whether consumer process attempts taking out data, it is determined that possess the number of producer's process transmission in current consumer's process According to message, if current consumer's process possesses the data-message of producer's process transmission, disappeared from data by consumer process Corresponding data are extracted in breath, and obtains corresponding null message buffer cell, the null message buffer cell that then will be obtained is passed It is handed to producer's process;
Wherein, in initial phase, all null message buffer cells in destination buffer are transferred to by consumer process Producer's process.
2. producer consumer model-based optimization method according to claim 1, it is characterised in that the determination is currently produced After the process of the null message buffer cell for whether possessing consumer process's transmission in person's process, also include:
If current producer's process does not possess null message buffer cell, control producer's process enters waiting process, to wait Consumer process transmits null message buffer cell to producer's process.
3. producer consumer model-based optimization method according to claim 1, it is characterised in that the determination current consumption Whether the process of the data-message of producer process transmission is possessed in person's process, including:
If current consumer's process does not possess the data-message of producer's process transmission, control consumer process to enter and waited Journey, to wait producer's process to send data-message to consumer process.
4. a kind of producer consumer model-based optimization system, it is characterised in that including:
Producer's management module, for attempting write-in new data when producer's process, it is determined that in current producer's process whether Possess null message buffer cell, if current producer's process possesses null message buffer cell, disappeared to sky by producer's process New data is write in breath buffer cell, corresponding data-message is obtained, and the data-message that will be obtained is sent to consumer process;
Consumer's management module, for attempting taking out data as consumer process, it is determined that whether gathered around in current consumer's process There is the data-message that producer's process sends, if current consumer's process possesses the data-message of producer's process transmission, lead to Cross consumer process and corresponding data are extracted from data-message, and obtain corresponding null message buffer cell, then incite somebody to action To null message buffer cell be transferred to producer's process;
Wherein, consumer's management module, is additionally operable in initial phase, by consumer process by destination buffer All null message buffer cells are transferred to producer's process.
5. producer consumer model-based optimization system according to claim 4, it is characterised in that
Producer's management module, is additionally operable in the case where producer's process attempts write-in new data, if the current producer Process does not possess null message buffer cell, then control producer's process to enter waiting process, to wait consumer process to production Person's process transmits null message buffer cell.
6. producer consumer model-based optimization system according to claim 4, it is characterised in that
Consumer's management module, is additionally operable in the case where consumer process attempts taking out data, if current consumer enters Cheng Wei possesses the data-message of producer's process transmission, then control consumer process to enter waiting process, to wait the producer to enter Journey sends data-message to consumer process.
CN201710042278.9A 2017-01-20 2017-01-20 A kind of producer consumer model-based optimization method and system Pending CN106802833A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710042278.9A CN106802833A (en) 2017-01-20 2017-01-20 A kind of producer consumer model-based optimization method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710042278.9A CN106802833A (en) 2017-01-20 2017-01-20 A kind of producer consumer model-based optimization method and system

Publications (1)

Publication Number Publication Date
CN106802833A true CN106802833A (en) 2017-06-06

Family

ID=58987010

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710042278.9A Pending CN106802833A (en) 2017-01-20 2017-01-20 A kind of producer consumer model-based optimization method and system

Country Status (1)

Country Link
CN (1) CN106802833A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107665243A (en) * 2017-09-11 2018-02-06 安徽慧视金瞳科技有限公司 A kind of across language environment data interactive method based on database access
CN114244797A (en) * 2021-12-17 2022-03-25 中国建设银行股份有限公司 Message processing method, device, system, equipment and medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101763289A (en) * 2009-09-25 2010-06-30 中国人民解放军国防科学技术大学 Message passing method based on shared memory
US20140237145A1 (en) * 2013-02-20 2014-08-21 International Business Machines Corporation Dual-buffer serialization and consumption of variable-length data records produced by multiple parallel threads

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101763289A (en) * 2009-09-25 2010-06-30 中国人民解放军国防科学技术大学 Message passing method based on shared memory
US20140237145A1 (en) * 2013-02-20 2014-08-21 International Business Machines Corporation Dual-buffer serialization and consumption of variable-length data records produced by multiple parallel threads

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
徐伶伶 等: "对比法在操作系统教学中的应用", 《计算机光盘软件与应用》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107665243A (en) * 2017-09-11 2018-02-06 安徽慧视金瞳科技有限公司 A kind of across language environment data interactive method based on database access
CN107665243B (en) * 2017-09-11 2021-03-09 安徽慧视金瞳科技有限公司 Cross-language environment data interaction method based on database access
CN114244797A (en) * 2021-12-17 2022-03-25 中国建设银行股份有限公司 Message processing method, device, system, equipment and medium

Similar Documents

Publication Publication Date Title
CN101272276B (en) Log management implementing method
CN109213462B (en) Android horizontal and vertical screen data synchronization method and device, terminal and readable medium
CN112947923A (en) Object editing method and device and electronic equipment
CN106802833A (en) A kind of producer consumer model-based optimization method and system
CN103618762A (en) System and method for enterprise service bus state pretreatment based on AOP
CN105045391A (en) Smart watch gesture input method and smart watch
CN100530212C (en) Bus line fire wall of embedded system
CN103488717A (en) Lock-free data gathering method and lock-free data gathering device
CN102279855A (en) Device and method for treating transactions with database
CN104331236B (en) The binding dragging method and device of a kind of multiple windows
CN107800776A (en) A kind of document handling method, terminal, server and computer-readable medium
CN106557148B (en) A kind of interface circuit, display driver, terminal device and display control method
CN102739788A (en) Field equipment communication method based on European installation bus (EIB) protocol
CN109413083A (en) A kind of intelligent station communication network shutdown data transparent transmission method and system
CN105740709A (en) Authority combination-based Android malicious software detection method
CN106896956B (en) The implementation method of multi-point touch under one kind " road " system
CN107395429A (en) The method and apparatus that virtual machine is managed in cloud data center
CN110457133A (en) A kind of processing method and system of operating-system resources exception
CN103209212A (en) Data caching method and system in Web network management client based on rich internet application (RIA)
CN103338063B (en) Android electric intelligent key and Bluetooth unlock system, as well as implementation method thereof
CN105022722B (en) A kind of electrical form ranks freezing method and device
CN103500092B (en) Judgment method for WORM appending writing and storage device
CN106648476A (en) Producer and consumer model optimization method and system
CN104182370B (en) A kind of data transmission method, device and mobile terminal
CN101697148A (en) Method and system for raising interface rate of computer memory cards

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20170606