We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, in read function you don't use mutex. So there is a race condition. Code start from line 117 in file HidApi.cpp:
bool isTimeout = true; while( (std::clock()-start) < end ) { if( this->readAvailable() > 0 ) { ret = this->readFifoBuffer.front(); this->readFifoBuffer.pop(); isTimeout = false; break; } } }
Segmentation fault can be rise in line:
this->readFifoBuffer.pop();
when device thread is during change te readFifoBuffer.
Resolve: I've make "pthread_mutex_t runningMutex;" public in class HidDeviceReaderThread. Then I've change read function to this:
bool isTimeout = true; while( (std::clock()-start) < end ) { #ifdef OS_LINUX pthread_mutex_lock( &(this->backgroundReader->runningMutex)); #endif if( this->readAvailable() > 0 ) { ret = this->readFifoBuffer.front(); this->readFifoBuffer.pop(); isTimeout = false; #ifdef OS_LINUX pthread_mutex_unlock( &(this->backgroundReader->runningMutex)); #endif break; } else { #ifdef OS_LINUX pthread_mutex_unlock( &(this->backgroundReader->runningMutex)); #endif } } }
Now it works fine.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi,
in read function you don't use mutex. So there is a race condition. Code start from line 117 in file HidApi.cpp:
Segmentation fault can be rise in line:
when device thread is during change te readFifoBuffer.
Resolve:
I've make "pthread_mutex_t runningMutex;" public in class HidDeviceReaderThread.
Then I've change read function to this:
Now it works fine.
The text was updated successfully, but these errors were encountered: