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.
|