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 02:09:28PM +0000, Paulo J. Matos wrote:
> 2009/12/31 Petr Baudis <pasky@suse.cz>:
> > But what's the problem? Why not simply
> >
> > ? ? ? ?int i = 0;
> > ? ? ? ?char buf[PATH_MAX];
> > ? ? ? ?do {
> > ? ? ? ? ? ? ? ?snprintf(buf, sizeof(buf), "run%d", ++i);
> > ? ? ? ?} while (mkdir(buf, 0777) < 0 && errno == EEXIST);
> >
> > mkdir() should be atomic, so each process will always pick a different
> > name.
> >
> 
> That's a good solution! Now, that I look into mkdir() though I can't
> find any reference to it being atomic. Are you sure that's the case?

That is good question; I think it should be the case on all sensible
systems, but I'm not sure. It might be good to ask on the austin-group
mailing list why is it not described as atomic in the POSIX spec.

				Petr "Pasky" Baudis


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