Thread synchronization
-
Hi all, I am having a list(queue)of tasks. My two threads are using the same list. First thread is to insert the task into it. (appending the list) Second thread is to process on each task . ( reading the list) My aim is to give the maximum availability to Thread one without hanging thread two. How to synchronize both thread so that, second thread should not wait for long and First thread keep inserting the item into list. Thanks in advance
-
Hi all, I am having a list(queue)of tasks. My two threads are using the same list. First thread is to insert the task into it. (appending the list) Second thread is to process on each task . ( reading the list) My aim is to give the maximum availability to Thread one without hanging thread two. How to synchronize both thread so that, second thread should not wait for long and First thread keep inserting the item into list. Thanks in advance
critical section! look for CCriticalSection class in MFC!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>
-
critical section! look for CCriticalSection class in MFC!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>
A piece of good advice is to stay clear of the MFC synchronization objects because they are not working properly. They may fail under certain circumstances. E.g. you cannot recursively lock a CCriticalSection from the same thread because it will cause a deadlock. Use the Win32 API with
::EnterCriticalSection()
and::LeaveCriticalSection()
instead. Read more here[^]."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
A piece of good advice is to stay clear of the MFC synchronization objects because they are not working properly. They may fail under certain circumstances. E.g. you cannot recursively lock a CCriticalSection from the same thread because it will cause a deadlock. Use the Win32 API with
::EnterCriticalSection()
and::LeaveCriticalSection()
instead. Read more here[^]."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownRoger Stoltz wrote:
E.g. you cannot recursively lock a CCriticalSection from the same thread because it will cause a deadlock.
:omg: Wow, thanks for the info Roger. I've never used the MFC sync objects before but I don't think I will ever use them now.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Roger Stoltz wrote:
E.g. you cannot recursively lock a CCriticalSection from the same thread because it will cause a deadlock.
:omg: Wow, thanks for the info Roger. I've never used the MFC sync objects before but I don't think I will ever use them now.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Yup, pretty amazing, isn't it? But the evidence is right there in the code. X| I've never used the MFC sync classes since I read Joe's advice many years ago in a much earlier essay of his. Even though CCriticalSection may work if it's only locked once in a call chain, you will eventually find yourself in a situation where you should perform a second lock due to encapsulation and at that time you're smoked; a re-write using the Win32 primitives is essential before it has a chance of working.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown