tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: fd code multithreaded race?

> So something naiive like this: [...] will give you the wrong result.


Essentially, you have a shared resource (the fd-number to thing table)
which you are using without any locking.  Of course there are races!

Some threading setups allow different threads to have independent file
descriptor tables, which would avoid the issue you sketch (but, of
course, introduce other issues).

> Never realized file descriptors and threads were so tricky ;)

There's nothing special about file descriptors here.  You have
basically the same issue with any other piece of state which is shared
by all threads.  To pick two more examples the kernel maintains,
working directory and umask.  These are a shared resource; like any
shared resource, accessing them from multiple threads requires care,
and usually locking of some sort.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index