c++ - Implement multi-thread applications without locks in ZeroMQ -
http://www.zeromq.org/blog:multithreading-magic
the message-based zeromq framework implements concurrent/multi-thread applications without using locks.
question> how works following example?
for example:
we have 2 clients each read data same database , later put modified results.
clienta: read data a, modified a.value = a.value + 1 write data database clientb: read data a, modified a.value = a.value + 2 write data database
question> not able figure out how implement such system zeromq don't need locks control behaviors of clienta , clientb. how can prevent following case happening.
clienta read data first clientb read data second clientb write data // data.value has been increased 2 clienta write data // conflict! because original value of has been // modified clientb , clienta has no information it. // if clienta writes without knowing update // changes made clientb voided.
how zeromq address such issue without using locks using messages?
thank you
a simple answer can emulate lock concurrent queue.
say have queue of size 1 that's filled. clients try grab value queue. 1 succeeded perform operation , put value in queue. 1 failed go sleep, , proceed after successful client finished.
this arguably of academic example. in reality using transactions in database system instead of locks amongst clients.
Comments
Post a Comment