Click here to Skip to main content
15,893,814 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to work out "type redefinition" problem Pin
yugiant16-Oct-09 5:51
yugiant16-Oct-09 5:51 
GeneralRe: how to work out "type redefinition" problem Pin
«_Superman_»16-Oct-09 6:03
professional«_Superman_»16-Oct-09 6:03 
GeneralRe: how to work out "type redefinition" problem Pin
yugiant16-Oct-09 6:06
yugiant16-Oct-09 6:06 
QuestionRe: how to work out "type redefinition" problem Pin
David Crow16-Oct-09 5:05
David Crow16-Oct-09 5:05 
Questionhow to get dial-in tab properties of user object in active directory using c++ Pin
raja 416-Oct-09 4:40
raja 416-Oct-09 4:40 
QuestionChild dialog problem Pin
ilgale16-Oct-09 4:26
ilgale16-Oct-09 4:26 
AnswerRe: Child dialog problem Pin
Iain Clarke, Warrior Programmer16-Oct-09 22:07
Iain Clarke, Warrior Programmer16-Oct-09 22:07 
QuestionHow do I make calling InitializeCriticalSection() thread safe? [modified] Pin
Steve Thresher16-Oct-09 2:06
Steve Thresher16-Oct-09 2:06 
I have a static class I use for caching data. This will now be accessed from multiple threads which means I need to add a CRITICAL_SECTION to make updating the cache thread safe. I now have the problem of who initialises the CRITICAL_SECTION given a static class doesn't have a constructor.

std::map<int,std::string> CMY_CACHE::m_cache_map;

CRITICAL_SECTION CMY_CACHE::m_critical_section;

class CMY_CACHE
{
private:
  static std::map<int,std::string> m_cache_map;

  static CRITICAL_SECTION m_critical_section; //<-- Where do I initialize this?

public:
    
std::string read(int index)
{
  EnterCriticalSection(&m_critical_section);

  std::map<int,std::string>::iterator it=m_cache_map.find(index);
  
  if (it==m_cache_map.end())
  {
    // Add value to cache

    // Adjust iterator
  }

  LeaveCriticalSection(&m_critical_section);


  return(it->second);
}

...

  // The following call could be issued by multiple threads
  std::string s=CMY_CACHE::read(0);


modified on Friday, October 16, 2009 8:28 AM

AnswerRe: How do I make calling InitializeCriticalSection() thread safe? Pin
Cedric Moonen16-Oct-09 2:32
Cedric Moonen16-Oct-09 2:32 
AnswerRe: How do I make calling InitializeCriticalSection() thread safe? Pin
CPallini16-Oct-09 2:54
mveCPallini16-Oct-09 2:54 
AnswerRe: How do I make calling InitializeCriticalSection() thread safe? Pin
cmk16-Oct-09 3:02
cmk16-Oct-09 3:02 
QuestionHandling keystrokes on TreeCntrl Pin
ratprita16-Oct-09 1:04
ratprita16-Oct-09 1:04 
AnswerRe: Handling keystrokes on TreeCntrl Pin
Hans Dietrich16-Oct-09 1:40
mentorHans Dietrich16-Oct-09 1:40 
Questionshow/hide CWebBrowser2 Pin
includeh1016-Oct-09 1:02
includeh1016-Oct-09 1:02 
AnswerRe: show/hide CWebBrowser2 Pin
Steve Thresher16-Oct-09 3:55
Steve Thresher16-Oct-09 3:55 
QuestionMFC Resource File Pin
Caslen16-Oct-09 0:16
Caslen16-Oct-09 0:16 
AnswerRe: MFC Resource File Pin
Hans Dietrich16-Oct-09 1:42
mentorHans Dietrich16-Oct-09 1:42 
GeneralRe: MFC Resource File Pin
Caslen16-Oct-09 2:22
Caslen16-Oct-09 2:22 
Questionmultithreaded TCP Server Application(MFC) Pin
Manmohan2915-Oct-09 23:51
Manmohan2915-Oct-09 23:51 
AnswerRe: multithreaded TCP Server Application(MFC) Pin
Moak16-Oct-09 0:16
Moak16-Oct-09 0:16 
GeneralRe: multithreaded TCP Server Application(MFC) Pin
Manmohan2916-Oct-09 0:26
Manmohan2916-Oct-09 0:26 
GeneralRe: multithreaded TCP Server Application(MFC) Pin
Moak16-Oct-09 0:44
Moak16-Oct-09 0:44 
QuestionCalculate factorial of any number less than 10000,but I don't know how to start with? Pin
milestanley15-Oct-09 22:08
milestanley15-Oct-09 22:08 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
Rajesh R Subramanian15-Oct-09 22:19
professionalRajesh R Subramanian15-Oct-09 22:19 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
CPallini15-Oct-09 22:52
mveCPallini15-Oct-09 22:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.