CN103164267A - Lock-free message queue implementation method - Google Patents

Lock-free message queue implementation method Download PDF

Info

Publication number
CN103164267A
CN103164267A CN2013101067555A CN201310106755A CN103164267A CN 103164267 A CN103164267 A CN 103164267A CN 2013101067555 A CN2013101067555 A CN 2013101067555A CN 201310106755 A CN201310106755 A CN 201310106755A CN 103164267 A CN103164267 A CN 103164267A
Authority
CN
China
Prior art keywords
thread
worker
main
message
idle
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
CN2013101067555A
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.)
Opzoon Technology Co Ltd
Original Assignee
Opzoon 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 Opzoon Technology Co Ltd filed Critical Opzoon Technology Co Ltd
Priority to CN2013101067555A priority Critical patent/CN103164267A/en
Publication of CN103164267A publication Critical patent/CN103164267A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention provides a lock-free message queue implementation method. The method includes a first step of utilizing a main thread to obtain messages and storing the messages in a message queue, a second step of utilizing the main thread to detect whether an idle worker thread exists in all worker threads, if the idle worker thread does not exist, continuing detecting all the worker threads until the idle worker thread is detected, and if the idle worker thread exists, skipping to a third step, the third step of utilizing the main thread to transmit the messages to the idle worker thread, wherein the idle worker thread receives and processes the messages, and the idle worker thread is changed to the worker thread, and a fourth step of transmitting an idle signal to the main thread after the worker threads complete processing of the messages. The lock-free message queue implementation method improves performance, decreases dangers of program deadlock, and simplifies code debugging operations on the condition that locking is avoided.

Description

Without lock message queue implementation method
Technical field
The present invention relates to cloud computing technology, particularly a kind of without lock message queue implementation method.
Background technology
In thread/process model, generally realize communicating by letter between thread/process with the producer/consumer's model.This model is robbed message with semaphore, and guarantees that with lock each thread/process is to global message formation secure access.Yet, the producer/consumer's model, the frequent lock that uses causes performance low.
Summary of the invention
(1) technical matters that solves
The technical matters that the present invention solves is how to solve in the producer/consumer's model the performance loss of locking and the semaphore invalid operation causes.
(2) technical scheme
The invention provides a kind of nothing lock message queue implementation method, described method comprises:
S1: main thread obtains message, and described message is kept in message queue;
S2: main thread detects whether available free worker thread of all working thread; If no, continue to detect all working thread, until the vacant working thread detected, jump procedure S3; If have, jump procedure S3;
S3: main thread sends to the vacant working thread with described message, and the vacant working thread receives described message and processes described message, and the vacant working thread becomes worker thread;
S4: worker thread sends to main thread with idle signal after handling described message.
Preferably, after main thread described in step S3 sent to the vacant working thread with described message, main thread became duty with the dormant state of vacant working thread.
Preferably, after step S4, worker thread enters dormant state.
Preferably, also comprise after step S4: main thread is placed in the vacant working thread with worker thread after receiving the idle signal of worker thread transmission.
(3) beneficial effect
The present invention in the situation that avoid locking, has improved performance without lock message queue implementation method by providing a kind of, has reduced the danger of program deadlock, has simplified code debugging work.
Description of drawings
Fig. 1 is method flow diagram provided by the invention.
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 clearly and completely described.
The invention provides a kind of nothing lock message queue implementation method, as shown in Figure 1, use producer's assignment message pattern, change original consumer and obtain massage pattern.Described method comprises:
S1: main thread obtains message, and described message is kept in message queue;
Main thread is the producer, and this message is the outside message that sends.
S2: main thread detects whether available free worker thread of all working thread; If no, continue to detect all working thread, until the vacant working thread detected, jump procedure S3; If have, jump procedure S3;
Worker thread is the consumer.
S3: main thread sends to the vacant working thread with described message, and the vacant working thread receives described message and processes described message, and the vacant working thread becomes worker thread;
After described main thread sent to the vacant working thread with described message, main thread became duty with the dormant state of vacant working thread.
S4: worker thread sends to main thread with idle signal after handling described message.
This worker thread enters dormant state.
Main thread is placed in the vacant working thread with worker thread after receiving the idle signal of worker thread transmission.
A kind of without lock message queue implementation method by adopting, main thread not only receives the outside message that sends, also receive the idle signal of worker thread, utilize this idle signal, obtain the state of all working thread, and according to this state, initiatively send message to worker thread by main thread, thereby can lock, improve efficient.
Above embodiment only is used for explanation the present invention; and be not limitation of the present invention; the those of ordinary skill in relevant technologies field; without departing from the spirit and scope of the present invention; can also make a variety of changes and modification; therefore all technical schemes that are equal to also belong to category of the present invention, and scope of patent protection of the present invention should be defined by the claims.

