Thanks for your reply. I would like to know if critical sections can be used to lock a section of code within the same thread. Critical Sections within same thread - possible ? Cheers Raja
RCM
Posts
-
Resource Access in Multiple Timers in Single thread -
Resource Access in Multiple Timers in Single threadHi, I have a dialog based MFC application which has 2 timers with same interval (say 5 mins) accessing a single resource. A structure instance which is a member variable of the App class is being updated in one timer and the same structure instance is being used in another timer. ( Typically, the memory resource is being accessed for write in one timer callback and for read in another timer callback ). The code snippet something is like this, CMyFrameDlg::TimerCallback1(...) { ... theApp.m_Struct.nVar1 = 10; theApp.m_Struct.szVar2 = "test"; ... ... } CMyFrameDlg::TimerCallback2(...) { ... ... localnVar = theApp.m_Struct.nVar1; localszVar = theApp.m_Struct.szVar2; ... } The 2 timers get called simultaneously. Issue is, that the values dont get reflected properly in timer2 and while the struct is being accessed in timer2 it is being updated simulataneously in timer1. Both timers belong to the same Thread. 1.) I need to update the same resource in one timer and use it for some other purpose in the second timer. Is it possible ? 2.) I also have certain WM_.. messages posted from another thread to this thread on which a callback gets invoked. And this callback also accesses the same structure instance, but the values are not properly updated. Why is it so ? Point is.. accessing the same resource ( memory) in multiple timers of the same thread. And also accessing same resource in multiple callbacks of the same thread (like user defined WM_message callbacks). Is there any restriction or way to do that ? Anxiously Waiting for a reply :~ Cheers Raja