comp.lang.ada
 help / color / mirror / Atom feed
* Two questions
@ 1996-11-07  0:00 Ding-yuan Sheu
  1996-11-07  0:00 ` Robert Dewar
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: Ding-yuan Sheu @ 1996-11-07  0:00 UTC (permalink / raw)
  Cc: mkanko, kshomper, lawlis, dsheu


Hello All,
	I am converting a C++ application into Ada95 and ran into
two problems. If you know the answers, please let me know. I appreciate
your any help.

(1) Is there an easy way to achieve the same result of the C++ sprintf
function in Ada? I know this may be a FAQ. Your patience and kindness 
are appreciated.

I work on my project on SGI machines. SGI provides some C++ library 
binding for Ada programers. However, for the sprintf function, I think
the binding interface is unclear. So, I don't know how to use it. If you
happen to know how to use it. Please let me know.

(2) In a C++ function, prorammers can declare a static local variable
to preserve its value between function calls. Can I do that in Ada?
For example, in C++, I can write a function as  follows:
void strcount(char *str)
{
   static int total =0;
   int count = 0;

   while (*str++) count++;
   total = total + count;
}

Whenever strcount is called, the value of total will not be reinitialize
to 0. It will preserve the value after it was called last time.
I know I can use a package to wrap strcount and declare a private
variable in the package to achieve the same result. However, is this the
only solution? Can I simply declare a static variable in the Ada
subprogram 
to achieve the same result? 
Any comments are welcomed. Thanks in advance.
======================================================================
Ding-yuan Sheu (Steven) | Student of Air Force Institute Technology
(513)233-2022           | for Master Degree of Computer System
dsheu@afit.af.mil       | Software Engineering Sequence




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Two questions
@ 2002-07-04 22:25 Mark
  2002-07-04 22:40 ` Jeffrey Creem
  0 siblings, 1 reply; 29+ messages in thread
From: Mark @ 2002-07-04 22:25 UTC (permalink / raw)


Gents I'd like to do a GUI application in ADA.  The application will
be run on Solaris.  Is there a 'free' toolset I could start off with
that offers ease of use.  Rapid seems to be the only one.   In any
event, help.


Could someone provide sample code on accomplishing a task.  I have an
application where I want the user to enter up to 250 values max. 
Values are in the range 1 .. 65535.
So now the user will first tell me how many values he wants:  lets
assume the user wants 10 values.
My next question would be for user to enter the 10 values within the
range specified above.  I'll then store user defined values into an
array which I'll pass on to a function that'll take user defined
values and parse into 'hibyte versus lobyte'.   The function part i
can handle however,the user selection part I'm a bit confused about.

I'd like to also have the option to to use a random number generator. 
 This helps such that if the user watns 200 values.  I'll generate 200
random numbers within specified range.

So now my 'menu' would look like this:
  -- 1. How many numbers.  
  -- 2. Random Numbers or User defined
  -- 3. Store numbers into array.  
  -- 4. Pass numbers into function.

I could do all this in Visual C etc, but as i'm learning Ada I've
grown to like it and am now trying to perfect my Ada.

Thanks in advance



^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Two questions
@ 2001-03-12 10:59 Christoph Grein
  2001-03-12 17:43 ` Stephen Leake
  0 siblings, 1 reply; 29+ messages in thread
From: Christoph Grein @ 2001-03-12 10:59 UTC (permalink / raw)
  To: comp.lang.ada

package something_cool is

    type cool is tagged private;
    
    function Create (P: in Some_Parameters) return Cool;    -- gets abstract on
                                                            -- derivation
    procedure Create (c : out cool; P: in Some_Parameters); -- does not get
                                                            -- abstract on
                                                            -- derivation
    package constructor is  -- nothing inside will be inherited

        procedure create (c : out cool; ... ... );

    end constructor;

private
        ...

end something_cool;

Thus make your choice. As Randy said, you can end with a bunch of useless 
constructors with the inherited ones.





^ permalink raw reply	[flat|nested] 29+ messages in thread
* Two questions
@ 2001-03-09 18:27 chris.danx
  2001-03-09 20:22 ` Mark Lundquist
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: chris.danx @ 2001-03-09 18:27 UTC (permalink / raw)


Hi,
    two questions, one on exceptions and one on objects or tagged types.

Where exactly can i put an exception handler?  I read in JE's book that you
can put them in loop ... end loop statements after an exit statement.  I
normally put handlers at the end of a routine, and i was supprised to find
you could put them elsewhere.  What i want to know is where else can i put
them?  In a while loop?  In a for loop?  In an if?  ... etc.