Claims (4)

1. a nothing lock message queue implementation method, is characterized in that, described method comprises:
S1: main thread obtains message, and described message is kept in message queue;
S2: main thread detects whether available free worker thread of all working thread; If no, continue to detect all working thread, until the vacant working thread detected, jump procedure S3; If have, jump procedure S3;
S3: main thread sends to the vacant working thread with described message, and the vacant working thread receives described message and processes described message, and the vacant working thread becomes worker thread;
S4: worker thread sends to main thread with idle signal after handling described message.
2. method according to claim 1, is characterized in that, after main thread described in step S3 sent to the vacant working thread with described message, main thread became duty with the dormant state of vacant working thread.
3. method according to claim 1, is characterized in that, after step S4, worker thread enters dormant state.
4. method according to claim 1, is characterized in that, also comprises after step S4: main thread is placed in the vacant working thread with worker thread after receiving the idle signal of worker thread transmission.
CN2013101067555A 2013-03-29 2013-03-29 Lock-free message queue implementation method Pending CN103164267A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2013101067555A CN103164267A (en) 2013-03-29 2013-03-29 Lock-free message queue implementation method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2013101067555A CN103164267A (en) 2013-03-29 2013-03-29 Lock-free message queue implementation method

Publications (1)

Publication Number Publication Date
CN103164267A true CN103164267A (en) 2013-06-19

Family

ID=48587383

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2013101067555A Pending CN103164267A (en) 2013-03-29 2013-03-29 Lock-free message queue implementation method

Country Status (1)

