05-28-05 07:48 AM
On Thu, 26 May 2005 22:40:46 -0700, Kashish wrote:
> Is file<<"Some string"<<endl is an atomic operation.
> where file is an ofstream object.
>
> If we output a string in ofstream and we provide endl after that,Can we
> make sure the whole string will be put in file at a time or the string
> can appear in parts.String lenfth is no more than 50 chars.
>
> I have 2 processes on different solaris boxes (NFS) running in
> parallel.one process writing lines to the file and other process
> reading lines from the file. Can we make sure filestream and endl that
> reading process will never get half entry. Either it will get full
> entry or no entry. or Do I need to use File Locking?
Irrespective of any issues involved with buffering and flushing by the C++
iostream mechanism if you are using NFS you have to take special steps to
ensure updates are seen by the reader. Do a bit of googling for "nfs"
and "cto" or "close to open semantics". Also, even if you implement CTO to
deal with cache coherency there are still potential race conditions that
could, at least theoretically, cause a "half entry" to be visible by the
reader. To solve that you have to use POSIX style locking. That will
adversely affect performance but that's that price you'll have to pay if
you don't want to use a clustered (i.e., distributed) filesystem.
[ Post a follow-up to this message ]
|