comp.lang.ada
 help / color / mirror / Atom feed
* returning a value from tasking??
@ 1996-11-30  0:00 Randy Kosarik
  1996-12-01  0:00 ` Robert Dewar
  1996-12-01  0:00 ` Tom Moran
  0 siblings, 2 replies; 3+ messages in thread
From: Randy Kosarik @ 1996-11-30  0:00 UTC (permalink / raw)



Hi,

  I am having a problem getting a task to work and am running out of
time this semester.
  I am running DEC Ada version 8.2 on a VAX. 

  What I am trying to do is get a character within 3 seconds, if no
character was
inputted, I want either a null character returned or a space returned. I
was told from
a previous message that I would have to TASK to do this.

  I have TASK2 calling TASK1. TASK1 will not return a value to TASK2
unless I remove the
second to last line( DO_EXIT(STATUS); ) from TASK1. When I do this
though, it will not exit when 3 seconds have expired.

  I have been scouring through the books trying to figure this one out
but, the tasking concept seems to be above my head, right now.. I keep
doing trial and error.

 Please, I have 10 days to figure this out... Any replies would be
GREATLY appreciated!
 -Randy  

--------------------------start of
TASK2.ADA----------------------------------------
with text_io, task1;
use text_io;
procedure task2 is
  z : character;
  x : INTEGER;
begin
 loop
   task1(z => z);
   put_line(z & " brought from task1");
 exit  when x > 5;
 x := x + 1;
 end loop;
end task2;
--------------------------end of
TASK2.ADA------------------------------------------


--------------------------start of
TASK1.ADA----------------------------------------
with TEXT_IO;
use TEXT_IO;
procedure task1 (z : in out CHARACTER) is

--      pragma TIME_SLICE (1.0);
        type CONDITION is new INTEGER;
        STATUS : CONDITION;
--        Z:CHARACTER;
        task T;
        task body T is
        begin
          Get(Z);
        end;

        procedure DO_EXIT(STATUS        :out CONDITION;
                          EXIT_STATUS   :in CONDITION := 1);
        pragma INTERFACE(VMS, DO_EXIT);
        pragma IMPORT_VALUED_PROCEDURE(DO_EXIT,
        pragma IMPORT_VALUED_PROCEDURE(DO_EXIT,
                                        "SYS$EXIT",
                                        MECHANISM => (VALUE, VALUE));
  begin
  delay 3.0;
-- nothing done;
  DO_EXIT(STATUS);
end task1;
--------------------------end of
TASK1.ADA-----------------------------------------




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

* Re: returning a value from tasking??
  1996-11-30  0:00 returning a value from tasking?? Randy Kosarik
@ 1996-12-01  0:00 ` Robert Dewar
  1996-12-01  0:00 ` Tom Moran
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1996-12-01  0:00 UTC (permalink / raw)



Randy asks how to read a character within three seconds, or quit the
attempt. 

Obviously we should not do his assignment for him, but the general
advice in this situation is to make sure you understand the tools
you are using. In this case, if you are using tasking, it is not
good enough to piece together a vague approximation based on things
people have showed you. You need to first assemble a reasonably 
complete knowledge of how tasking works from an appropriate text
book. In this case obviously the solution is a timed entry call
followed by a conditional abort, but you need to know what these
are to use them. if you were using Ada 95 rather than the
obsolescent Ada 83, you could use asyncrhonous transfer of
control to achieve the conditional abort.





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

* Re: returning a value from tasking??
  1996-11-30  0:00 returning a value from tasking?? Randy Kosarik
  1996-12-01  0:00 ` Robert Dewar
@ 1996-12-01  0:00 ` Tom Moran
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Moran @ 1996-12-01  0:00 UTC (permalink / raw)



>get a character or return if none is input within 3 seconds
  This is very much an OS dependent problem, and I don't know the OS 
calls available to you.  There ought to be one that accepts a timeout
and does just what you ask.  If not, you may have to resort to getting
one OS thread to do a read, while another does a timeout, and whichever
finishes first kills the other.  That is a substantially trickier, and
also implementation dependent, problem.




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

end of thread, other threads:[~1996-12-01  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-30  0:00 returning a value from tasking?? Randy Kosarik
1996-12-01  0:00 ` Robert Dewar
1996-12-01  0:00 ` Tom Moran

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