Kraus Philipp
I'm new with boost thread, I have some problems. I have got two methods, one for writing and one for reading my data and I would do this thread-safe. I have tried to do this with boost::unique_lockboost::shared_mutex lock(...), but I have created a deadlock.
For example my methods are called within the threads and set / get data to / from a ublas matrix.
How can I do both methods in the correct way thread-safe?
boost::mutex m; void setData( const size_t row, const size_t col, const size_t data) { boost::unique_lockboost::mutex lk(m); _matrix(row, col) = data } void getData( const size_t row, const size_t col, size_t& a, size_t& b) { boost::unique_lockboost::mutex lk(m); a = _matrix(row, col); b = _matrix(col, row); } Once you've got the basics working, you can change the mutex to a boost::shared_mutex and the lock in getData to a shared_lock rather than a unique_lock if profiling determines that this is the bottle neck, *and* the shared_mutex helps. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976