comp.lang.ada
 help / color / mirror / Atom feed
* Files opened for exclusive read
@ 2004-03-05 13:13 Daniel Allex
  2004-03-05 14:44 ` Preben Randhol
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Daniel Allex @ 2004-03-05 13:13 UTC (permalink / raw)


When Ada opens a file, the only option is for exclusive use.  This
causes a problem when multiple executables may be reading at the same
time.  Any suggestions?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 13:13 Files opened for exclusive read Daniel Allex
@ 2004-03-05 14:44 ` Preben Randhol
  2004-03-05 16:54 ` Robert I. Eachus
  2004-03-08  3:47 ` Dan Allex
  2 siblings, 0 replies; 10+ messages in thread
From: Preben Randhol @ 2004-03-05 14:44 UTC (permalink / raw)


On 2004-03-05, Daniel Allex <dallex@erols.com> wrote:
> When Ada opens a file, the only option is for exclusive use.  This
> causes a problem when multiple executables may be reading at the same
> time.  Any suggestions?

Doesn't happen in Linux. This must be Windows?

-- 
Rox-Filer; *the* file manager => http://rox.sf.net/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 13:13 Files opened for exclusive read Daniel Allex
  2004-03-05 14:44 ` Preben Randhol
@ 2004-03-05 16:54 ` Robert I. Eachus
  2004-03-05 18:14   ` Preben Randhol
  2004-03-06  1:05   ` Jeffrey Carter
  2004-03-08  3:47 ` Dan Allex
  2 siblings, 2 replies; 10+ messages in thread
From: Robert I. Eachus @ 2004-03-05 16:54 UTC (permalink / raw)


Daniel Allex wrote:
> When Ada opens a file, the only option is for exclusive use.  This
> causes a problem when multiple executables may be reading at the same
> time.  Any suggestions?

Look into mode strings for your compiler.  When you open a file in 
Text_IO there is a mode parameter.  The meaning of the mode parameter is 
implementation defined.  Of course, the possible settings using the mode 
string will depend on the operating system as well, and Windows does not 
'simply' support file sharing.  In GNAT 3.15p a mode string of 
"shared=yes" will allow you to share a file within an Ada program (have 
it open under two different names with different positions).  But if you 
want to share a file with say an external C program, you probably have 
to use Interfaces.C_Strings.  The problem of course is the buffering 
that otherwise goes on.

Read the gnat_rm for much more detail.

-- 
                                           Robert I. Eachus

"The only thing necessary for the triumph of evil is for good men to do 
nothing." --Edmund Burke




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 16:54 ` Robert I. Eachus
@ 2004-03-05 18:14   ` Preben Randhol
  2004-03-05 19:04     ` Mark H Johnson
  2004-03-06  1:05   ` Jeffrey Carter
  1 sibling, 1 reply; 10+ messages in thread
From: Preben Randhol @ 2004-03-05 18:14 UTC (permalink / raw)


On 2004-03-05, Robert I. Eachus <rieachus@comcast.net> wrote:
> Look into mode strings for your compiler.  When you open a file in 
> Text_IO there is a mode parameter.  The meaning of the mode parameter is 
> implementation defined.  Of course, the possible settings using the mode 
> string will depend on the operating system as well, and Windows does not 
> 'simply' support file sharing.  In GNAT 3.15p a mode string of 
> "shared=yes" will allow you to share a file within an Ada program (have 
> it open under two different names with different positions).  But if you 
> want to share a file with say an external C program, you probably have 
> to use Interfaces.C_Strings.  The problem of course is the buffering 
> that otherwise goes on.

Will shared=yes be silently ignored on a linux/unix OS where this is not
an issue?

-- 
Rox-Filer; *the* file manager => http://rox.sf.net/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 18:14   ` Preben Randhol
@ 2004-03-05 19:04     ` Mark H Johnson
  2004-03-05 19:32       ` Mark H Johnson
  0 siblings, 1 reply; 10+ messages in thread
From: Mark H Johnson @ 2004-03-05 19:04 UTC (permalink / raw)


Preben Randhol wrote:

