Thread Problem
-
1.)I have a data source that is continously modified, i.e items added, deleted, changed. I used a static global mutex object to actually allow only one thread to modify it. Now I have a list ctrl that shows that data, the refreshing is done in a different thread. Now in that thread:
DeleteAllItems(); for(unsigned int i=0; i
No what if I have a list of 10 elements and I deleted some of them when this thread is running. As the compiler will store the value of m_aryCall.Count() in some temporary variable and when its asks for 10th element, which is not there. 2.)In Modify Data Block a create a thread by new and run it, now the threads are running and the ModifyData is called many times when the previous threads is running. This actually creates memory leak as the thread is not deleting itself. [http://www.priyank.in/](http://www.priyank.in/)
-
1.)I have a data source that is continously modified, i.e items added, deleted, changed. I used a static global mutex object to actually allow only one thread to modify it. Now I have a list ctrl that shows that data, the refreshing is done in a different thread. Now in that thread:
DeleteAllItems(); for(unsigned int i=0; i
No what if I have a list of 10 elements and I deleted some of them when this thread is running. As the compiler will store the value of m_aryCall.Count() in some temporary variable and when its asks for 10th element, which is not there. 2.)In Modify Data Block a create a thread by new and run it, now the threads are running and the ModifyData is called many times when the previous threads is running. This actually creates memory leak as the thread is not deleting itself. [http://www.priyank.in/](http://www.priyank.in/)
I am not sure I understand 100% of what you are trying to do, but it seems to me that you have a mumber of threads modifying the data (and using a Global Mutex to make sure they do it one at a time) and a number of threads reading the data. If that is the case just use the same Mutex for the reading threads also. That way your data is not being modified as another thread is tryting to read it.
-
1.)I have a data source that is continously modified, i.e items added, deleted, changed. I used a static global mutex object to actually allow only one thread to modify it. Now I have a list ctrl that shows that data, the refreshing is done in a different thread. Now in that thread:
DeleteAllItems(); for(unsigned int i=0; i
No what if I have a list of 10 elements and I deleted some of them when this thread is running. As the compiler will store the value of m_aryCall.Count() in some temporary variable and when its asks for 10th element, which is not there. 2.)In Modify Data Block a create a thread by new and run it, now the threads are running and the ModifyData is called many times when the previous threads is running. This actually creates memory leak as the thread is not deleting itself. [http://www.priyank.in/](http://www.priyank.in/)
Priyank Bolia wrote: I used a static global mutex object to actually allow only one thread to modify it The problem is, you like to directly modify the control from different threads... You should only modify controls from the main thread (or the thread which created the control)... When you like to directly modify it from an other thread, it comes to unexpected situations like memory leaks or a deadlock of the app... You should only modify the controls from different threads with the usage of PostMessage... Communicate from the worker thread(s) with the main thread only with PostMessage and custom defined user messages to provide an save ui access... like: http://www.codeproject.com/threads/usingworkerthreads.asp Best regards ;)