The second is to do with tagged types.  Sometimes it is suggested that you
put your 'create routine' -- the initialisation routine -- in a nested
package.  Others suggest putting it in the same package as the tagged type.

Example

package something_cool is

    type cool is tagged private;

    package constructor is

        procedure create (c : out cool; ... ... );

    end constructor;

    private
        ...
        ...

end something_cool;

or

package something_cool is

    type cool is tagged private;

    procedure create (c : out cool; ... ... );

    private
        ...
        ...

end something_cool;


What's the difference?  Where should i use method 1 and where should i use
method 2?


Thanks,
Chris Campbell





^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Two questions
@ 1996-11-09  0:00 tmoran
  1996-11-11  0:00 ` Adam Beneschan
  1996-11-13  0:00 ` Richard A. O'Keefe
  0 siblings, 2 replies; 29+ messages in thread
From: tmoran @ 1996-11-09  0:00 UTC (permalink / raw)



> (1) Is there an easy way to achieve the same result of the C++
> sprintf function in Ada?
The Ada idiom for
  char str[20];
  sprintf(&str, "variable %s = %d", name, x);
would be something like:
declare
  str:constant string := "variable " & name & " =" & integer'image(x);
begin
 ...
Or, since you can return whole strings from functions, you can have
 ... return "variable " & name & " =" & integer'image(x);




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Two questions
@ 1996-05-01  0:00 Bernard Banner
  0 siblings, 0 replies; 29+ messages in thread
From: Bernard Banner @ 1996-05-01  0:00 UTC (permalink / raw)



GNAT 3.03 is available now for HP (at cs.nyu.edu/pub/gnat) and does have a
preliminary version of tasking support.

> At 10:43 AM 5/1/96, W. Wesley Groleau (Wes) wrote:
> >1. Anyone working on a HP-UX port of gnat?  He/She/They may be able to
> >use some code that I can provide.  I didn't write it, but I have
> >verified (with the help of the original anonymous author) that it
> >works.
>
> There has been an HP-PA port of GNAT 3.01 that I have been using for some
> time. It is on the NYU FTP. It doesn't have tasking, though. Or are you
> specifically looking for 3.03?
>
> __________________________________________________________________________
> Ed Seidewitz                              NASA Goddard Space Flight Center
> <ed.seidewitz@gsfc.nasa.gov>              Code 552.3
> (301)286-7631                             Greenbelt MD 20771
> __________________________________________________________________________
> For non-NASA business, please use: <seidewitz@acm.org>
>
>




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Two questions
@ 1996-05-01  0:00 Ed Seidewitz
  0 siblings, 0 replies; 29+ messages in thread
From: Ed Seidewitz @ 1996-05-01  0:00 UTC (permalink / raw)



At 10:43 AM 5/1/96, W. Wesley Groleau (Wes) wrote:
>1. Anyone working on a HP-UX port of gnat?  He/She/They may be able to
>use some code that I can provide.  I didn't write it, but I have
>verified (with the help of the original anonymous author) that it
>works.

There has been an HP-PA port of GNAT 3.01 that I have been using for some
time. It is on the NYU FTP. It doesn't have tasking, though. Or are you
specifically looking for 3.03?

__________________________________________________________________________
Ed Seidewitz                              NASA Goddard Space Flight Center
<ed.seidewitz@gsfc.nasa.gov>              Code 552.3
(301)286-7631                             Greenbelt MD 20771
__________________________________________________________________________
For non-NASA business, please use: <seidewitz@acm.org>




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Two questions
@ 1996-05-01  0:00 W. Wesley Groleau (Wes)
  0 siblings, 0 replies; 29+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-05-01  0:00 UTC (permalink / raw)



1. Anyone working on a HP-UX port of gnat?  He/She/They may be able to
use some code that I can provide.  I didn't write it, but I have
verified (with the help of the original anonymous author) that it
works.

2. Asked this on gnatlist a while ago, but I didn't see an answer,
so I'll try a wider audience...

I am trying to study some of the rts with ada2html, which chokes at
the gnatf stage.  I do not need a "working" gnat, so any tricks
that get the file(s) past gnatf are OK.  Anyone have such a workaround
for the following?

398 -> gnatf -gnatg -gnatv -x6 -v a-astaco.ads


GNAT Front End/XREF Tool Version 2.05 (C) Copyright NYU, 1992,1993,1994

Checking: a-astaco.ads  last modified at 95-11-29 04:24.00 GMT.
fatal error: runtime library configuration error
cannot locate "Root_Controlled" in file "s-finimp.ads" (entity not in package)
 41 lines: No errors
compilation of a-astaco.ads abandoned

--------------
Root_Controlled is defined, but in s-finroo.ads - and neither s-finroo nor
s-finimp are directly with'ed by s-astaco

Is there a CLI option to make gnatf show the dependency tree of files it
parsing?

--
---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Magnavox - Mail Stop 10-40                               Home: 219-471-7206
Fort Wayne,  IN   46808              elm (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Two questions
@ 1989-04-11 13:32 Piercarlo Grandi
  1989-04-14 17:14 ` callen
  0 siblings, 1 reply; 29+ messages in thread
From: Piercarlo Grandi @ 1989-04-11 13:32 UTC (permalink / raw)


In article <124000035@inmet> callen@inmet writes:
    
    >There is another problem with Ada tasking, and it is well known to those
    >who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
    >address space is suspended waiting for resolution of the page fault;
    
    This behavior is dependent upon the Ada runtime system implementation. MVS
    supports its own flavor of tasking, in which several tasks (threads of control)
    run in the same address space. On a machine with more than one physical
    processor (which is very common these days), several tasks in the same 
    address space can run simultaneously on different processors. If one of the
    tasks incurs a page fault, the other tasks do NOT wait.

Unfortunately I do not have a multiprocessor MVS system :->.

However on this subject, I cited OS/MVS and IMS preceisely because the
problem has been solved within them; MVS has one of the few multithreading
facilities (if that is the right word :->) around, and among others PL/1 uses
it etc...
    
    So what you want to look for is an implementation that allows you to 
    map Ada tasks to "true" MVS tasks. There are at least 2.

Let me add though that if I were selling an Ada compiler for MVS, I would
not boast that it does have real multithreading because it maps Ada tasks
onto MVS tasks; I would keep it a closely guarded secret. Why?

Easy is the answer: it is fairly obvious that Ada tasking was designed to
support a very fine grain of tasking, such as associating tasks with a
buffer pool, etc... Too bad that MVS tasks have truly stupendous overheads.

IBM are the first to admit this; in an old (early seventies) issue of their
Systems Journal (devoted to explaining the new VS2, as it was then called)
they discuss how it was decided that the MVS kernel internally would not use
MVS tasks, but rather lightweight tasks, precisely because TCBs are too
expensive to use in a multithread program like MVS itself.  Also, there must
be some good reason for which the major IBM databases or communication
subsystems or transaction processing systems don't use TCBs...

Too bad that those two vendors that you cite as allowing you to map Ada
tasks to "true" MVS tasks did not take the trouble of duplicating the IMS or
CICS internal schedulers, that do get page fault signals from the MVS
kernel. By the way, there is a facility to get page fault signals also in VM,
precisely because it is used to run multithreaded operating systems, and
these when run under it do use them.

On the other hand I must admit that using MVS tasks for Ada tasks, while
being quite inappropriate to the Ada style of tasking, does have the
advantage of being able to run them on multiple processors, which a simple
page fault handling in address space scheduler cannot do.

Unles sof course the in address space scheduler runs as multiple MVS tasks
(it, not the Ada tasks it manages). I don't really remember well, but some
recent version of IMS may do that.

Summing up, I thoroughy agree with other posters that Ada really requires
a lightweight thread implementation, and most current operating systems
do not qualify, either because they do not have threads or because they
are not lightweight. And, let me add, wasn't Ada supposed to run on
embedded systems where all tasks are lightweight, and there is no notion
of address spaces, not to speak of paging? :-] :-]
-- 
Piercarlo "Peter" Grandi            |  ARPA: pcg%cs.aber.ac.uk@nss.cs.ucl.ac.uk
Dept of CS, UCW Aberystwyth         |  UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK  |  INET: pcg@cs.aber.ac.uk

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Two questions
@ 1989-03-30 11:53 Piercarlo Grandi
  1989-04-13  0:46 ` Paul Stachour
  0 siblings, 1 reply; 29+ messages in thread
From: Piercarlo Grandi @ 1989-03-30 11:53 UTC (permalink / raw)


In article <9274@claris.com> peirce@claris.com (Michael Peirce) writes:
    >2. When a task has completed its execution, termination is delayed until all
    >   dependent tasks have terminated (9.4.6).  As a result, our program
    >   fills up all memory with completed tasks unable to terminate.  Why is
    >   this?  Can something be done about it (without altering task dependency)?
    >
    >
    >We have the impression that Ada was designed to deal with a small
    >number of large tasks, whereas we are trying to create a large number
    >of small tasks.  Is this true?  Does it matter?
    >
    
    The way we dealt with this problem was to reuse our tasks.  We had
    a situation where we wanted to dispatch a handler task for each incoming
    request from the network. In Vax Ada, the tasks weren't removed from
    memory until after the program exited the scope of the task declaration.

This is all nice and true, but of course hardly satisfactory. It essentially
defeats the idea of using dynamically created tasks. It is a style of
programming akin to that used in Concurrent Euclid or other languages
with only a static number of tasks configurable. The scheme though is
efficient and not too difficult to implement, and slightly more flexible.

There is another problem with Ada tasking, and it is well known to those
who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
address space is suspended waiting for resolution of the page fault;
another Ada task is not redispatched, even if it could, because on virtually
all the Ada implementations I know of (notably the VMS one) the OS does not
know about Ada tasks at all. In other words, Ada tasking is not very good on
virtual memory systems if one wants to keep track of multiple external
events. The classic example is having a terminal monitor, with each terminal
served by its own task.

There are only two solutions, one fairly horrible, having a signal delivered
by the OS on a page fault to the in-address space scheduler, the second
and proper one is to have threads in the OS and associated Ada tasks with
the threads. Unfortunately the second one can be fairly expensive, many
systems have high overhead threads (e.g. OS/MVS).
-- 
Piercarlo "Peter" Grandi            |  ARPA: pcg%cs.aber.ac.uk@nss.cs.ucl.ac.uk
Dept of CS, UCW Aberystwyth         |  UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK  |  INET: pcg@cs.aber.ac.uk

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Two questions
@ 1989-03-29  9:16 HansM
  1989-03-29 18:35 ` Michael Peirce
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: HansM @ 1989-03-29  9:16 UTC (permalink / raw)


We are trying to understand Ada tasking and there are two things we fail to
understand:

1. When an exception is raised and not handled in a task body, the task
   is terminated and the exception is not further propagated, without
   notice (11.4.1.8).  Why is this?
   Is there a way to invoke the kind of traceback that occurs when an
   exception is propagated out of the main program?

2. When a task has completed its execution, termination is delayed until all
   dependent tasks have terminated (9.4.6).  As a result, our program
   fills up all memory with completed tasks unable to terminate.  Why is
   this?  Can something be done about it (without altering task dependency)?


We have the impression that Ada was designed to deal with a small
number of large tasks, whereas we are trying to create a large number
of small tasks.  Is this true?  Does it matter?

Can anybody enlighten us?

AdvTHANKSance

Hans Mulder		Sjouke Mauw
hm@uva.uucp		sjouke@uva.uucp
mcvax!uva!hm		mcvax!uva!sjouke

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

end of thread, other threads:[~2002-07-04 22:40 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-07  0:00 Two questions Ding-yuan Sheu
1996-11-07  0:00 ` Robert Dewar
1996-11-08  0:00 ` Robert I. Eachus
1996-11-08  0:00 ` Norman H. Cohen
1996-11-08  0:00 ` Jon S Anthony
  -- strict thread matches above, loose matches on Subject: below --
2002-07-04 22:25 Mark
2002-07-04 22:40 ` Jeffrey Creem
2001-03-12 10:59 Christoph Grein
2001-03-12 17:43 ` Stephen Leake
2001-03-09 18:27 chris.danx
2001-03-09 20:22 ` Mark Lundquist
2001-03-09 20:56 ` Randy Brukardt
2001-03-12 15:36 ` John English
2001-03-12 18:11   ` chris.danx
1996-11-09  0:00 tmoran
1996-11-11  0:00 ` Adam Beneschan
1996-11-13  0:00 ` Richard A. O'Keefe
1996-05-01  0:00 Bernard Banner
1996-05-01  0:00 Ed Seidewitz
1996-05-01  0:00 W. Wesley Groleau (Wes)
1989-04-11 13:32 Piercarlo Grandi
1989-04-14 17:14 ` callen
1989-03-30 11:53 Piercarlo Grandi
1989-04-13  0:46 ` Paul Stachour
1989-03-29  9:16 HansM
1989-03-29 18:35 ` Michael Peirce
1989-03-31 13:10 ` stt
1989-03-31 18:59 ` Scott Simpson
1989-04-03 14:44 ` callen

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