저는 Java 개발자이며 iPhone에서 스레드 동기화를 수행해야합니다. 스레드가 있는데, 다른 스레드를 호출하고 그 자식 스레드가 끝날 때까지 기다릴 필요가 있습니다. java에서 나는 wait/notify를 호출하여 모니터를 사용합니다.iphone 스레드 동기화
어떻게 아이폰에서 프로그래밍 할 수 있습니까?
감사
저는 Java 개발자이며 iPhone에서 스레드 동기화를 수행해야합니다. 스레드가 있는데, 다른 스레드를 호출하고 그 자식 스레드가 끝날 때까지 기다릴 필요가 있습니다. java에서 나는 wait/notify를 호출하여 모니터를 사용합니다.iphone 스레드 동기화
어떻게 아이폰에서 프로그래밍 할 수 있습니까?
감사
약 NSOperation
dependencies도 NSNotification
알림을 읽어보십시오.
NSConditionLock는
가 개인적으로, 나는의 pthreads를 선호 모든 작업을 수행합니다. 스레드가 완료 될 때까지 차단하려면 pthread_join
이 필요합니다. pthread_cond_t
을 설정하고 하위 스레드가이를 알릴 때까지 호출 스레드가 대기하도록 할 수 있습니다.
void* TestThread(void* data) {
printf("thread_routine: doing stuff...\n");
sleep(2);
printf("thread_routine: done doing stuff...\n");
return NULL;
}
void CreateThread() {
pthread_t myThread;
printf("creating thread...\n");
int err = pthread_create(&myThread, NULL, TestThread, NULL);
if (0 != err) {
//error handling
return;
}
//this will cause the calling thread to block until myThread completes.
//saves you the trouble of setting up a pthread_cond
err = pthread_join(myThread, NULL);
if (0 != err) {
//error handling
return;
}
printf("thread_completed, exiting.\n");
}