Re: waiting for another thread without blocking resources...
On Feb 14, 12:57 pm, Lars Uffmann <a...@nurfuerspam.de> wrote:
Cholo Lennon wrote:
AFAIK 2 possibilities:
2- Your thread is not 'joinable'. Threads are joinable if they are
built with a ctor functor parameter (you will get an assert calling
'join' on a non-joinable thread)
Yes, I do construct it with a function parameter, I was told this is the
only way to construct a thread? In the meantime I've also seen the
reset-function, so I am very confused now... So how do I make a joinable
thread? Construct it with thread:thread() and then call thread::reset
The boost thread documentation is not the best (lacks of basic
examples). Try looking the source code examples provided by the
library (looking the underlaying implementation is a good idea too;
It's straightforward if you know win threads or pthreads)
Well - I don't know either... Guess I'll have to get a hardcopy of some
Best Regards & Thanks for your help so far...
Take a look to thread's ctors:
m_thread = reinterpret_cast<void*>(GetCurrentThread());
m_id = GetCurrentThreadId();
// explicit ctor
thread::thread(const function0<void>& threadfunc)
m_thread = reinterpret_cast<void*>(
0, 0, &thread_proxy, ¶m, 0, &m_id));
If you provide a functor, you are constructing a 'joinable' thread.
Ctor without parameter constructs a thread that take the ownership of
the calling thread (this is useful in some situations).
Another way is (as Yannick told you) to use a condition (synchronized
flag). You must wait for a 'set' condition (the 'exit' thread
condition). On the ground, condition::wait calls the same function
than thread::join to perform the wait operation.
PS: Could you provide some code to check the library use?