Giter VIP home page Giter VIP logo

wqueue's People

Contributors

vichargrave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wqueue's Issues

Does not safely destroy the mutex (pthread_mutex_destroy can get called while in pthread_cond_wait)

Hi Vic, first of all thanks for sharing your code! It was just the missing peace to solve issues in my project!

Unfortunatly your code does not safely destroy the mutex. The documentation says:

It shall be safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex, or a mutex that another thread is attempting to lock, or a mutex that is being used in a pthread_cond_timedwait() or pthread_cond_wait() call by another thread, results in undefined behavior.

Thats exactly what happens sometimes ;(

In my case ~wqueue() gets called from another thread while your wqueue::remove() method just executes pthread_cond_wait. However, pthread_mutex_destroy(&m_mutex) should never get called at this time. pthread_cond_wait checks at the beginning for destroyed mutex. That's why it doesn't always crash, but sometimes the destroy happens after that check ;(

To reproduce I open and immediately close the dialog that initializes and destroys the thread very often.

To safely destroy the thread probably requires a design change.

In Java I solved that problem with a work item that stops the thread. Maybe that would not require a vast design change.

compile error..

I try to test it but there is a compile error like:
g++ -c -Wall -I../threads main.cpp -o main.o
g++ -c -Wall -I../threads ../threads/thread.cpp -o ../threads/thread.o
g++ -lpthread main.o ../threads/thread.o -o wqueue
../threads/thread.o: In function Thread::~Thread()': thread.cpp:(.text+0x9b): undefined reference to pthread_detach'
thread.cpp:(.text+0xb7): undefined reference to pthread_cancel' ../threads/thread.o: In function Thread::start()':
thread.cpp:(.text+0x11e): undefined reference to pthread_create' ../threads/thread.o: In function Thread::join()':
thread.cpp:(.text+0x16c): undefined reference to pthread_join' ../threads/thread.o: In function Thread::detach()':
thread.cpp:(.text+0x1c0): undefined reference to `pthread_detach'
collect2: error: ld returned 1 exit status
Makefile:12: recipe for target 'wqueue' failed
make: *** [wqueue] Error 1

Moreover, I want to get results back to the main().
How can I do it?
Best thanks for you help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.