I would like to explain what I want to do by using C language with pthreads
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;
}
So the above is what I want to do in objective-c. This is what I use in objective-c to create threads:
[NSThread detachNewThreadSelector:@selector(threadOne) toTarget:self withObject:nil];
As I do not declare and initialise anything like thread id, I do not know how to cancel one thread from another thread. Can someone convert my C code into objective-c or recommend me something else?