Re: [Boost-users] Boost.Thread locking across two functions

On Fri, 09 Jun 2006 22:51:48 -0300, Peteris Krumins [Newsgroups]
Hello!
I am using a library which itself internally does not use any thread sync mechanisms but it provides callback functions lib_lock() and lib_unlock() which I can specify if the lib is used in multithread environment. lib_lock() would get called before critical segment and after it lib_unlock() would get called.
I read Boost.Thread documentation and I understand that lock concept
is
not thread-safe itself and should be used only at block scope. This makes me think that I have no way to use locking provided by Boost to acquire a lock in lib_lock() function and release it in lib_unlock()? But I am not sure.
Do you have any suggestions if this can be done using Boost?
Thanks! P.Krumins
I don't think it was intended to be used this way, but you can accomplish what you want with the lock_ops<> class: mutex m; lib_lock() { boost::detail::thread::lock_opsboost::mutex::lock (m); } lib_unlock() { boost::detail::thread::lock_opsboost::mutex::unlock (m); } Moshe
participants (1)
-
Moshe Matitya