multithreading - Efficient multithreaded shared access to memory buffer -


this question might pretty simple still can't figure out efficient way this. have following setup:

1) thread downloads data internet memory buffer.

2) @ same time, thread b wants read data has been downloaded buffer.

the buffer not circular or anything. there write cursor , read cursor. once thread has written buffer, updates write cursor tell thread b how data available reading.

the problem thread b reads thousands of bytes in steps of single byte @ time. need efficient way of synchronizing 2 threads. i've tried setevent() , waitforsingleobject() seems quite slow (or did wrong) because thread b reading in packets of 1 byte buffer thread b has call waitforsingleobject() every byte needs read. sounds lot of overhead.

shouldn't possible without mutex (critical section) protection? i.e. thread b poll write cursor until enough data available , copy it. question of synchronization comes up, i.e. when thread updates write cursor, change reflected in thread b? don't have experience multithreading programming , many of articles available on sound extremely complicated i'd glad if point me right direction implement in efficient way.

yes, can poll in 1 thread changes made in other thread, without needing mutex. fast, has high cpu overhead thread b polls check new data.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -