Subj : Re: static member variable To : comp.programming.threads From : Gianni Mariani Date : Wed Feb 23 2005 09:08 am nin234@yahoo.com wrote: > I tried searching the newgroups for an answer to this question. I > found > many related topics, but didn't find the exact answer I am looking > for. ..... snip > class srvLog > { > static int nLglvl; .... snip > Logging is controlled by the nLglvl static variable. This is part of > a daemon. So the logging is to a file and the value of nLglvl will be > set by a command line tool. > My questions are the following > 1) Is the value of nLglvl shared by threadA, threadB and main() > thread. Yes srvLog::nLglvl exists in exactly one place - that's what static means. > > 2)Where should I call setlvl()? Anywhere you like. > 3) If the answer to 1) is yes. Is it really required to use locking > in > this scenario. Because the change to the value of nLglvl will be > infrequent and I can live with some bad reads. Locking is not required since synchronizing with the change is not important. You may want to make it volatile > > I am using POSIX threads. Linux and solaris are the current > environments. It must be portable to all unix flavors. You might want to look at a C++ library like boost, or Austria C++. .