By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Using multiple file descriptors for the same file

P: n/a
Hi all,
I am writing a multi-threaded application in c++ running on
solaris. I have a file which is updated by a single thread by
appending data into the file and at same time the other threads are
reading the content written into the file. Can anybody tell me is
there a performance or any other gain (except for the multex locking)
by using different file descriptors in each thread for the same file
rather than using a single FD with a mutex (or read write) lock. Is it
an overhead using multiple FDs for a single file? Pardon me if I am
posting this in a wrong group.

Thanks!

DJD.
Oct 20 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DJ Dharme wrote:
Hi all,
I am writing a multi-threaded application in c++ running on
solaris. I have a file which is updated by a single thread by
appending data into the file and at same time the other threads are
reading the content written into the file. Can anybody tell me is
there a performance or any other gain (except for the multex locking)
by using different file descriptors in each thread for the same file
rather than using a single FD with a mutex (or read write) lock. Is it
an overhead using multiple FDs for a single file? Pardon me if I am
posting this in a wrong group.

Thanks!

DJD.
This is an OS issue, not c++ issue. I think that you may post in
comp.unix.solaris
Oct 20 '08 #2

P: n/a
On Oct 20, 10:54*am, DJ Dharme <donjuandharmap...@gmail.comwrote:
* * * * * I am writing a multi-threaded application in c++ running on
solaris. I have a file which is updated by a single thread by
appending data into the file and at same time the other threads are
reading the content written into the file. Can anybody tell me is
there a performance or any other gain (except for the multex locking)
by using different file descriptors in each thread for the same file
rather than using a single FD with a mutex (or read write) lock. Is it
an overhead using multiple FDs for a single file?
It depends on how you create file descriptors on the same file.

If you use open() with the same file name, you'll get file descriptors
referring to a different file description, referring to the same file.

fd0 -description0 \
fd1 -description1 -file
fd2 -description2 /

If, on the other hand, you use dup() to get new file descriptors,
these file descriptors refer to the same file description.

fd0 \
fd1 -description -file
fd2 /

File description is a structure where file offset and access mode are
stored among other things. This structure is protected by a mutex (or
a spin-lock).

In the latter case the threads will contend to access the same file
description when you do read/write().
Pardon me if I am posting this in a wrong group.
Better use comp.unix.programmer for Unix specific questions. Replies
to this message should automatically go there.

--
Max
Oct 20 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.