Archived

This topic is now archived and is closed to further replies.

Concurrency issue

This topic is 5043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lets say i have a real-time stream and with one thread1 i am grabbing 20 frames a second from it and writing 20 times a second into a same bitmap file. (that was my "producer" side) On the other hand another thread2 polls the bitmap to read the data from it using a while loop. How many times a second will this thread2 get the chance to read the whole bitmap? (that ofcourse is debatable and depends on many other factors) BUT the main question is: Can someone tell me if while thread2 is reading it can be pre-empted to allow thread1 to write? (same priority level of threads). So will i be able to at least 3-4 times a second successfully read the bitmap via thread2 ? (((threads running as user created under windows)))) Many thanks to all who answer. kalash

Share this post


Link to post
Share on other sites
All Win32 OS's are pre-emptive (yes for Win95,98,ME, WinNT,2k,XP).
While syncronization in this case is not critical for the applications integrity, it will produce artifacts if you let them run-free.
For example "tearing" in 3D rendering is the result of an unsyncronized screen update.

[edited by - Magmai Kai Holmlor on February 19, 2004 10:40:13 PM]

Share this post


Link to post
Share on other sites
Ok, so you are saying thread2 will still read a couple of times every second ? and there will be no crashes ?

thread2 i basically in a while loop trying read image time and time again.

Share this post


Link to post
Share on other sites
Actually i am not sure if they r on same level priority but i assume they are, or does implicitly write have proiority in WinOS ?

will thread2 be premptable by write thread1 or write will have to wait ?

Share this post


Link to post
Share on other sites
Perhaps you''d want to doublebuffer your image as well, so that the critical section would be shortened to a simple pointer swap, lessening the chance of stalls in your render loop.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by jperalta
You might want to look at using mutices (sing. mutex) and semaphores.

I don''t see why you should use mutants or semaphores to synchronize two threads within the same process. Critical section would be your choise as that likely is much cheaper (no kernel mode transition required if no other thread is waiting for the crisec when you try to aquire it).

Share this post


Link to post
Share on other sites