My Thread Programs Crash
- by zp26
I have a problem with threads objectiveC.
The line of code below contains the recv block the program waiting for a datum.
My intention is to launch a thread parallel to the program so that this statement does not block any application.
I put this code in my program but when active switch the program crashes.
Enter the code.
-(IBAction)Chat{
if(switchChat.on){
buttonInvio.enabled = TRUE;
fieldInvio.enabled = TRUE;
[NSThread detachNewThreadSelector:@selector(riceviDatiServer) toTarget:self withObject:nil];
}
else {
buttonInvio.enabled = FALSE;
fieldInvio.enabled = FALSE;
}
-(void)riceviDatiServer{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
int ricevuti;
NSString *datiRicevuti;
ricevuti = recv(temp, &datiRicevuti, datiRicevuti.length, 0);
labelRicezione.text = [[NSString alloc] initWithFormat:@"%s.... %d", datiRicevuti, ricevuti];
[pool release];
}