[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: A proposed solution for svn admin directory names

From: Duane Griffin <d.griffin_at_psenterprise.com>
Date: 2005-06-29 20:37:24 CEST

On Wed, 2005-06-29 at 18:26, Joseph Galbraith wrote:
> char* getadmdir()
> {
> static char* szAdmDir = 0;
> if ( szAdmDir == 0 )
> {
> szAdmDir = ::getenv("SVN_ADM_DIR");
> if ( szAdmDir == 0 )
> szAdmDir = ".svn";
> }
>
> return szAdmDir;
> }

Aside from the possibility of non-atomic pointer assignment, there is
another failure case where the function returns NULL:

Consider the situation with two threads A and B where SVN_ADM_DIR is not
set. A and B both enter the function and the first if block. Thread A
continues into the second if block and does the assignment. Now thread B
executes the getenv line. Thread A executes the return statement,
returning the current global value of szAdmDir, which has been set by
thread B to NULL. Bang.

It really isn't possible to do this sort of thing in a thread-safe
manner without synchronization.

Regards,
Duane.

-- 
Duane Griffin
Senior Software Developer
Process Systems Enterprise Limited - "The model company"
Bridge Studios, 107a Hammersmith Bridge Road, London W6 9DA
Call +44 (0)20 8563 0888 or visit us at www.psenterprise.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jun 29 20:38:23 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.