POSスレッドでC言語を使用して何をしたいのかを説明したいと思います
pthread_t tid1, tid2;
void *threadOne() {
//some stuff
}
void *threadTwo() {
//some stuff
pthread_cancel(tid1);
//clean up
}
void setThread() {
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&tid1,&attr,threadOne, NULL);
pthread_create(&tid2,&attr,threadTwo, NULL);
pthread_join(tid2, NULL);
pthread_join(tid1, NULL);
}
int main() {
setThread();
return 0;
}
したがって、上記は私がObjective-cでやりたいことです。これは私がobjective-cでスレッドを作成するために使用するものです:
[NSThread detachNewThreadSelector:@selector(threadOne) toTarget:self withObject:nil];
スレッドIDのようなものを宣言して初期化しないので、あるスレッドを別のスレッドからキャンセルする方法がわかりません。誰かが私のCコードをobjective-cに変換したり、他の何かを勧めたりできますか?