comp.lang.ada
 help / color / mirror / Atom feed
* Protected hash map (efficient programming with a protected type)
@ 2017-11-16 20:42 Victor Porton
  2017-11-16 21:00 ` Victor Porton
  2017-11-16 23:50 ` Randy Brukardt
  0 siblings, 2 replies; 4+ messages in thread
From: Victor Porton @ 2017-11-16 20:42 UTC (permalink / raw)


Process_Descriptor record consists of a process ID (an integer), two file 
descriptors (for stdin and stdout). Process descriptors may also contain two 
strings: program input string (formed before the program started) and 
program output string (which is appended every time we get some output from 
the program). It may contain more data.

Process descriptors are organized into a hash map from a Unix process ID 
into a project descriptor.

Sometimes we receive Unix signal SIGCHLD what is configured to call a 
protected procedure (of a protected object). This protected procedure should 
remove the process descriptor from the map.

Now I don't understand how to organize access to the map.

First, copying process descriptors should be avoided because the stdout 
string may be long and occupy a significant amount of memory. Thus I want to 
use accesses to process descriptors rather than descriptor itself.

But in this case, an access value may become dangling if SIGCHILD handler 
procedure is run in the middle and its use become erroneous.

What to do?

Note that my program is single-threaded.

I write some important open source programs for the benefit for the World. 
Please help me.

-- 
Victor Porton - http://portonvictor.org


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

* Re: Protected hash map (efficient programming with a protected type)
  2017-11-16 20:42 Protected hash map (efficient programming with a protected type) Victor Porton
@ 2017-11-16 21:00 ` Victor Porton
  2017-11-16 23:50 ` Randy Brukardt
  1 sibling, 0 replies; 4+ messages in thread
From: Victor Porton @ 2017-11-16 21:00 UTC (permalink / raw)


Victor Porton wrote:
> Process_Descriptor record consists of a process ID (an integer), two file
> descriptors (for stdin and stdout). Process descriptors may also contain
> two strings: program input string (formed before the program started) and
> program output string (which is appended every time we get some output
> from the program). It may contain more data.
> 
> Process descriptors are organized into a hash map from a Unix process ID
> into a project descriptor.
> 
> Sometimes we receive Unix signal SIGCHLD what is configured to call a
> protected procedure (of a protected object). This protected procedure
> should remove the process descriptor from the map.
> 
> Now I don't understand how to organize access to the map.
> 
> First, copying process descriptors should be avoided because the stdout
> string may be long and occupy a significant amount of memory. Thus I want
> to use accesses to process descriptors rather than descriptor itself.
> 
> But in this case, an access value may become dangling if SIGCHILD handler
> procedure is run in the middle and its use become erroneous.
> 
> What to do?
> 
> Note that my program is single-threaded.
> 
> I write some important open source programs for the benefit for the World.
> Please help me.

It seems I know what to do:

In the signal handler (be it SIGCHLD, SIGTERM, or SIGNINT) I will just send 
one byte (indicating the kind of the signal) from the task through a pair of 
pipes to the task itself. Then I will use poll() Unix call to detect when 
this "one byte" is sent and run whatever I need without the need to make it 
compatible with signal handlers and without the need to use protected 
procedures (except of the protected procedure which handles the signal).

-- 
Victor Porton - http://portonvictor.org

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

* Re: Protected hash map (efficient programming with a protected type)
  2017-11-16 20:42 Protected hash map (efficient programming with a protected type) Victor Porton
  2017-11-16 21:00 ` Victor Porton
@ 2017-11-16 23:50 ` Randy Brukardt
  2017-11-17  0:28   ` Victor Porton
  1 sibling, 1 reply; 4+ messages in thread
From: Randy Brukardt @ 2017-11-16 23:50 UTC (permalink / raw)


"Victor Porton" <porton@narod.ru> wrote in message 
news:oukt7t$1ifn$1@gioia.aioe.org...
> Process_Descriptor record consists of a process ID (an integer), two file
> descriptors (for stdin and stdout). Process descriptors may also contain 
> two
> strings: program input string (formed before the program started) and
> program output string (which is appended every time we get some output 
> from
> the program). It may contain more data.

I'm not sure I understand. In every system that I've ever used, there can 
only be one set of process descriptor information for each process ID. That 
means the other data is secondary to the process ID, and the ID alone is 
sufficient to determine the other information.

Specifically, a running process (with a particular ID) has StdIn and StdOut 
file descriptors. But there never are two copies of the same process (with 
the same ID) with different StdIn and StdOut information; those necessarily 
have to be different processes with different IDs. (Perhaps something could 
change the StdIn or StdOut file descriptors, but you wouldn't keep the old 
ones in such a case.)

Thus, I'd index the map using the process ID (which is typically a small 
integer), and use that to retrieve the other information as needed. If the 
process ID is destroyed, one needs a mechanism to remove it (and thus the 
other information) from the map. But that can be implemented with just a 
normal Delete (assuming the Map is implemented with one of the Ada 
Containers).

                                              Randy.



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

* Re: Protected hash map (efficient programming with a protected type)
  2017-11-16 23:50 ` Randy Brukardt
@ 2017-11-17  0:28   ` Victor Porton
  0 siblings, 0 replies; 4+ messages in thread
From: Victor Porton @ 2017-11-17  0:28 UTC (permalink / raw)


Randy Brukardt wrote:

> "Victor Porton" <porton@narod.ru> wrote in message
> news:oukt7t$1ifn$1@gioia.aioe.org...
>> Process_Descriptor record consists of a process ID (an integer), two file
>> descriptors (for stdin and stdout). Process descriptors may also contain
>> two
>> strings: program input string (formed before the program started) and
>> program output string (which is appended every time we get some output
>> from
>> the program). It may contain more data.
> 
> I'm not sure I understand. In every system that I've ever used, there can
> only be one set of process descriptor information for each process ID.
> That means the other data is secondary to the process ID, and the ID alone
> is sufficient to determine the other information.

I store some additional information (such as the retrieved part of its 
stdout output) in my Process_Descriptor record.

To retrieve the additional information about a process with given ID, I need 
to store the additional information in a map from process ID to 
Process_Descriptor.

So it can be restored from a process ID, but I need to look into a hash map 
to do it.

> Specifically, a running process (with a particular ID) has StdIn and
> StdOut file descriptors. But there never are two copies of the same
> process (with the same ID) with different StdIn and StdOut information;

Certainly, never.

> those necessarily have to be different processes with different IDs.
> (Perhaps something could change the StdIn or StdOut file descriptors, but
> you wouldn't keep the old ones in such a case.)
> 
> Thus, I'd index the map using the process ID (which is typically a small
> integer), and use that to retrieve the other information as needed. If the

Certainly so. But it amounts to a hash lookup.

> process ID is destroyed, one needs a mechanism to remove it (and thus the
> other information) from the map. But that can be implemented with just a
> normal Delete (assuming the Map is implemented with one of the Ada
> Containers).

The problem was to do it right in a protected interrupt handler, without 
breaking atomicity...

... but (see my other post) I decided to do all processing linearized (not 
in an interrupt), using poll() to watch for all kinds of events, so that I 
no more need to do it in a protected procedure...

in more details:

In the signal handler (be it SIGCHLD, SIGTERM, or SIGNINT) I will just send 
one byte (indicating the kind of the signal) from the task through a pair 
of pipes to the task itself. Then I will use poll() Unix call to detect 
when this "one byte" is sent and run whatever I need without the need to 
make it compatible with signal handlers and without the need to use 
protected procedures (except of the protected procedure which handles the 
signal).

>                                               Randy.

-- 
Victor Porton - http://portonvictor.org


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

end of thread, other threads:[~2017-11-17  0:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-16 20:42 Protected hash map (efficient programming with a protected type) Victor Porton
2017-11-16 21:00 ` Victor Porton
2017-11-16 23:50 ` Randy Brukardt
2017-11-17  0:28   ` Victor Porton

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