473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Using multiple file descriptors for the same file

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
2 5367
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: François Pinard | last post by:
This question is a bit technical, but hopefully, this list will offer me good hints or nice solutions. Happily enough for me, it often does! :-) I would need to recognise and play with...
9
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
5
by: John Marshall | last post by:
Hi, Does anyone see a problem with doing: data = file("tata").read() Each time this is done, I see a new file descriptor allocated (Linux) but not released. 1) Will there ever be a point...
14
by: Antoon Pardon | last post by:
Can anyone explain why descriptors only work when they are an attribute to an object or class. I think a lot of interesting things one can do with descriptors would be just as interesting if the...
36
by: Roman Mashak | last post by:
Hello, All! I implemented simple program to eliminate entry from the file having the following structure (actually it's config file of 'named' DNS package for those who care and know): ...
0
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
3
by: ZhukovL | last post by:
I'm having some trouble implementing the handling of multiple pipes in a shell I'm writing. I was hoping someone could point me in the right direction because I really cant see where I'm going...
5
by: yinglcs | last post by:
I have a c/c++ program in linux. I would like to know if I kill my program (e.g. exit(1)), will it release all the file descriptors my program held (regardless if I call close(fd) of each file...
8
ashitpro
by: ashitpro | last post by:
Understanding Ext-2 file system:chapter 1 The first block in each Ext2 partition is never managed by the Ext2 filesystem, because it is reserved for the partition boot sector. The rest of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.