You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Graham Leggett <mi...@sharp.fm> on 2001/07/30 23:39:01 UTC

Handholding: Locking

Hi all,

I need some handholding with the porting of some of the auth_ldap code
from v1.3 to v2.0.

In the v1.3 code, I have locks being created like this:

 mtx = ap_create_mutex(NULL);
 GET_MUTEX(mtx);
 RELMUTEX(mtx);

What would the above look like using apr_lock.h from APR?

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."

Re: Handholding: Locking

Posted by Aaron Bannert <aa...@ebuilt.com>.
On Tue, Jul 31, 2001 at 09:33:42AM +0200, Graham Leggett wrote:
> > A read/write lock will allow simultaneous "readers", and will provide
> > exclusive "writers". As an application developer using APR, you'd have to
> > use apr_lock_acquire_rw() instead of the normal apr_lock_acquire() you
> > use with a mutex, so that you can ask for a read or a write lock. What this
> > gives you is finer grain control over how much parallization certain parts
> > of you code may endure.
> 
> Ok - In the code I am busy porting, a shared memory cache is
> implemented. When something writes to the cache, nothing else must read
> or write. When something is read from the cache, anyone else may read
> simultaneously without a problem. Is this a job for a read/write lock?

That sounds right to me. Make sure the lock exists in your shared
memory address space (of course) :)

-aaron


Re: Handholding: Locking

Posted by Graham Leggett <mi...@sharp.fm>.
Justin Erenkrantz wrote:

> > Ok - In the code I am busy porting, a shared memory cache is
> > implemented. When something writes to the cache, nothing else must read
> > or write. When something is read from the cache, anyone else may read
> > simultaneously without a problem. Is this a job for a read/write lock?
> 
> I think you've answered your own question.  (Yes.)  -- justin

Cool :) Just making sure I understand this stuff correctly before I go
missioning off to try and make it work. Thanks :)

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."

Re: Handholding: Locking

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Tue, Jul 31, 2001 at 09:33:42AM +0200, Graham Leggett wrote:
> Ok - In the code I am busy porting, a shared memory cache is
> implemented. When something writes to the cache, nothing else must read
> or write. When something is read from the cache, anyone else may read
> simultaneously without a problem. Is this a job for a read/write lock?

I think you've answered your own question.  (Yes.)  -- justin


Re: Handholding: Locking

Posted by Graham Leggett <mi...@sharp.fm>.
Aaron Bannert wrote:

> A mutex does simple mutual-exclusion. All accesses to the critical section
> are serialized.

Ok.

> A read/write lock will allow simultaneous "readers", and will provide
> exclusive "writers". As an application developer using APR, you'd have to
> use apr_lock_acquire_rw() instead of the normal apr_lock_acquire() you
> use with a mutex, so that you can ask for a read or a write lock. What this
> gives you is finer grain control over how much parallization certain parts
> of you code may endure.

Ok - In the code I am busy porting, a shared memory cache is
implemented. When something writes to the cache, nothing else must read
or write. When something is read from the cache, anyone else may read
simultaneously without a problem. Is this a job for a read/write lock?

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."

Re: Handholding: Locking

Posted by Aaron Bannert <aa...@ebuilt.com>.
On Tue, Jul 31, 2001 at 09:06:49AM +0200, Graham Leggett wrote:
> > This is for a intraprocess mutex.  The flags in apr_lock.h can tell you
> > how to do other types of locks.
> 
> What is the difference between a APR_MUTEX lock and an APR_READWRITE
> lock?

A mutex does simple mutual-exclusion. All accesses to the critical section
are serialized.

A read/write lock will allow simultaneous "readers", and will provide
exclusive "writers". As an application developer using APR, you'd have to
use apr_lock_acquire_rw() instead of the normal apr_lock_acquire() you
use with a mutex, so that you can ask for a read or a write lock. What this
gives you is finer grain control over how much parallization certain parts
of you code may endure.

HTH,
-aaron


Re: Handholding: Locking

Posted by Graham Leggett <mi...@sharp.fm>.
Justin Erenkrantz wrote:

> > I need some handholding with the porting of some of the auth_ldap code
> > from v1.3 to v2.0.
> >
> > In the v1.3 code, I have locks being created like this:
> >
> >  mtx = ap_create_mutex(NULL);
> >  GET_MUTEX(mtx);
> >  RELMUTEX(mtx);
> 
> apr_lock_create(&mtx, APR_MUTEX, APR_INTRAPROCESS, NULL, pool);
> apr_lock_acquire(mtx);
> apr_lock_release(mtx);
> 
> This is for a intraprocess mutex.  The flags in apr_lock.h can tell you
> how to do other types of locks.

What is the difference between a APR_MUTEX lock and an APR_READWRITE
lock?

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."

Re: Handholding: Locking

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Mon, Jul 30, 2001 at 11:39:01PM +0200, Graham Leggett wrote:
> Hi all,
> 
> I need some handholding with the porting of some of the auth_ldap code
> from v1.3 to v2.0.
> 
> In the v1.3 code, I have locks being created like this:
> 
>  mtx = ap_create_mutex(NULL);
>  GET_MUTEX(mtx);
>  RELMUTEX(mtx);

apr_lock_create(&mtx, APR_MUTEX, APR_INTRAPROCESS, NULL, pool);
apr_lock_acquire(mtx);
apr_lock_release(mtx);

This is for a intraprocess mutex.  The flags in apr_lock.h can tell you
how to do other types of locks.

HTH.  -- justin