macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

lock

ロックが使用中ならスレッドを停止させます

解説

ロックが使用中ならスレッドを停止させます。
使用中でなければロックを使用中にします。

返り値

( void )

なし

引数

クラス

NSLocking

Instance Methods

使用可能

10.0

参照

例文

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
theLock = [[NSLock alloc] init];

[NSApplication detachDrawingThread:@selector(action:) toTarget:self withObject:@"thread1"];
[NSApplication detachDrawingThread:@selector(action:) toTarget:self withObject:@"thread2"];

}
//スレッド
-(void)action:(id)arg
{
   int i;
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
[theLock lock];//ロック
  for (i=1;i<2000;i++) {
    NSLog([NSString stringWithFormat:@"%@ %d",arg,i]);
    }
[theLock unlock];//ロック解除
    [pool release];
    [NSThread exit];
}
@end