discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Proper use of scoped_lock in out-of-tree module?


From: Johnathan Corgan
Subject: Re: [Discuss-gnuradio] Proper use of scoped_lock in out-of-tree module?
Date: Tue, 2 Jul 2013 16:17:41 -0700

On Tue, Jul 2, 2013 at 4:06 PM, Monahan-Mitchell, Tim <address@hidden> wrote:
 
I see different use cases of this in the gnuradio tree, like:

gr::thread::scoped_lock guard(d_mutex);

gr::thread::scoped_lock l(d_mutex);

gr::thread::scoped_lock lock(d_setlock);

As well as variances of whether the mutex variable is declared in a header file...

Could someone lend some kind words on what is recommended (at least for GR 3.7)?

There is really nothing special or unique going on here.  A scoped lock grabs the associated mutex during its scope lifetime.  The above three are just using different names for the local variable instance of the the lock.

The associated mutex is usually a (private) member viable of a class, and is used as a synchronization object by different class methods.  As a member variable, you have a choice to name it whatever you want.  If the mutex is the only one in the class, we usually call it d_mutex.  If there is more than on mutex in the class, then we give it a unique name.

If you're writing your own code as a class, making the mutex a member variable and calling it d_mutex, and calling the local scoped lock object 'guard', is probably the most descriptive, but again, it's up to you.

--
Johnathan Corgan
Corgan Labs - SDR Training and Development Services
http://corganlabs.com
reply via email to

[Prev in Thread] Current Thread [Next in Thread]