discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: thread question


From: Aurelien
Subject: Re: thread question
Date: Thu, 27 Dec 2001 19:39:44 +0100

Le jeudi 27 décembre 2001, à 07:22 PM, Richard Frith-Macdonald a écrit :

No .... the lock needs to be created beforehand. You could have a single global lock
created at the start of your program, and do something like this.

Ah !

Pardon me, I don't understand a word of the following code:
- (void) doSomething
{
  static NS(Recursive)Lock *aLock = nil;

You can declare a static variable (that is, a class variable, then ?) inside a method ???

  if (aLock == nil)
    {
      [globalLock lock];
      if (aLock == nil)

Hey ! we already know that aLock is nil !

        {
          aLock = [[NS(Recursive)Lock alloc] init];
        }
      [globalLock unlock];
    }

Do you mean, that we must obtain a lock to allocate the lock ? That sounds logical to me. Why wouldn't we simply create the lock in the object's init method ? Maybe you suggest that this is more "lazy", ie we don't necessarily *have* to have an NSLock associated with the *whole* object, hence the need for a globalLock ?

  [aLock lock];
  // do something
  [aLock unlock];
}


Now, what I don't understand is the use in java of the wait(), notify () and notifyAll() methods.

There is really no direct equivalent ... but NSConditionLock should cover most of this I think.


Right, I forgot that one ! Should be OK.

Thanks Richard,

Aurélien




reply via email to

[Prev in Thread] Current Thread [Next in Thread]