Problem with threads
I'm trying to create a separate thread for my program which basically polls using the read command. However this new thread seems to block the main thread, anyone know why this could happen.
In main I call this function pthread_create(&mainEventThread, NULL, GenericEventThread, NULL); which calls /*New threads start function */ void *GenericEventThread() { short int i, nError = -1; int nEventNumber; unsigned char buffer[16]; memset(buffer, '\0', 16); while(1){ /*Switches read mode to read events from the interrupt pipe */ ioctl(sd, IOC_INT); /*Reads event packet from the interrupt pipe */ nError = read(sd, buffer, 16); if(nError != -1){ /*Acknowledge the event once the event number is decode */ nEventNumber = decodeEvent(buffer); doInterruptAcknowledge(nEventNumber); doInterruptComplete((int)nEventNumber); nError = -1; memset(buffer, '\0', 16); } } } I've used pthread_self to check that a new thread is being created, so why is the while loop in one thread blocking the main thread from running, I haven't used the join function anywhere in my code. |
The thread shouldn't block the main one. However, the read() call may. Are you sure it doesn't block?
|
Thanks for pointing that out, yes the problem was that the read was blocking.
|
All times are GMT -5. The time now is 01:41 AM. |