double-checked locking for singleton pattern

Hello

After reading the Meyers& Alexandrescu article "C++ and the Perils of
Double-Checked Locking"
(http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf) which
claims that there is no
way of implementing double-checked locking for C++ singletons, I
wonder if the following simple
solution might do the work:

class Singleton {
public:
   static Singleton* instance();
....
private:
  Singleton();
  static Singleton * pInstance;
};

Singleton::Singleton()
{
  ... // do necessary initialisation
  pInstance = this;
}

Singleton* Singleton::instance() {
  if (pInstance == 0) {
    Lock lock;
    if (pInstance == 0) {
        new Singleton();
    }
  }
  return pInstance;
}

The issue which was highlighted in the article is related to the fact
that the line which looks like
pInstance = new Singleton;
can not be used in the Singleton::instance() function since some
compilers may generate code which would assign a value to the
pInstance variable right after allocating memory and BEFORE the
Singleton constructor is executed. It seems that a simple modification
shown above can overcome this problem. Am I wrong? Can someone comment
on that please.

Cheers,
Sergei

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
kse13e
5/14/2008 2:12:42 PM
comp.lang.c++.moderated 10706 articles. 11 followers. allnor (8507) is leader. Post Follow

11 Replies
419 Views

Similar Articles

[PageSpeed] 21
<kse13e@yandex.ru> wrote in message
news:83b09fe9-210c-43eb-9030-ccd6096128ac@m36g2000hse.googlegroups.com...
> Hello
>
> After reading the Meyers& Alexandrescu article "C++ and the Perils of
> Double-Checked Locking"
> (http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf) which
> claims that there is no
> way of implementing double-checked locking for C++ singletons, I
> wonder if the following simple
> solution might do the work:

Its not going to work; there is a race-condition.

[...]

> The issue which was highlighted in the article is related to the fact
> that the line which looks like
> pInstance = new Singleton;
> can not be used in the Singleton::instance() function since some
> compilers may generate code which would assign a value to the
> pInstance variable right after allocating memory and BEFORE the
> Singleton constructor is executed. It seems that a simple modification
> shown above can overcome this problem. Am I wrong? Can someone comment
> on that please.

The problem is that your missing a memory barrier after you load from, 
and
before you store to the instance pointer. Here is sketch of 
high-performance
DCL algorithm that has all the correct barriers in place:
________________________________________________________________
template<typename T>
static T& once() {
  static T* g_this = NULL;
  static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
1:T* l_this = ATOMIC_LOADPTR_MBDEPENDS(&g_this);
  if (! l_this) {
    pthread_mutex_lock(&g_lock);
    if (! (l_this = g_lock)) {
      try {
2:      l_this = ATOMIC_STOREPTR_MBRELEASE(&g_this, new T);
      } catch (...) {
        pthread_mutex_unlock(&g_lock);
        throw;
      }
    }
    pthread_mutex_unlock(&g_lock);
  }
  return *l_this;
}
________________________________________________________________





Line 1 atomically load the shared pointer using trailing data-dependant
load-acquire memory barrier. Line 2 atomically stores to the shared 
pointer
using preceding store-release memory barrier:
________________________________________________________________
void* ATOMIC_LOADPTR_MBDEPENDS(void** p) {
  void* v;
  atomic {
    v = *p;
    MEMBAR #LoadStore | #LoadDepends;
  }
  return v;
}


void* ATOMIC_STOREPTR_MBRELEASE(void** p, void* v) {
  atomic {
    MEMBAR #LoadStore | #StoreStore;
    *p = v;
  }
  return v;
}
________________________________________________________________



-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Chris
5/14/2008 5:25:53 PM
On May 14, 5:12 pm, kse...@yandex.ru wrote:
> Hello
>
> After reading the Meyers& Alexandrescu article "C++ and the Perils of
> Double-Checked Locking"
> (http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf) which
> claims that there is no
> way of implementing double-checked locking for C++ singletons, I
> wonder if the following simple
> solution might do the work:
>
....
>
> The issue which was highlighted in the article is related to the fact
> that the line which looks like
> pInstance = new Singleton;
> can not be used in the Singleton::instance() function since some
> compilers may generate code which would assign a value to the
> pInstance variable right after allocating memory and BEFORE the
> Singleton constructor is executed. It seems that a simple modification
> shown above can overcome this problem. Am I wrong? Can someone comment
> on that please.

