2
我正在使用dispatch_semaphore_wait來停止當前線程,但它看起來像停止了我所有的線程。dispatch_semaphore_wait停止iPhone APP中的所有線程
代碼:
SampleReader *reader = [[SampleReader alloc] initWithHostname:hostname andFilePath:filepath];
reader.endHandler = endHandler;
[reader start];
dispatch_semaphore_wait(reader->mSem, DISPATCH_TIME_FOREVER);
我的發車方法是這樣的:
mFileStream = [[NSOutputStream outputStreamToFileAtPath:[fileurl path] append:FALSE] retain];
[mFileStream open];
mNetworkStream = (NSInputStream *)CFReadStreamCreateWithFTPURL(NULL, (CFURLRef)ftpurl);
mNetworkStream.delegate = self;
[mNetworkStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[mNetworkStream open];
我得到回調的委託方法之一,其中I信號旗語
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode{
switch (eventCode)
Case NSStreamEventErrorOccurred:
dispatch_semaphore_signal(mSem);
break;
case NSStreamEventEndEncountered:
dispatch_semaphore_signal(mSem);
break;
}
但是,當我在信號量上發送等待時,不調用委託方法。 它只有被稱爲當我註釋掉
//dispatch_semaphore_signal(mSem);
任何幫助將不勝感激。