How to terminate thread after timeout?

I connect to database in thread. Standard threads <thread>. I am waiting for termination : thread.join().
But sometimes I must wait infinitely. How to terminate?
In main thread sleep and after delete threads? How to reconcile with join?
I'm not sure what you are asking for. join() actually waits infinitely until the thread terminates (which might never be the case).

If you ask for wait without join(), i.e. independent from thread see condition_variable:

http://www.cplusplus.com/reference/condition_variable/condition_variable/
I can't use join or condition variable because in thread I have database operation which hangs thread.
Join is never reached.
delete thread is enough to close thread by system (for example Linux)?

For example:
in thread : connect to Neo4j database - wait and wait...
main thread know it exceeds timeout, but if mainthread calls delete thread it terminate main thread!
Last edited on
Topic archived. No new replies allowed.