GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Jun-2007, 19:57
meili100 meili100 is offline
Junior Member
 
Join Date: Feb 2007
Posts: 37
meili100 has a little shameless behaviour in the past

A Question About Static Variable and Thread-Safe


I was asked to write a function with a static variable in it. for example:

CPP / C++ / C Code:
void foo(){
static int a=1;
a++;
}

Obviously this is not thread safe. Then I was asked to solve this problem to make it thread safe.
I was told that I can use a class to wrap it. Does anybody has an idea what that is?

Do you have a better solution?
Last edited by LuciWiz : 07-Jun-2007 at 15:16. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.