[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Using multiple file descriptors for the same file

DJ Dharme

10/20/2008 9:55:00 AM

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.
2 Answers

Michael

10/20/2008 11:58:00 AM

0

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

Maxim Yegorushkin

10/20/2008 12:06:00 PM

0

On Oct 20, 10:54 am, DJ Dharme <donjuandharmap...@gmail.com> wrote:

>           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