Hi, as I understand the scoped_lock, it locks every ressource in a code block. What if I dont want to lock a ressource all the time the method is running? Do I have to create a new method? Example: boost::mutex a_mutex; ... { boost::mutex::scoped_lock lock(a_mutex); cou<<"bla"; //much of code where cout dont has to be locked ... } Torsten -----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]Im Auftrag von boost-users-request@lists.boost.org Gesendet: Donnerstag, 14. Dezember 2006 14:55 An: boost-users@lists.boost.org Betreff: Boost-users Digest, Vol 1117, Issue 1 Send Boost-users mailing list submissions to boost-users@lists.boost.org To subscribe or unsubscribe via the World Wide Web, visit http://lists.boost.org/mailman/listinfo.cgi/boost-users or, via email, send a message with subject or body 'help' to boost-users-request@lists.boost.org You can reach the person managing the list at boost-users-owner@lists.boost.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Boost-users digest..."
Hi! you could define a scope where to lock ;) Just like this: boost::mutex a_mutex; ... { { boost::mutex::scoped_lock lock(a_mutex); //lock cout<<"bla"; }//end of scope => unlock //much of code where cout dont has to be locked ... } With Kind Regards, Ovanes Markarian On Thu, December 14, 2006 15:12, Goroll, Torsten wrote:
Hi,
as I understand the scoped_lock, it locks every ressource in a code block. What if I dont want to lock a ressource all the time the method is running? Do I have to create a new method?
Example:
boost::mutex a_mutex; ... { boost::mutex::scoped_lock lock(a_mutex); cou<<"bla";
//much of code where cout dont has to be locked ... }
Torsten
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]Im Auftrag von boost-users-request@lists.boost.org Gesendet: Donnerstag, 14. Dezember 2006 14:55 An: boost-users@lists.boost.org Betreff: Boost-users Digest, Vol 1117, Issue 1
Send Boost-users mailing list submissions to boost-users@lists.boost.org
To subscribe or unsubscribe via the World Wide Web, visit http://lists.boost.org/mailman/listinfo.cgi/boost-users or, via email, send a message with subject or body 'help' to boost-users-request@lists.boost.org
You can reach the person managing the list at boost-users-owner@lists.boost.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Boost-users digest..." _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ovanes Markarian wrote:
Hi!
you could define a scope where to lock ;) Just like this:
boost::mutex a_mutex; ... { { boost::mutex::scoped_lock lock(a_mutex); //lock cout<<"bla"; }//end of scope => unlock
//much of code where cout dont has to be locked ... }
Or: foo() { boost::mutex::scoped_lock lk(a_mutex); cout << "bla" ; lk.unlock(); .... some other stuff unlocked lk.lock(); // lock again ..... } The lock is (conditionally) unlocked however when you leave the scope. Roland
Hi, I was about to use the sleep method for threads when something crossed my mind: - Is this the actual sleep function which will block all resources hold by the thread during the sleeping time or - Is this something with a more wait-wise behaviour were the thread leaves resources to be used by others while waiting? Anybody knows? Thanks in advance.
Berenguer Blasi escribió:
Hi,
I was about to use the sleep method for threads
do you mean boost::thread::sleep()?
when something crossed my mind:
- Is this the actual sleep function which will block all resources hold by the thread during the sleeping time or
Yes, it is.
- Is this something with a more wait-wise behaviour were the thread leaves resources to be used by others while waiting?
No it isn't. ;) Regards, Raul.
You can use lock/unlock methods no? -----Mensaje original----- De: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]En nombre de Ovanes Markarian Enviado el: jueves, 14 de diciembre de 2006 15:20 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] threads / scoped_lock Hi! you could define a scope where to lock ;) Just like this: boost::mutex a_mutex; ... { { boost::mutex::scoped_lock lock(a_mutex); //lock cout<<"bla"; }//end of scope => unlock //much of code where cout dont has to be locked ... } With Kind Regards, Ovanes Markarian On Thu, December 14, 2006 15:12, Goroll, Torsten wrote:
Hi,
as I understand the scoped_lock, it locks every ressource in a code block. What if I dont want to lock a ressource all the time the method is running? Do I have to create a new method?
Example:
boost::mutex a_mutex; ... { boost::mutex::scoped_lock lock(a_mutex); cou<<"bla";
//much of code where cout dont has to be locked ... }
Torsten
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]Im Auftrag von boost-users-request@lists.boost.org Gesendet: Donnerstag, 14. Dezember 2006 14:55 An: boost-users@lists.boost.org Betreff: Boost-users Digest, Vol 1117, Issue 1
Send Boost-users mailing list submissions to boost-users@lists.boost.org
To subscribe or unsubscribe via the World Wide Web, visit http://lists.boost.org/mailman/listinfo.cgi/boost-users or, via email, send a message with subject or body 'help' to boost-users-request@lists.boost.org
You can reach the person managing the list at boost-users-owner@lists.boost.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Boost-users digest..." _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
Berenguer Blasi
-
Goroll, Torsten
-
Ovanes Markarian
-
Raúl Huertas
-
Roland Schwarz