The key quote from that paper:

"... people who do nothing but think about this kind of thing all day
long,
day after day, year after year. Unless you write optimizing compilers
yourself,
they are _way_ ahead of you."

Sorry, couldn't resist :)

--
  Nikolai



-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
nickf3
5/14/2008 11:05:07 PM
On 14 Maj, 23:12, kse...@yandex.ru wrote:
> Singleton::Singleton()
> {
>   ... // do necessary initialisation
>   pInstance = this;
>
> }
You do nothing to prevent compiler from changing the above code into:
Singleton::Singleton()
{
     pInstance = this;
     ... // do necessary initialisation
}
This could be due to some register usage optimalizations for example.

Cheers
Sfider

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Marcin
5/15/2008 3:04:50 PM
On 16 ???, 00:04, Marcin Swiderski <sfider.b...@gmail.com> wrote:
> On 14 Maj, 23:12, kse...@yandex.ru wrote:> Singleton::Singleton()
> > {
> >   ... // do necessary initialisation
> >   pInstance = this;
>
> > }
>
> You do nothing to prevent compiler from changing the above code into:
> Singleton::Singleton()
> {
>      pInstance = this;
>      ... // do necessary initialisation}
>


Thank you for the comment. I have realized that by reading the article
more attentively.
But what I still don't understand in it is the text on the page 11.
The authors claim that
the following code ensures proper initialisation order (the code is
already optimized):

Singleton* Singleton::instance()
{
   if (pInstance == 0) {
     Lock lock;
     if (pInstance == 0) {
         Singleton* volatile temp =
         static_cast<Singleton*>(operator new(sizeof(Singleton)));
         static_cast<volatile int&>(temp->x) = 5;
         pInstance = temp;
     }
   }
}

but then they are saying that "Unfortunately, this all does nothing
to address the first problem: C++'s abstract machine is single-
threaded,
and C++ compilers may choose to generate thread-unsafe code from
source
like the above, anyway."

I wonder how this may happen, i.e. what multi-threaded compiler might
be doing wrong about that code?

Cheers,
Sergei


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
kse13e
5/16/2008 4:31:53 PM
as commented in many of the posts and the afore mentioned paper from
Andrei Alexandrescu & Scott Meyers, the problem is the lack of
barriers. But as they comment in the very same paper:

"
At this point, one might reasonably wonder why Lock isn�t also
declared volatile. After all, it�s critical that the lock be
initialized before we try to write to pInstance or temp. Well, Lock
comes from a threading library, so we can assume it either dictates
enough restrictions in its specification or embeds enough magic in its
implementation to work without needing volatile. This is the case with
all threading libraries that we know of.
"

So, what would be the problem with the following implementation:

Singleton *pInstance;
Singleton* Singleton::instance()
{
    if (pInstance == 0) {
      Lock lock_1;
      if (pInstance == 0) {
          static Singleton* volatile temp = new Singleton();
          {
              Lock lock_2;
              pInstance = temp;
          }
      }
    }
}

if lock_2 works as a barrier against optimization, pInstance will
never be assigned before the object is correctly constructed ...

cheers,
- jan

ps.: i'm pretty sure there must be a problem, it wouldn't be that
simple, but i can't see how :)


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
pfeifer
5/29/2008 9:35:49 PM
On May 30, 6:35 am, pfei...@gmail.com wrote:
> as commented in many of the posts and the afore mentioned paper from
> Andrei Alexandrescu & Scott Meyers, the problem is the lack of
> barriers. But as they comment in the very same paper:
>
> "
> At this point, one might reasonably wonder why Lock isn't also
> declared volatile. After all, it's critical that the lock be
> initialized before we try to write to pInstance or temp. Well, Lock
> comes from a threading library, so we can assume it either dictates
> enough restrictions in its specification or embeds enough magic in its
> implementation to work without needing volatile. This is the case with
> all threading libraries that we know of.
> "
>
> So, what would be the problem with the following implementation:
>
> Singleton *pInstance;
> Singleton* Singleton::instance()
> {
>     if (pInstance == 0) {
>       Lock lock_1;
>       if (pInstance == 0) {
>           static Singleton* volatile temp = new Singleton();
>           {
>               Lock lock_2;
>               pInstance = temp;
>           }
>       }
>     }
>
> }
>
> if lock_2 works as a barrier against optimization, pInstance will
> never be assigned before the object is correctly constructed ...
>

Whether you use a lock or a barrier for synchronization, you need to
use the same object on all threads that need to be synchronized. In
particular lock_2 (assuming that it is actually locking a mutex, which
is not apparent from your code) is synchronizing with nobody: only one
thread will ever acquire it, so it is useless.

Also, AFAIK, nothing in your code, assuming a relaxed memory model,
guarantees that, if pinstance is != 0, it will actually point to a
valid object (and, no, I'm not talking about the fact you didn't zero
initialize it).


--
Giovanni P. Deretta


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
gpderetta
5/30/2008 7:50:54 AM
On Fri, 30 May 2008 08:50:54 -0600, gpderetta wrote:
> Whether you use a lock or a barrier for synchronization, you need to use
> the same object on all threads that need to be synchronized. 

Sorry, that is true. I failed to detail that in my pseudo-code. Let me
retry it:

Singleton *pInstance = 0;
Mutex mtx1, mtx2;

Singleton* Singleton::instance()
{
   if (pInstance == 0) {
     Lock lock_1(mtx1);
     if (pInstance == 0) {
       static Singleton* volatile temp = new Singleton();
       {
         Lock lock_2(mtx2);
         pInstance = temp;
       }
     }
  }
}


> In
> particular lock_2 (assuming that it is actually locking a mutex, which
> is not apparent from your code) is synchronizing with nobody: only one
> thread will ever acquire it, so it is useless.

Indeed it is synchronizing with nobody. But is there anyway for the
compiler to know that ? How can it know that no other thread is going to
synchronize on mtx2 ?

Well ... but maybe i'm back to the assumption that i can beat the
compiler into not optimizing something, which as A.Alexandrescu&S.Meyers
tries to discourage us from.

Although i would be surprised if today's compiler would optimize out a
lock like above -- it has to understand about all other possible threads,
and mtx2 being global, understand at link time that it is being only
locked in one place -- that means the linker has to know about the
semantics of locking.


> Also, AFAIK, nothing in your code, assuming a relaxed memory model,
> guarantees that, if pinstance is != 0, it will actually point to a valid
> object (and, no, I'm not talking about the fact you didn't zero
> initialize it).

the idea is that lock_2(mtx2) works as a barrier: that is the compiler
cannot move the assignment "pInstance = temp" across that.

If that is true, pInstance will only be != 0 after the object it points
to is properly constructed.

Otherwise many other things would break: imagine if the compiler starts
moving assignments on a shared memory structured before it actually
acquires the lock !?

thx
- jan


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Jan
5/30/2008 11:27:40 AM
On May 30, 8:27 pm, Jan Pfeifer <pfei...@stanford.edu> wrote:
> On Fri, 30 May 2008 08:50:54 -0600, gpderetta wrote:
> > Whether you use a lock or a barrier for synchronization, you need to use
> > the same object on all threads that need to be synchronized.
>
> Sorry, that is true. I failed to detail that in my pseudo-code. Let me
> retry it:
>
> Singleton *pInstance = 0;
> Mutex mtx1, mtx2;
>
> Singleton* Singleton::instance()
> {
>    if (pInstance == 0) {
>      Lock lock_1(mtx1);
>      if (pInstance == 0) {
>        static Singleton* volatile temp = new Singleton();
>        {
>          Lock lock_2(mtx2);
>          pInstance = temp;
>        }
>      }
>   }
>
> }
> > In
> > particular lock_2 (assuming that it is actually locking a mutex, which
> > is not apparent from your code) is synchronizing with nobody: only one
> > thread will ever acquire it, so it is useless.
>
> Indeed it is synchronizing with nobody. But is there anyway for the
> compiler to know that ? How can it know that no other thread is going to
> synchronize on mtx2 ?

Whole program analysis?

>
> Well ... but maybe i'm back to the assumption that i can beat the
> compiler into not optimizing something, which as A.Alexandrescu&S.Meyers
> tries to discourage us from.
>
> Although i would be surprised if today's compiler would optimize out a
> lock like above

compilers have surprised me many times.

> -- it has to understand about all other possible threads,
> and mtx2 being global, understand at link time that it is being only
> locked in one place -- that means the linker has to know about the
> semantics of locking.

If the linker can do link time optimizations, it certainly must. And
probably many do. For example I know for sure that there are Java
compilers that can remove useless locks. I wouldn't be surprised if C+
+ compilers did the same.

>
> > Also, AFAIK, nothing in your code, assuming a relaxed memory model,
> > guarantees that, if pinstance is != 0, it will actually point to a valid
> > object (and, no, I'm not talking about the fact you didn't zero
> > initialize it).
>
> the idea is that lock_2(mtx2) works as a barrier: that is the compiler
> cannot move the assignment "pInstance = temp" across that.
>
> If that is true, pInstance will only be != 0 after the object it points
> to is properly constructed.
>

This might fool some compilers which do not do whole program
compilation; It certainly won't fool the cpu, which is free to load
the pointed-to value before loading the pointer (yes, some cpus are
actually capable of doing that). I.e. you have to prevent reordering
(by the compiler or cpu), not only at the store, but also at the load.

> Otherwise many other things would break: imagine if the compiler starts
> moving assignments on a shared memory structured before it actually
> acquires the lock !?
>

As long as you use locks correctly AND your compiler understands them,
nothing will break.

--
Giovanni P. Deretta

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
gpderetta
5/30/2008 3:11:07 PM
"Jan Pfeifer" <pfeifer@stanford.edu> wrote in message
news:g1p6n2$nl6$1@news.stanford.edu...
> On Fri, 30 May 2008 08:50:54 -0600, gpderetta wrote:
>> Whether you use a lock or a barrier for synchronization, you need to use
>> the same object on all threads that need to be synchronized.
>
> Sorry, that is true. I failed to detail that in my pseudo-code. Let me
> retry it:
>
> Singleton *pInstance = 0;
> Mutex mtx1, mtx2;
>
> Singleton* Singleton::instance()
> {
>   if (pInstance == 0) {
>     Lock lock_1(mtx1);
>     if (pInstance == 0) {
>       static Singleton* volatile temp = new Singleton();
>       {
>         Lock lock_2(mtx2);
>         pInstance = temp;
>       }
>     }
>  }
> }
[...]

Its not guaranteed to work because there are mutex implementations out there
which do not use a memory barrier after every lock procedure; here is an
example:

http://groups.google.com/group/comp.programming.threads/browse_frm/thread/22b2736484af3ca6

Therefore, you would need to store into `pInstance' _after_ mtx2 has been
acquired and released. Here is a sketch:
______________________________________________________________
#include <pthread.h>

class mutex_guard {
  pthread_mutex_t* const m_mtx;
public:
  mutex_guard(pthread_mutex_t* const mtx) : m_mtx(mtx) {
    pthread_mutex_lock(m_mtx);
  }
  ~mutex_guard() throw() {
    pthread_mutex_unlock(m_mtx);
  }
};

template<typename T>
static T& once() {
  static T* volatile g_this = NULL;
  static pthread_mutex_t g_main_mtx = PTHREAD_MUTEX_INITIALIZER;
  static pthread_mutex_t g_mem_mtx = PTHREAD_MUTEX_INITIALIZER;
  T* l_this = g_this;
  if (! l_this) {
    mutex_guard const main_lock(&g_main_mtx);
    if (! l_this) {
      l_this = new T;
      {
        mutex_guard const mem_lock(&g_mem_mtx);
      }
      g_this = l_this;
    }
  }
  return *l_this;
}

______________________________________________________________


However, its still not guaranteed to work because it has undefined behavior
according to the PThread Standard. Although, it will most certainly work in
practice on some existing platforms if the compiler does not optimize the
`g_mem_mtx' lock/unlock sequence away...


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Chris
5/30/2008 3:14:26 PM
"Chris Thomasson" <cristom@comcast.net> wrote in message
news:jeudncfHdoRq9d3VnZ2dnUVZ_vqdnZ2d@comcast.com...
> "Jan Pfeifer" <pfeifer@stanford.edu> wrote in message
> news:g1p6n2$nl6$1@news.stanford.edu...
>> On Fri, 30 May 2008 08:50:54 -0600, gpderetta wrote:
>>> Whether you use a lock or a barrier for synchronization, you need to use
>>> the same object on all threads that need to be synchronized.
>>
>> Sorry, that is true. I failed to detail that in my pseudo-code. Let me
>> retry it:
>>
[...]
>
> Its not guaranteed to work because there are mutex implementations out 
> there
> which do not use a memory barrier after every lock procedure; here is an
> example:
>
> http://groups.google.com/group/comp.programming.threads/browse_frm/thread/22b2736484af3ca6
>
> Therefore, you would need to store into `pInstance' _after_ mtx2 has been
> acquired and released. Here is a sketch:
> ______________________________________________________________
[...]
> ______________________________________________________________
>
>
> However, its still not guaranteed to work because it has undefined 
> behavior
> according to the PThread Standard. Although, it will most certainly work 
> in
> practice on some existing platforms if the compiler does not optimize the
> `g_mem_mtx' lock/unlock sequence away...

One platform where this is guaranteed NOT to work would be DEC Alpha. That
architecture does not have implicit data-dependant load barrier. This will
bust the initial load of `pInstance'. The Alpha requires a memory barrier
after the load...


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Chris
5/30/2008 10:20:33 PM
"Chris Thomasson" <cristom@comcast.net> wrote in message
news:jeudncfHdoRq9d3VnZ2dnUVZ_vqdnZ2d@comcast.com...
[...]
> ______________________________________________________________
[...]
> template<typename T>
> static T& once() {
>  static T* volatile g_this = NULL;
>  static pthread_mutex_t g_main_mtx = PTHREAD_MUTEX_INITIALIZER;
>  static pthread_mutex_t g_mem_mtx = PTHREAD_MUTEX_INITIALIZER;
>  T* l_this = g_this;
>  if (! l_this) {
>    mutex_guard const main_lock(&g_main_mtx);
>    if (! l_this) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ARGH!

      if (! (l_this = g_this)) {


of course! Sorry for that non-sense.

[...]


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Chris
6/1/2008 2:01:12 AM
Reply:
Similar Artilces:

Adaptive Filtering v Lock In Amp
Can lock in amplification properly be considered a form of adaptive filtering? Bret Cahill On Feb 12, 7:50=A0pm, Bret Cahill <BretCah...@peoplepc.com> wrote: > Can lock in amplification properly be considered a form of adaptive > filtering? > > Bret Cahill I beleive a PLL could be classified in this way. It's non-linear of course and originally analogue in nature (though software version exist). It's all a matter of definitions. No way does it come under the current LMS FIR category but under perhaps an earlier Analogue genre - maybe. It...

Check for 0xff in byte array
I need to check if there is a 0xff in a particular byte of a byte array (actually in 2 consecutive bytes) which represents a trailer of a file. I can't work out how to do it. Any help would be appreciated. TIA -- Steve Steve Rainbird wrote: > I need to check if there is a 0xff in a particular byte of a byte array > (actually in 2 consecutive bytes) which represents a trailer of a file. > > I can't work out how to do it. > > Any help would be appreciated. > > TIA > assume byte[] b if (b[n] == (byte)0xff) // true -- Knute Johnson email s...

regexp for legal JNDI name (covering check for 2 space sequence)
I found I needed to build a regexp for a legal JNDI name. Tracing through the schemas, it appears that a JNDI name is supposed to be a "xsd:token", which has a curious definition. From the definition, it doesn't have leading or trailing spaces, or carriage returns, line feeds, or tabs. The odd part is that it cannot have sequences of TWO or more spaces, but single spaces are allowed. I'm not concerned about the leading/trailing spaces. The two-space thing is what I can't figure out. In general, how do you specify a regexp to match a string that specifies a substring...

Hopefully simple lock-free problem (C-arrays)
Hi, The world of lock-free programming is still mostly a mistery to me, but I hope my problem is simple enough. It surely looks simple to me :-) I have a global definition (of a predicate, but who cares) that has local versions for each thread. Threads come and go. I don't know how many there are, but the infrastructures provides a small unique integer for each of them. Currently, the code is this: if ( true(def, P_THREAD_LOCAL) ) { int i = LD->thread.info->pl_tid; Definition local; LOCKDYNDEF(def); if ( !def->definition.local || i...

MAC sends double attachments
Hi! I have a strange problem... When MAC clients send an e-mail with certain types of attachments, they arrive twice(the right file and a smaller one that is not openable). Better, if i send DOC, PLN, BMP files it happens. If i send DWG, XLS, PDF files all works correctly, only the right file is sent. Any ideas ? ? ? Thank you in advance!!! Mark ...

Error checking reads
I was taught to check *anything* that produced a return code. In I think all perl programs I have ever seen I see opens followed by "or die ....." But how does one check the <> operator? I suppose one could code my @a = <$somehandle> or die ......... and my $a = <$somehandle> or die ........... but what about while ( <$somehandle> ) ? TIA -- Regards Dave Saville Dave Saville <dave@invalid.invalid> wrote: > I was taught to check *anything* that produced a return code. A rather obvious exception is the return value from print(). Once you...

On sysprocplan being locked
Guys, This had been question of discussion in the iiug forum in many occasions or for years. Correct me if I am wrong, I can recall one saying that altering and modifying objects in the database will cause IDS to force the reoptimization of stored procedures thereby at times causing sysprocplan to lock. Does the "altering and modifying objects" apply to temp tables where we create and drop indexes. In my situation, killing the sessions and update stats for the procedures resolve it. But I am only looking for a root cause now, trying to narrow down or isolate the problem ...

antenna pattern
how i plot the different antennas patterns using matlab "m files" There is a good tool box that will probably have what you need and is well documented. Find it here <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4456&objectType=file> mina gerges wrote: > > > how i plot the different antennas patterns using matlab "m files" ...

drawn lines are doubled
I'm working on a ortho mode application on Ubuntu linux with a nvidia card. Horizontal and diagonal lines have started being drawn as closely spaced double lines. But not always, now and then I get single lines like they should be. I'm thinking that it might have something to do with vertical retrace timing of my hardware, but am not sure. Does anyone have an idea? thanks, Bob On Jul 6, 12:28=A0pm, bob <bobs...@xyzzy.com> wrote: > I'm working on a ortho mode application on Ubuntu linux with a nvidia > card. Horizontal and diagonal lines have started being drawn ...

program locks files when they are in use...
Hello, I have the following problem I have acrobat 7.0 as viewer. I'm using TeXnicCenter 6.31 on a windows XP home PC (something which can make pdf-files, not really important). My problem is: Whenever I trie to compile the pdf in TeXnicCenter with the pdf opened in acrobat, I allways have some errors because adobe reader has locked the file. Is there any way you can ask windows to make that adobe acrobat reader DOES NOT lock the files it has opened? Thanks in advance... Plinius plinius@gmail.com wrote: > Hello, I have the following problem > > I have acrobat 7.0 as viewer...

double 0.00274 == double 0.000274 ??
Hi all, in my program, i set up two double numbers, say double a = 0.00274; double b = 0.000274; Those a and b are used paramters and so they are not supposed to change while program runs. In parameter section of my output, however, those two values come out same. a = 0.00274 b = 0.00274 I don't understand what's going on here. Does anyone have any ideas? Thank you. Jong-Hoon Jonie wrote: > I don't understand what's going on here. Does anyone have any ideas? There is a bug in your code. The code you didn't show. You could e.g. use a debugger to trace where ...

++ / -- operators with floats and doubles
Yesterday I found in a piece of code a float being incremented with ++. For some reason (wrong, I guess...) I thought that only integer types could be incremented that way, and I had never seen floats or doubles incremented that way before. Just to be sure I did a toy program and compiled with gcc -ansi -pedantic -Wall and it worked without any error or warning, showing the correct result. Is it correct to increment floats or doubles with ++ and --? Is it defined or am I getting into the realm of undefined behaviour? If it's correct, can you think of a place where it could be useful? Many ...

Use input variable as a match pattern
Good morning all. Is it possiple to pass a shell script variable into awk and use it as a pattern to select lines for output? if so, any channce of an example or two. Thanks Rob.B Rob Bradford wrote: > Good morning all. > > Is it possiple to pass a shell script variable into awk and use it as > a pattern to select lines for output? > > if so, any channce of an example or two. > > Thanks > > Rob.B Here's a quick example (others here will likely post more examples): #!/bin/sh foo="example" echo "example result" | gawk -vMYVAR=$foo ...

Avoid double for loop
Any ideas how I reduce this double for loop? T = 40; price = rand(T,1); strike = rand(T,1); %%I know i can generate both of them simultaneously but this is just a snippet to give you an idea of what I want to do... for i=1:T for j=1:T-1 intrinsic(i,j) = price(j+1)-price(i); end end In article <fnsqle$s8j$1@fred.mathworks.com>, Anish Goorah <anish.goorah@gmail.com> wrote: >Any ideas how I reduce this double for loop? >T = 40; >price = rand(T,1); >strike = rand(T,1); %%I know i can generate both of them >simultaneously but this is just a snippet t...

superfast centrino notebook, check rendertest!
Hi, I bought me a new notebook/laptop computer, a Dell Latitude D800, 1.6 Ghz (Centrino!), 1 Gb DDR RAM. I had in mind to buy the 2.4 Ghz Inspiron, 2.4 Ghz > 1.6 Ghz, sounds faster, but it isn't! The centrino 1.6 Ghz processor is a little bit faster then the 2.4 Ghz Intel. Some render tests I did in Lightwave, same scene, same everything. AMD Atlon XP 2100+, 1 Gb SDRAM, GeForce4 Ti 4200 128Mb --------------------------------> 9 min 42 sec AMD Atlon XP 2100+, 512 Mb DDR RAM, GeForce2 64Mb -------------------------------> 9 min 7 sec Dell I...

software locking with mac address
Hi all, I'm relatively new to shareware authoring. (I dont know if this is the correct NG to post, if not, please direct me to one) I want to know whether using the MAC address for locking the product is of any real value. If, for example, I do not want to put up my application on the internet for download, and, all my customers need custom software (projects rather than products), then, is hardcoding the mac address into the application (for checking) a bad idea? At the moment I can very well afford to keep a simple spreadsheet with info of which client has which MAC number...

Someone locked you out of your BIOS, never ferr.
I think a virus put a BIOS password in my friend's HP Mini 1000 netbook. I know I didn't do it, and I know it had malware. I've read online several other stories from those who never set a password and are still stuck with one. I read about one repair shop that wanted 325 dollars to unlock the BIOS. Another website wanted $50, But Dogbert has programs to do it for free! For HP, Dell, Fujitsu, Samsung, Compaq, and all that use Phoenix bioses. Check it out. http://dogber1.blogspot.com/2009/05/table-of-reverse-engineered-bios.html Let's hear it for Dogbert! [enormous a...

Problem with double for loop... help!
Hi, &nbsp; I am very stuck, with this problem, i suppose is stupid problem, but i cant see it.. &nbsp; I attached the vi. My problem is when I use the double for loop to looking for the values of source array between 2 elements from another array, when the vi 'search 1d array', when the values is out of range, put 0 on the rest of array elements, and i would like remove all the 0, i want the double for loop, show only the index from the values between these elements. I know each time the for loop search the range, and when it doesn't find any value put 0, but i dont know d...

Materials doubling as *materials*
Sometimes materials double up in material list and the copies show up as *material*. This is not a big deal, but it's boring to delete each of them again and again.. -Andrei ...

how to bracket path/filename in double quotes
The following script, from the May issue of Linux Journal, uses 'icat' to restore files, including their full path. But it fails on paths that contain spaces, such as "Program Files", and I'm not handy enough with scripting to figure out how to bracket the entire path/filename in double quotes. #!/bin/bash DISK=/dev/sdb1 # disk to scan RESTOREDIR=/home/kyle/recovery # directory to restore to mkdir -p "$RESTOREDIR" cat $1 | while read line; do filetype=`echo "$line" | awk {'print $1'}` filenode=`echo "$line" | a...

double usingle multiply with double returned
Hello, Let me first state that I am new to Forth. I am trying to write a program for a circa 1985 device with its embedded Forth. The Forth is a subset of Forth-83 and is missing a few words, e.g. M*/. I've search for a definition of M*/ using other Forth words without any luck. What I need is a multiply (d u -- d). I have already created my own multiply but I suspect that it is not very efficient and thought I'd reach out here. My implementation (grade school multiply): DUP ROT ROT UM* SWAP 2SWAP UM* D+ Thanks. Op Sat, 28 Feb 2009 10:38:51 -0800 (PST) schreef datajerk: >...

nero check
I have "nero check" on startup, may I disable it on startup because I don't se any reason to run it?...thanx.. > I have "nero check" on startup, may I disable it on startup because I don't > se any reason to run it?...thanx.. Do you have Nero installed on your machine ? (I haven`t heard of that specific app so unless it`s part of the new Nero 6.x) Try running MSCONFIG from start/run and see if it`s listed under the right hand tab (this may not work on XP, I refuse to touch the eXcrement Pile) and untick it if it exists. You may also want...

Locks problem
Hi, I have modified the FLCKREC kernel parameter in Unixware but I still experience a locks problem, the FLCKREC has a value of 30000 currently, could someone please guide me on which other parameters I may need to change, or any other way I could get rid of the Locks problem in UNIXWARE 7. the other parameter I have tried to modify is SFNOLIM, but still the problem has persisted. Regards. ken wrote: > Hi, > > I have modified the FLCKREC kernel parameter in Unixware but I still > experience a locks problem, the FLCKREC has a value of 30000 currently, > could someone please...

double linked list #2
I have a simple implementation of double linked list this code is crashing if i enter values not present in the linked list(during insertion) or if i try to delete values not present in the list can u suggest how can i avoid it? #include<stdio.h> #include<stdlib.h> #include<ctype.h> void main() { int i,n,c,x,m,flag=0; struct node{ struct node* next; int data; struct node* prev; }*h,*t,*start,*last,*z,*p,*q; printf("enter the number of nodes"); scanf_s("%d",&n); if(n<=0) { printf("no of nodes cannot be %d\n",n); exit(0)...

double loop
Dear All, I cleared up the notebook but when I plot the picture I don't recover the contour plot desidered.  The colours should be the different correlation coefficient and it is not the case. I will be grateful if you could help Maria   h=0.71 ckms=299792.5 HubE[z_,Om_,Ol_]:=SQRT(Om*(1+z)^3+Ol)dL[z_,Om_,Ol_,h_]:=3.0856*1018*106*ckms/(100*h)*(1+z)*NIntegrate[1/HubE[z,Om,Ol],{z,0,z},MaxRecursion ->100] TabOmegalambda=Table[i,{i,0.1,1.1,0.05}] TabOmegaM=Table[i,{i,0.0,1.0,0.05}] LxOmegalambda={}; Do[ Ol=TabOmegalambda[[k]]; LxOmegaM={}; Do[ Om=TabOmegaM[[...