c++ - pthread_cond_wait() not waking up on signal -
i trying wake thread queue process data, except it's not waking up. not sure if approach flawed. here code:
main:
struct threadoperationstruct _threadio; int main(int argc, char** argv) { // threads created here... }
my waiting thread:
void decompresslogfile::wait() { while (!_threadio.endevent) { pthread_mutex_lock(&lock); size_t queuesize = _threadio.decompresslogqueue.size(); if (!queuesize) { // prevent further thread execution fprintf(stdout, "decompresslogfile() thread sleeping...\n"); pthread_cond_wait(&_threadio.decompressqueuenotify, &lock); } else { fprintf(stdout, "processing compressed log files. queue size %lu\n", queuesize); /* * async tasks need go here... */ //bzip2_decompressfile(); _threadio.decompresslogqueue.pop(); } } fprintf(stdout, "wait() end\n"); }
another class on thread:
_threadio.decompresslogqueue.push(newlog); pthread_cond_signal(&_threadio.decompressqueuenotify);
the struct
looks this:
struct threadoperationstruct { std::queue<std::string> decompresslogqueue; std::queue<std::string> processlogqueue; void notifydecompressthread() { fprintf(stdout, "notifying..\n"); pthread_cond_signal(&this->decompressqueuenotify); } pthread_cond_t decompressqueuenotify; pthread_cond_t processqueuenotify; bool endevent = false; }; extern threadoperationstruct _threadio;
now, question irrelevant question above... i've had experience using c++11 threads on windows , not on linux. i've read around portability, should remain pthread on linux. hold true c++14?
thanks
Comments
Post a Comment