I've created to create a listener class that will call methods such as on_left_mouse_released on a controller object. It works fine, and now I am trying to have it run in another thread using boost::thread. However, I seem to be doing something wrong. I am new to multithreading, so this could easily be a simple error.
Here are selected portions from the listener class:
void Listener::listen()
{
keepListening = true;
while(keepListening)
{
if(timerEnabled)
{
this->CheckForTimerEvent();
if( !PendingMouseOrKeyEvents()) //readconsoleinput is blocking
continue;
}
if(!keepListening) //could have been changed in a timer event
break;
if(!mouseEnabled && !keyboardEnabled)
continue;
ReadConsoleInput(hIn, &InRec, 1, &NumRead);
//see http://msdn.microsoft.com/en-us/library/windows/desktop/ms683499(v=vs.85).aspx
//for more information on InRec and its submembers
if(mouseEnabled &&InRec.EventType == MOUSE_EVENT)
{
this->ProcessMouseEvent(InRec.Event.MouseEvent);
cout << "here";
}
else if(keyboardEnabled && InRec.EventType == KEY_EVENT)
{
this->ProcessKeyEvent(InRec.Event.KeyEvent);
cout << "here";
}
}
}
void Listener::operator()()
{
listen();
}
In my main function, if I create a Listener object named listener, then say "listener();" both of the couts occur with the appropriate events. However, if I use "boost::thread listen (boost::ref(listener));" instead, nothing happens.
Does anyone see why this is?