[ Back to Table of Contents ] [ << ] [ >> ]


From:    Kan Yabumoto           tech@xxcopy.com
To:      XXCOPY user
Subject: Concurrent access of a file
Date:    2007-09-27


    In a multi-tasking operating system such as Windows, many
    processes (executing programs) are running at any given moment.
    Inevitably, there will be instances where a file is accessed
    by two or more processes at the same time.

    Ideally speaking, if all programs completely avoid accessing
    the same file, there will be no problems except every program
    needs to wait for its turn for access.  Therefore, if the
    programs coordinate their accesses to a common file whenever
    the simultaneous access can be safely performed, the system
    performance can be increased.  For example, when all programs
    that access the file in read-only mode, then, sharing the files
    should be done and such file sharing takes place all the time.

    In the Windows system, files are available for access on a
    first-come-first-served basis.  That is, when a file is currently
    not opened by any program, it is available to any program (provided
    that the log-in user has the necessary access permission) in any
    share mode it wants.  The programmer who writes the application
    has discression in the determining the file share setting.  The
    application declares the file share mode setting at the time of
    opening the file.  The default mode of opening a file is an
    exclusive access (not to share with any other program until the
    file is closed).  Fair-minded programs often share the file they
    open for read-only purposes.

The file share control switch:

    XXCOPY (starting with ver 2.96.0) now allows the user to
    select how the file sharing is performed with the following
    new switches.

      /SHR             // Enables read-share  (default)
      /SHW             // Enables write-share
      /SHRW or /SHWR   // Enables rd/wr-share (old default)
      /SH0             // Disables file share (most conservative)

Typical scenarios:

    The great majority of file-copy operations can be safely carried
    out with the default (/SHR) setting.  Since XXCOPY does not alter
    the contents of the source file, using the read-share (/SHR)
    setting allows it to share a file that has been opened by another
    program that declared its willingness to share the file on a
    read-only basis.

    When a program modifies the contents of a file, it typically opens
    the file for read-write purposes with no share allowed.  In this
    case, XXCOPY will have to wait for the file to become accessible
    (XXCOPY's /CR switch determines the length of the retry period).
    But, there are rare cases where a program opens a file for
    read/write purposes, yet allows other programs such as XXCOPY
    to concurrently access the file by allowing a read-write share.
    Then, XXCOPY with the /SHRW switch can access the file and make
    its copy.  In such a case, there is an implicit "trust" by XXCOPY
    to the other program that first opened the file to behave
    reasonably in order to maintain the integrity of the shared file.
    If the other program modifies part of the file in such a way that
    the snapshot of the given file (read by XXCOPY) loses the
    coherency, then, the copy of the file may become "corrupt" even
    though XXCOPY completes the copy operation "without error".

    We believe there are rare but useful occasions where copying
    a file regardless of the integrity of the file contents is
    beneficial.  XXCOPY allows for the use of /SHRW (or even /SHW)
    when the particular situation calls for it.

    Then, there are cases where the user does not want to copy a
    file which is being opened by another program even though the
    conservative sharing mode (/SHR) makes a perfectly safe copy.
    In such a case, /SH0 disallows XXCOPY to access any file that
    is being opened by another program.

© Copyright 2016 Pixelab All rights reserved.

[ XXCOPY Home ] [ Table of Contents ] [ << ] [ >> ]

Join the XXCOPY group