Re: thread concurrency (POSIX)




Pascal Bourguignon ha scritto:

"gio" <giorginooo.rossi@xxxxxxxx> writes:

Hi all.
I have a multithread application running on a multiprocessor ( 2 thread
can be running at the same time).
Suppose I have 2 thread:
t1 lists the content of a directory (using opendir and readdir_r) and
t2 delete a file.

Suppose also I have a directory /home that contains 2 file txt1 and
txt2.

Consider this scenario:
t1 read and print the content of /home
t2 delete txt1.

if t1 and t2 are running at the same time there are 3 possibility:
1.: t2 deletes txt1 first that t1 reads it with readdir_r
(IN THIS CASE THE OUTPUT OF T1 IS : TXT2)
2.: t2 deletes txt1 after t1 has read it with readdir_r
(IN THIS CASE THE OUTPUT OF T1 IS : TXT1 TXT2 ALSO IF TXT1 DOESN'T
EXIST)
3.: t2 deletes txt1 at the same time t1 reads it with readdir_r

WHAT APPENS IN THIS CASE AT LEVEL OF O.S. ? CAN THIS OPERATION BE
OVERLAPPED?

On one hand, POSIX mandates that file creation (creat, open) and file
suppression (unlink) be atomic. On the other hand, the way readdir
specification is worded, the suppression of a file has no effect on
the other directory entries that should still be all scanned by
readdir.

The only thing is that when the entry is removed after openddir or
rewinddir, it may still be read or not.

So:

reading an entry with readdir ==> the entry was present in the
directory when opendir or
rewinddir was executed.

is the only thing you can know.

This is the same for threads or processes.



--
__Pascal Bourguignon__ http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.

thanks for your answer but I don't understand.
what appens at level of O.S.(e.g. linux) when 2 request for the same
file arrive at the same time (one from readdir_r and the other from
remove ) ?

.



Relevant Pages

  • Re: thread concurrency (POSIX)
    ... On the other hand, the way readdir ... the suppression of a file has no effect on ... The only thing is that when the entry is removed after openddir or ... rewinddir, it may still be read or not. ...
    (comp.os.linux.development.system)
  • Re: thread concurrency (POSIX)
    ... On the other hand, the way readdir ... the suppression of a file has no effect on ... rewinddir, it may still be read or not. ... the directory when unlink modifies it. ...
    (comp.os.linux.development.system)
  • Re: Question on readdir
    ... inside the loop where I read an entry from the directory, ... I modify it or delete it? ... readdirhas inherent races involving time of check versus ... In practice usually readdir is safe if the directory is at most one ...
    (comp.os.linux.development.apps)
  • Question on readdir
    ... When dealing with DIR / opendir / readdir, ... loop where I read an entry from the directory, I modify it or delete ...
    (comp.os.linux.development.apps)