-(void)startThread {
m_bRunThread = YES;
if(m_bRunThread) {
NSThread* myThread = [[NSThread alloc]initWithTarget:self selector:@selector(display) object:theConditionLock];
[myThread start];
/*((WaitForSingleobject(event,1500) != WAIT_OBJECT_O) || !m_bRunThread) {
m_bRunThread = false;
Trace(_T("Unable to start display Thread\n"));
}*/
}
[self insert];
}
-(void)insert {
[theConditionLock lockWhenCondition:LOCK];
NSLog(@"I'm into insert function of thread!");
[theConditionLock unlockWithCondition:UNLOCK];
}
-(void)display {
NSLog(@"I'm into display function");
while (YES) {
[theConditionLock lockWhenCondition:LOCK];
NSAutoreleasePool* pool1 = [[NSAutoreleasePool alloc]init];
NSLog(@"Into the lock");
[theConditionLock unlockWithCondition:UNLOCK];
[pool1 drain];
}
}
插入和顯示方法都是在調用insert方法之前調用startThread.display。但是我希望顯示等待插入完成其執行。如果它停止了一個信號必須被髮送到開始線程顯示錯誤信息。Objective C中的線程
如何做到這一點。
但是在上面的代碼中,顯示方法首先被調用,並且在無限循環中繼續。
如果我那麼做,我需要讓startThread進入休眠狀態,否則線程不會被調用,因爲startThread在調用顯示線程後會退出。 – spandana 2011-06-01 06:01:58
爲什麼這是一個問題?你想做什麼? – skorulis 2011-06-01 06:06:51