On 19 Aug 2007, at 4:09 PM, Adam R. Maxwell wrote:

>
> On Aug 19, 2007, at 03:10, Christiaan Hofman wrote:
>
>>
>> On 19 Aug 2007, at 1:50 AM, Adam R. Maxwell wrote:
>>
>>> I was looking at some of the refactoring in Skim, and noticed that
>>> the
>>> file functions are supposed to be thread safe.  Isn't there a
>>> potential race condition in SKTemporaryDirectoryCreating, if  
>>> multiple
>>> threads are creating baseTmpDir or incrementing a counter to find a
>>> unique name?  In BibDesk's NSFileManager method we use
>>> @synchronized(self) to guard against that, but the function might
>>> need
>>> a mutex created in an __attribute__((constructor)) (or use CFUUID to
>>> make a unique name).
>>>
>>> --  
>>> adam
>>
>> @synchronize actually is completely useless here, as this only works
>> when it's used always, which is certainly not true here. Note that
>> NSFileManager itself is not thread safe.
>
> @synchronized() works fine here; it's a category method that only we
> call, so the mutex /is/ always used.  And yes, I know NSFileManager is
> not thread safe...that's why I wrote many of the category methods for
> BibDesk.  Looking at BibDesk again, it still suffers from a race
> condition, since it returns a path without creating it, so subsequent
> parallel calls can easily get the same name.
>
> -- 
> adam

Well, @synchronized is OK for getting the unique number, but I'm not  
sure if accessing defaultManager itself is thread safe. Moreover the  
call to createDirectoryAtPath:attributes: may not be thread safe.

As for the race condition, this probably is not a big problem. If the  
file is not created, it has a pretty arbitrary file name. Chances  
that two files with the same base name are created are pretty small.

Christiaan



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
skim-app-develop mailing list
skim-app-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-develop

Reply via email to