Country Link
CN (1) CN103164267A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104216765A (en) * 2014-08-15 2014-12-17 东软集团股份有限公司 Multithreading concurrent service processing method and system
CN106201705A (en) * 2016-07-25 2016-12-07 东软集团股份有限公司 Process the method and device of message
CN106293973A (en) * 2016-08-17 2017-01-04 深圳市金证科技股份有限公司 Lock-free message queue communication means and system
WO2018036406A1 (en) * 2016-08-25 2018-03-01 阿里巴巴集团控股有限公司 Message transmission system, method and device
CN108153596A (en) * 2017-12-15 2018-06-12 珠海金山网络游戏科技有限公司 A kind of message treatment method and device based on lock-free queue
CN111625370A (en) * 2019-02-27 2020-09-04 杭州海康威视系统技术有限公司 Message pushing method and device, electronic equipment and storage medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1740974A (en) * 2005-09-14 2006-03-01 艾默生网络能源有限公司 A threading scheduling management method and system
CN201364484Y (en) * 2009-01-21 2009-12-16 重庆交通大学 Remote bridge monitoring system based on B/S mode
CN101710286A (en) * 2009-12-23 2010-05-19 天津大学 Parallel programming model system of DAG oriented data driving type application and realization method
CN102262564A (en) * 2011-08-16 2011-11-30 天津市天祥世联网络科技有限公司 Thread pool structure of video monitoring platform system and realizing method
CN102279766A (en) * 2011-08-30 2011-12-14 华为技术有限公司 Method and system for concurrently simulating processors and scheduler
CN102449602A (en) * 2009-04-03 2012-05-09 谷歌公司 System and method for reducing startup cost of a software application
CN102591709A (en) * 2011-12-20 2012-07-18 南京大学 Shapefile master-slave type parallel writing method based on OGR (open geospatial rule)
CN102622273A (en) * 2012-02-23 2012-08-01 中国人民解放军国防科学技术大学 Self-learning load prediction based cluster on-demand starting method
CN102629220A (en) * 2012-03-08 2012-08-08 北京神州数码思特奇信息技术股份有限公司 Dynamic task allocation and management method

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1740974A (en) * 2005-09-14 2006-03-01 艾默生网络能源有限公司 A threading scheduling management method and system
CN201364484Y (en) * 2009-01-21 2009-12-16 重庆交通大学 Remote bridge monitoring system based on B/S mode
CN102449602A (en) * 2009-04-03 2012-05-09 谷歌公司 System and method for reducing startup cost of a software application
CN101710286A (en) * 2009-12-23 2010-05-19 天津大学 Parallel programming model system of DAG oriented data driving type application and realization method
CN102262564A (en) * 2011-08-16 2011-11-30 天津市天祥世联网络科技有限公司 Thread pool structure of video monitoring platform system and realizing method
CN102279766A (en) * 2011-08-30 2011-12-14 华为技术有限公司 Method and system for concurrently simulating processors and scheduler
CN102591709A (en) * 2011-12-20 2012-07-18 南京大学 Shapefile master-slave type parallel writing method based on OGR (open geospatial rule)
CN102622273A (en) * 2012-02-23 2012-08-01 中国人民解放军国防科学技术大学 Self-learning load prediction based cluster on-demand starting method
CN102629220A (en) * 2012-03-08 2012-08-08 北京神州数码思特奇信息技术股份有限公司 Dynamic task allocation and management method

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104216765B (en) * 2014-08-15 2017-11-03 东软集团股份有限公司 A kind of method and system of multi-thread concurrent processing business
CN104216765A (en) * 2014-08-15 2014-12-17 东软集团股份有限公司 Multithreading concurrent service processing method and system
CN106201705A (en) * 2016-07-25 2016-12-07 东软集团股份有限公司 Process the method and device of message
CN106201705B (en) * 2016-07-25 2019-10-08 东软集团股份有限公司 Handle the method and device of message
CN106293973A (en) * 2016-08-17 2017-01-04 深圳市金证科技股份有限公司 Lock-free message queue communication means and system
CN106293973B (en) * 2016-08-17 2019-12-13 深圳市金证科技股份有限公司 lock-free message queue communication method and system
CN107783845B (en) * 2016-08-25 2021-04-13 阿里巴巴集团控股有限公司 Message transmission system, method and device
WO2018036406A1 (en) * 2016-08-25 2018-03-01 阿里巴巴集团控股有限公司 Message transmission system, method and device
CN107783845A (en) * 2016-08-25 2018-03-09 阿里巴巴集团控股有限公司 Message delivery system, method and apparatus
TWI752967B (en) * 2016-08-25 2022-01-21 香港商阿里巴巴集團服務有限公司 Message transmission system, method and device
CN108153596A (en) * 2017-12-15 2018-06-12 珠海金山网络游戏科技有限公司 A kind of message treatment method and device based on lock-free queue
CN111625370A (en) * 2019-02-27 2020-09-04 杭州海康威视系统技术有限公司 Message pushing method and device, electronic equipment and storage medium
CN111625370B (en) * 2019-02-27 2023-10-10 杭州海康威视系统技术有限公司 Message pushing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN103164267A (en) Lock-free message queue implementation method
CN103345422B (en) A kind of multithreading hard real-time control method based on Linux
AU2017309399A8 (en) Systems and methods for resource sensing for sidelink operation
EP3376379A1 (en) Task management methods and system, and computer storage medium
MY155867A (en) Scheduling collections in a scheduler
WO2013158330A3 (en) Method to reduce multi-threaded processor power consumption
CN103995751A (en) Cross-platform communication system and method
CN103281261A (en) Ethernet communication method and Ethernet communication system
CN103336684A (en) AC capable of concurrent processing AP information and processing method thereof
CN102999412A (en) Method for monitoring process under Linux
US9569264B2 (en) Multi-core system for processing data packets
CN104363034B (en) Method and device for unbinding wearable device
US20130191613A1 (en) Processor control apparatus and method therefor
CN103607360A (en) Message processing method, line card and switching equipment
CN104618152A (en) Session table aging method and system
US20150089101A1 (en) Managing network interface controller-generated interrupts
CN104486149B (en) A kind of finite state machine method for ground test
CN103823712A (en) Data flow processing method and device for multi-CPU virtual machine system
CN106375382A (en) Data distribution method and system, control server and node client
CN101529353B (en) Method for carrying out online program changes on an automation system
CN103096168B (en) A kind of data communication method for parallel processing based on IPTV set top box
FI3457637T3 (en) Conflict resolution method for a remotely controlled device and conflict resolution system
CN105245372A (en) Optimization method for loading network resources based on cache and asynchronous mechanism
JP2014027586A5 (en)
WO2019126797A3 (en) System and method for executing instructions

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into 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: 20130619