0

次のコードは、期待どおりにコンパイルおよび実行されます。

#import <objc/objc.h>
#import <Foundation/Foundation.h>

BOOL loopValue = YES;
@interface myThread:NSObject
-(void) enterThread: (NSArray *) elemt count: (NSString *) x;
@end

@implementation myThread
-(void) enterThread : (NSArray *) elemt
{
  NSLog (@" Inside mythread ");
  NSAutoreleasePool *pool =  [[ NSAutoreleasePool alloc] init];
 int i;
int cnt =10;
  for(i=0; i<cnt; i++) {
  NSLog (@"Number of elemennts in array %i ", [elemt count]); 
  [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
  }

  loopValue = NO; 
  [pool drain];  
}
@end



int main ( int argc, char ** argv)
{
  NSAutoreleasePool *pool = [[ NSAutoreleasePool alloc] init];
  // id tobj = [[myThread alloc] init];
  id tobj = [ myThread new ];
  NSLog (@"Starting New Thread ");
   [NSThread detachNewThreadSelector:@selector(enterThread:)  toTarget:tobj withObject:[NSArray arrayWithObjects:@"ram",@"20",nil]];
  while(1)
  if ( loopValue )
    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
   else
      break;


  NSLog (@".. Exiting.. \n");
  [pool drain];
  return 0; 

}

私の質問:

コンパイル中に、次の警告が表示されます。

mythread.m:24:1: warning: incomplete implementation of class ‘myThread’ [enabled by default]

mythread.m:24:1:警告:'-enterThread:count:'のメソッド定義が見つかりません[デフォルトで有効]

実行中

WARNING your program is becoming multi-threaded, but you are using an ObjectiveC runtime library .... Removed due to redability]hich does not have a thread-safe implementation of the +initialize method. ......

私は何が間違っているのですか?警告/実行時エラーの両方を回避する方法。

4

1 に答える 1

1

宣言しenterThread:count:たメソッドは ですが、実装するメソッドは ですenterThread:。また、あなたが得ているその警告は、古い GNUstep ランタイムからしか見たことがないはずですが、そうではないと思います。

于 2012-04-14T12:58:36.307 に答える