This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Semaphores in libc
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?
Cheers,
--
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net