|
Boost Users : |
From: Moshe Matitya (Moshe.Matitya_at_[hidden])
Date: 2006-06-14 12:21:58
On Fri, 09 Jun 2006 22:51:48 -0300, Peteris Krumins [Newsgroups]
<pknewsgroups_at_[hidden]> wrote:
>
> 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_ops<boost::mutex>::lock (m);
}
lib_unlock()
{
boost::detail::thread::lock_ops<boost::mutex>::unlock (m);
}
Moshe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net