From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5a78c81cd9a1f563 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!bcklog1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 28 Jun 2006 21:00:50 -0500 From: "Steve" Newsgroups: comp.lang.ada References: <1151434435.502270.265470@m73g2000cwd.googlegroups.com> <1151501695.077579.108560@i40g2000cwc.googlegroups.com> Subject: Re: How to spawn, fork, and exec within Ada (Do you have small example program) Date: Wed, 28 Jun 2006 19:02:12 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Original Message-ID: <8P-dndFaB7bPqT7ZnZ2dnUVZ_tydnZ2d@comcast.com> NNTP-Posting-Host: 24.20.111.245 X-Trace: sv3-6Uafe0yQe1xjwd0mlqIyNxwD5MoHi3vg22Zl8QxqnP+GuHNg2wm2p94TSztLVNg/tqe3eGI2UzjEYfA!ujXoloiaAiJ8SwXAlT4TaKxHRgpyviv8qGRJCWYDyu8dZbegAhez/312BmUqVxVqLHP3FPQGWnop!/qnB1R3Sh1Xzuw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:5261 Date: 2006-06-28T19:02:12-07:00 List-Id: "Chris L" wrote in message news:1151501695.077579.108560@i40g2000cwc.googlegroups.com... > > Steve wrote: >> The answer is the same: you may be able to do it, but you probably don't >> really want to. There are other ways of achieving the same functionality >> that are a lot easier. > > Could you elaborate with an example? Do you mean use one process > instead of a parent child pair of processies? It is hard for me to answer your question without first having the answer to mine, but I'll try to give a little information and see if it helps. If I understand correctly, in good ole Unix the only took for creating new threads of execution (prior to PThreads) is "fork" (I can't say for sure since I haven't worked a lot in Unix). "fork" is a system call that replicates the calling process and returns a status telling the caller whether it is the parent or child. It is a simple and powerful system, but is not portable. In Ada, tasking is built into the language. The Ada run time library abstracts the implementation of tasking on the target environment. For example with GNAT on Linux two tasking models are available, one that uses pthreads, and one that uses separate processes, the underlying mechanism (usually) doesn't matter to the Ada application. Here is an example of a simple tasking Ada program: with Ada.Integer_Text_IO; with Ada.Text_IO; procedure SimpleTaskDemo is task type MakeNoise is entry Start( which : Natural ); end MakeNoise; task body MakeNoise is me : Natural; begin accept Start( which : Natural ) do me := which; end; for i in 1 .. 10 loop Ada.Text_IO.Put( "Hello from: " ); Ada.Integer_Text_IO.Put( me, 3 ); Ada.Text_IO.Put( " Count: " ); Ada.Integer_Text_IO.Put( i, 3 ); Ada.Text_IO.New_Line; delay 1.0; end loop; end MakeNoise; task1 : MakeNoise; task2 : MakeNoise; begin task1.Start( 1 ); delay 0.5; task2.Start( 2 ); end SimpleTaskDemo; It creates two instances of the task "MakeNoise", task1 and task2. Each task displays "Hello from: Count: in a loop. Here is the output: Hello from: 1 Count: 1 Hello from: 2 Count: 1 Hello from: 1 Count: 2 Hello from: 2 Count: 2 Hello from: 1 Count: 3 Hello from: 2 Count: 3 Hello from: 1 Count: 4 Hello from: 2 Count: 4 Hello from: 1 Count: 5 Hello from: 2 Count: 5 Hello from: 1 Count: 6 Hello from: 2 Count: 6 Hello from: 1 Count: 7 Hello from: 2 Count: 7 Hello from: 1 Count: 8 Hello from: 2 Count: 8 Hello from: 1 Count: 9 Hello from: 2 Count: 9 Hello from: 1 Count: 10 Hello from: 2 Count: 10 I wrote this program using GNAT on Windows XP. It will also run without modification on Linux and numerous other target systems without modification. I successfully ported a non-windowed Ada application from Windows to Linux in a matter of a couple of hours. The only reason the sources had to be modified is the interface to networking on the two operating systems are different. If I were to do the same today I would use AdaSockets which abstracts the network interface so I shouldn't have to make any source modifications. But then, I'm still not sure if this is what you are asking, Steve (The Duck) > > Thank you, > Christopher Lusardi >