discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Setter Gettor method style


From: Nicola Pero
Subject: Re: Setter Gettor method style
Date: Mon, 5 Aug 2002 13:01:04 +0100 (BST)

> True, you don't get it for free, you need to use locks. However,
> setters/getters like this would be safe:
> 
> -(void) setFoo: (NSString *)newfoo
> {
>  [foo_lock lock];
>  ASSIGN(foo,newfoo);
>  [foo_lock unlock];
> }
> 
> -(NSString *) foo
> {
>  NSString *retval;
>  [foo_lock lock];
>  retval=[[foo retain] autorelease];
>  [foo_lock unlock];
>  return retval;
> }
> 
> To make a class thread-safe by itself, you have to retain and
> autorelease it inside the lock, so you need to do it before returning
> it. If you just return the value without doing the retain/autorelease,
> you can't get thread safety inside the class; the users would be forced
> to handle it themselves.

Ok - now makes sense :-)




reply via email to

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