This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Semaphores in libc


On Thu, Dec 31, 2009 at 1:22 PM, Petr Baudis <pasky@suse.cz> wrote:
> On Thu, Dec 31, 2009 at 01:14:42PM +0000, Paulo J. Matos wrote:
>> Â fl.l_len = 0;
>
> I'm not really that familiar with file region blocks, but I'd expect
> this to be a problem - try non-zero len; but if you end up doing this,
> I think semaphores are more elegant. flock() locks (albeit less portable)
> might be a better fit.
>
> Ultimately, the best practice is to lock directly the resource you need
> exclusive access to - what are you doing in the critical section?
>

In the critical section I am creating a directory. The directory has
the name 'runx' where x is an integer > 0.

The critical section tries to find the first x such that runx does not
exist and when it does not exist, it creates it.
Now, the current problem without the lock is that once I get 24
processes in, two of the processes find that run2 does not exist, and
both use it as their directory.

I don't think there's actually a 'resource' (like a file I would like
to write to) in this case.

-- 
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]