> 
> Will shared=yes be silently ignored on a linux/unix OS where this is not
> an issue?
> 
It has been a couple years since I asked that question of ACT, but I 
believe the answer is NO. When shared=yes, the GNAT run time will share 
the file pointer (buffers, etc.). This was NOT what we wanted - we 
happened to have more than one task reading some initialization data 
from a file and were expecting each task to read the whole file (not 
just pieces).
   --Mark





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 19:04     ` Mark H Johnson
@ 2004-03-05 19:32       ` Mark H Johnson
  2004-03-05 19:52         ` Preben Randhol
  0 siblings, 1 reply; 10+ messages in thread
From: Mark H Johnson @ 2004-03-05 19:32 UTC (permalink / raw)


Mark H Johnson wrote:

> Preben Randhol wrote:
> 
>>
>> Will shared=yes be silently ignored on a linux/unix OS where this is not
>> an issue?
>>
> It has been a couple years since I asked that question of ACT, but I 
> believe the answer is NO. When shared=yes, the GNAT run time will share 
> the file pointer (buffers, etc.). This was NOT what we wanted - we 
> happened to have more than one task reading some initialization data 
> from a file and were expecting each task to read the whole file (not 
> just pieces).
>   --Mark
> 

In retrospect, my explanation is perhaps a little too brief. The 
following is a summary of a recent (5.02a) copy of the GNAT User's Guide 
(section 8.8, Shared Files)

In the absence of a shared=xxx, attempting to open two or more files w/ 
the same full name is an error (raises USE_ERROR).

If shared=no, the file can be opened with separate stream identifiers w/ 
the exact effect dependent on how the C stream routines do this.

If shared=yes and two or more files are opened with the same full name, 
the same stream is shared between the files w/ the semantics in section 
A.14 of the Ada Reference Manual.

So, to recap - shared=yes is not ignored, the semantics in the ARM are 
followed. If you want to open the same file more than once w/o error and 
without sharing, use shared=no. [at least this is how it works on x86 
Linux, I can't comment on other machine/OS combinations]
   --Mark




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 19:32       ` Mark H Johnson
@ 2004-03-05 19:52         ` Preben Randhol
  0 siblings, 0 replies; 10+ messages in thread
From: Preben Randhol @ 2004-03-05 19:52 UTC (permalink / raw)


On 2004-03-05, Mark H Johnson <Mark_H_Johnson@raytheon.com> wrote:
> So, to recap - shared=yes is not ignored, the semantics in the ARM are 
> followed. If you want to open the same file more than once w/o error and 
> without sharing, use shared=no. [at least this is how it works on x86 
> Linux, I can't comment on other machine/OS combinations]

I see so one have to make a OS dependant version of the package that
open files then...

-- 
Rox-Filer; *the* file manager => http://rox.sf.net/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 16:54 ` Robert I. Eachus
  2004-03-05 18:14   ` Preben Randhol
@ 2004-03-06  1:05   ` Jeffrey Carter
  1 sibling, 0 replies; 10+ messages in thread
From: Jeffrey Carter @ 2004-03-06  1:05 UTC (permalink / raw)


Robert I. Eachus wrote:

> Look into mode strings for your compiler.

Because this wording is a little confusing, let me clarify that Eachus 
is referring to the parameter named Form, not the parameter named Mode.

-- 
Jeff Carter
"My mind is aglow with whirling, transient nodes of
thought, careening through a cosmic vapor of invention."
Blazing Saddles
85




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-05 13:13 Files opened for exclusive read Daniel Allex
  2004-03-05 14:44 ` Preben Randhol
  2004-03-05 16:54 ` Robert I. Eachus
@ 2004-03-08  3:47 ` Dan Allex
  2004-03-16  5:28   ` Randy Brukardt
  2 siblings, 1 reply; 10+ messages in thread
From: Dan Allex @ 2004-03-08  3:47 UTC (permalink / raw)


Apparently, this is a short comming of Object Ada running on NT. 
Appreciate all the responses.  I'm trying to convince the powers that be 
to migrate to GNAT.

Daniel Allex wrote:
> When Ada opens a file, the only option is for exclusive use.  This
> causes a problem when multiple executables may be reading at the same
> time.  Any suggestions?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Files opened for exclusive read
  2004-03-08  3:47 ` Dan Allex
@ 2004-03-16  5:28   ` Randy Brukardt
  0 siblings, 0 replies; 10+ messages in thread
From: Randy Brukardt @ 2004-03-16  5:28 UTC (permalink / raw)


"Dan Allex" <dallex@erols.com> wrote in message
news:UIednfmQiM5acdbd4p2dnA@adelphia.com...
> Apparently, this is a short comming of Object Ada running on NT.
> Appreciate all the responses.  I'm trying to convince the powers that be
> to migrate to GNAT.
>
> Daniel Allex wrote:
> > When Ada opens a file, the only option is for exclusive use.  This
> > causes a problem when multiple executables may be reading at the same
> > time.  Any suggestions?

(I know this is late; I'm just back from a week off...)

When the file is opened in Windows, it is necessary to pass the appropriate
sharing bits. By default, files are opened for exclusive access in Windows.
I think most Ada run-time systems just do the default by default. But good
Windows compilers support some sort of Form parameter to set the sharing
mode. Certainly Janus/Ada does that, and I'm pretty sure we got the idea
from the Aonix Ada 83 compilers. So I'd be quite surprised if ObjectAda
doesn't have a way to do it.

Note that this has nothing to do with Ada, so the technique for doing it is
likely to be completely different on each compiler. I'd suggest contacting
Aonix's support people with your question (presuming you can't find any
discussion of it in their documentation). (I'm not convinced that the GNAT
support really will solve your problem, although there probably is some way
to get the handle opened directly by Windows and then used as an Ada file.)

                        Randy.






^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-03-16  5:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-05 13:13 Files opened for exclusive read Daniel Allex
2004-03-05 14:44 ` Preben Randhol
2004-03-05 16:54 ` Robert I. Eachus
2004-03-05 18:14   ` Preben Randhol
2004-03-05 19:04     ` Mark H Johnson
2004-03-05 19:32       ` Mark H Johnson
2004-03-05 19:52         ` Preben Randhol
2004-03-06  1:05   ` Jeffrey Carter
2004-03-08  3:47 ` Dan Allex
2004-03-16  5:28   ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox