comp.lang.ada
 help / color / mirror / Atom feed
* In case you need to remember...
@ 2012-04-06 15:20 mockturtle
  2012-04-06 15:32 ` Pascal Obry
  2012-04-06 20:09 ` anon
  0 siblings, 2 replies; 6+ messages in thread
From: mockturtle @ 2012-04-06 15:20 UTC (permalink / raw)


...how nice is having tasks built-in in your preferred language, I just landed over this text (Threads — Threat or Menace?)

   http://www.faqs.org/docs/artu/ch07s03.html#id2923889

Just an excerpt: 

  "Threads are a fertile source of bugs because they can too easily know too much about each others' internal states. There is no automatic encapsulation, as there would be between processes with separate address spaces that must do explicit IPC to communicate. Thus, threaded programs suffer from not just ordinary contention problems, but from entire new categories of timing-dependent bugs that are excruciatingly difficult to even reproduce, let alone fix."

Hmm... Why do I have this warm and cozy feeling? :-) 

BTW, a curiosity: does the Linux version of GNAT use threads to implement tasks? 

Riccardo



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

* Re: In case you need to remember...
  2012-04-06 15:20 In case you need to remember mockturtle
@ 2012-04-06 15:32 ` Pascal Obry
  2012-04-06 20:09 ` anon
  1 sibling, 0 replies; 6+ messages in thread
From: Pascal Obry @ 2012-04-06 15:32 UTC (permalink / raw)


Le 06/04/2012 17:20, mockturtle a �crit :
> BTW, a curiosity: does the Linux version of GNAT use threads to implement tasks?

Yes, the Windows and MacOS version too.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|    http://www.obry.net  -  http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B




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

* Re: In case you need to remember...
  2012-04-06 15:20 In case you need to remember mockturtle
  2012-04-06 15:32 ` Pascal Obry
@ 2012-04-06 20:09 ` anon
  2012-04-06 20:14   ` Ludovic Brenta
  2012-04-11 18:15   ` Shark8
  1 sibling, 2 replies; 6+ messages in thread
From: anon @ 2012-04-06 20:09 UTC (permalink / raw)


The truth is Ada is Concurrent which means Ada uses one and only one 
thread for all tasks. 


And on a multiple core system the thread may swap between processors 
during thread scheduling but the Ada code is only one thread under 
the OS.  The RM 2012 does have some multiple processors packages but 
they are not enough routines to build a fully functioning true multiple 
thread for each task.

Now, GNAT using OS_Lib packages does have some OS links that can request 
new thread but these routines are not listed in the RM. Also, GNAT can 
use the Spawn or folk call but it is not recommended due to fact of 
blocking and signal/locks which are unpredictable. (see Note in 
System.OS_Lib.ads) Now in GNAT 2012 release in a month or two this 
may be different.


And example to demonstrated Ada based thread:


with Ada.Text_IO ;
with Ada.Integer_Text_IO ;
with Ada.Task_Identification ;

--  If Ada was multiple tasking using threads then the main procedure 
--  would end and the Task would run in the background similar to 
--  starting a server on any OS. This is, the main procedure would 
--  be use to active the task and then exit. But due to the fact that 
--  Ada is still concurrent the main procedure will finish executing 
--  but will be blocked in "Finalization".  Some resources may be 
--  release but not all. In other words the main procedure will be 
--  blocked and some resources held until the "Task" ends it run or 
--  the operator kills the executing thread which kills both the 
--  main procedure and the task and release all resources.
--
--  Also if you use a thread monitor you will see only one thread
--  was created and is running. And if Ada used multiple threads then 
--  in this program there would be one thread for the main procedure
--  "Test" and a second thread for the task "Task_1". But there is 
--  only one thread indicating that Ada is still concurrent.
--

procedure Test is

  use Ada ;
  use Text_IO ;
  use Integer_Text_IO ;


  task type CPU_TASK is
    entry Run_cpu ;  
  end CPU_TASK ;

  PC : Integer := 55 ;
  Run_Flag : Boolean := False ;

  --  Task is activated once the program begins
  --  If Ada was multiple thread then this task would activated once 
  --  the OS created a new thread entry in the job thread scheduler
  Task_1 : CPU_TASK ;  


  task body CPU_TASK is

    begin -- CPU_TASK 

      Put_Line ( "Processor is Uninitialized" ) ;
      loop
        select
          accept Run_cpu ;      

              -- Run until process is either reset, halted.  

              Put_Line ( "Task is in RUN Mode" ) ;
              Run_Flag := True ;
              loop
                Put_Line ( "Executed Instruction" & PC'img ) ;
                PC := PC + 1 ;
                Delay  0.0 ; -- tells Ada RTL to swap task to main
              end loop ;
              exit ;
        or
         terminate ;
        end select ;
      end loop ;
    end CPU_TASK ;

begin

  Put_Line ( "Reset Processor status" ) ;
  PC := 0 ;
  Delay 0.1 ;
  Put_Line ( "Set processor status to RUN Task" ) ;
  Task_1.Run_cpu ;

  Delay  0.5 ;
  Put_Line ( "Trying to Single Step Task" ) ;


--  Delay  0.1 ;
--  Put_Line ( "Stopping the Task" ) ;
--  Ada.Task_Identification.Abort_Task ( Task_1 ' Identity ) ;

    Put_Line ( "Finished Excution of program" ) ;
end test ;

In <1984433.261.1333725652284.JavaMail.geo-discussion-forums@vbbfr18>, mockturtle <framefritti@gmail.com> writes:
>....how nice is having tasks built-in in your preferred language, I just lan=
>ded over this text (Threads =97 Threat or Menace?)
>
>   http://www.faqs.org/docs/artu/ch07s03.html#id2923889
>
>Just an excerpt:=20
>
>  "Threads are a fertile source of bugs because they can too easily know to=
>o much about each others' internal states. There is no automatic encapsulat=
>ion, as there would be between processes with separate address spaces that =
>must do explicit IPC to communicate. Thus, threaded programs suffer from no=
>t just ordinary contention problems, but from entire new categories of timi=
>ng-dependent bugs that are excruciatingly difficult to even reproduce, let =
>alone fix."
>
>Hmm... Why do I have this warm and cozy feeling? :-)=20
>
>BTW, a curiosity: does the Linux version of GNAT use threads to implement t=
>asks?=20
>
>Riccardo




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

* Re: In case you need to remember...
  2012-04-06 20:09 ` anon
@ 2012-04-06 20:14   ` Ludovic Brenta
  2012-04-11 18:15   ` Shark8
  1 sibling, 0 replies; 6+ messages in thread
From: Ludovic Brenta @ 2012-04-06 20:14 UTC (permalink / raw)


anon@att.net writes:
> The truth is Ada is Concurrent which means Ada uses one and only one 
> thread for all tasks.

No, this is an implementation-defined characteristic.  On bare boards,
there is not even such a thing as a "thread".  Some operating systems
support processes but not threads.  Some others support both threads and
processes.  The compiler is free to choose whichever method is suitable
for the target.

For example, GNAT on most platforms uses (*multiple*) POSIX threads,
which are implemented and supported in Linux and *BSD kernels.  On
Windows, GNAT uses Windows threads.

-- 
Ludovic Brenta.



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

* Re: In case you need to remember...
  2012-04-06 20:09 ` anon
  2012-04-06 20:14   ` Ludovic Brenta
@ 2012-04-11 18:15   ` Shark8
  2012-04-11 21:22     ` tmoran
  1 sibling, 1 reply; 6+ messages in thread
From: Shark8 @ 2012-04-11 18:15 UTC (permalink / raw)
  Cc: anon

On Friday, April 6, 2012 3:09:24 PM UTC-5, an...@att.net wrote:
> The truth is Ada is Concurrent which means Ada uses one and only one 
> thread for all tasks. 

That's certainly not what the video over here implies:
http://www.adapower.com/index.php?Command=Class&ClassID=AdvocacyVideos&Title=Ada+Advocacy+Videos

(I'm not sure which segment, I'm currently on a no-sound computer so I can't check.)

Further, because TASK is a language-construct it may be handled in any number of ways, so long as that implementation conforms to the requirements of the ARM. Though even that could conceivably be handled differently via pragma usage; the ARM is quite permissive about implementation defined pragmas:
"In addition, an implementation may provide implementation-defined pragmas, which must then be described in Appendix F. An implementation is not allowed to define pragmas whose presence or absence influences the legality of the text outside such pragmas. Consequently, the legality of a program does not depend on the presence or absence of implementation-defined pragmas."
(see http://archive.adaic.com/standards/83lrm/html/lrm-02-08.html )

The above means that NVidia could have used Ada tasks as its CUDA/GPU-processor code via pragma; allowing the compiler to a) reject code which could not be run on the GPU, or b) pass the task on to the main CPU and issue a warning with the technical limitation barring it from being put onto the GPUs. {Further, such code would also be able to be compiled with any regular Ada compiler which only warned about the unrecognized pragmas.}




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

* Re: In case you need to remember...
  2012-04-11 18:15   ` Shark8
@ 2012-04-11 21:22     ` tmoran
  0 siblings, 0 replies; 6+ messages in thread
From: tmoran @ 2012-04-11 21:22 UTC (permalink / raw)


> > On Friday, April 6, 2012 3:09:24 PM UTC-5, an...@att.net wrote:
> > The truth is Ada is Concurrent which means Ada uses one and only one=20
> > thread for all tasks.=20
>
> That's certainly not what the video over here implies:
   Take anything said by anon@att.net with a tablespoonful, not a grain,
of salt.  His statement above, for instance, is wrong.



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

end of thread, other threads:[~2012-04-11 21:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-06 15:20 In case you need to remember mockturtle
2012-04-06 15:32 ` Pascal Obry
2012-04-06 20:09 ` anon
2012-04-06 20:14   ` Ludovic Brenta
2012-04-11 18:15   ` Shark8
2012-04-11 21:22     ` tmoran

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