comp.lang.ada
 help / color / mirror / Atom feed
* dynamic multithreading
@ 2002-11-14 13:12 Artiom Ivanov
  2002-11-14 13:49 ` David Marceau
                   ` (4 more replies)
  0 siblings, 5 replies; 47+ messages in thread
From: Artiom Ivanov @ 2002-11-14 13:12 UTC (permalink / raw)


I have a question to all who had been working closely with multithreaded
programming.

As you know in many applications when using threads, we sometimes need to
create a "tasks" dynamically (I mean at run-time).

For example when you need to create a server for a client applications (when
there can be more then one client application) you need to create tasks when
it's needed at run-time and after finishing processing destruct them.

It will be very cool if you could explain me a way to proceed for dynamic
multithreading and post me some examples.

Thanks in advance






^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: dynamic multithreading
@ 2002-11-18  9:22 Grein, Christoph
  2002-11-18 12:25 ` Thierry Lelegard
  0 siblings, 1 reply; 47+ messages in thread
From: Grein, Christoph @ 2002-11-18  9:22 UTC (permalink / raw)


Of course this program _must_ consume all memory.

You explicitly allocate on the heap, but never deallocate. That's what 
Unchecked_Deallocation is for.

Or do you mean even with Free, it consumes all memory?

> No need to argue, just try the following program with and without
> the "Free". If you find one Ada95 compiler one one platform where
> it does not eat up all the memory, please let us know.
> 
> With GNAT on Solaris, VMS, Linux, HP-UX and Windows, I already know
> the answer...
> 
> -Thierry
> 
> with Ada.Text_IO;
> with Ada.Unchecked_Deallocation;
> with System;
> 
> procedure Crazy_Tasks is
> 
>     task type T is
>         pragma Priority (System.Priority'Last);
>         entry Foo;
>     end T;
> 
>     type Access_T is access T;
> 
>     task body T is
>     begin
>         select
>             accept Foo;
>         else
>             null;
>         end select;
>     end T;
> 
>     procedure Free is new Ada.Unchecked_Deallocation (T, Access_T);
> 
>     type Counter is mod 2**32;
> 
>     Count : Counter := 0;
>     TV    : Access_T;
> 
> begin
> 
>     loop
>         TV := new T; -- should terminate immediately
>         while not TV.all'Terminated loop
>             delay 0.0;
>         end loop;
>         -- Free (TV);
>         Count := Count + 1;
>         if Count mod 50_000 = 0 then
>             Ada.Text_IO.Put_Line (Counter'Image (Count) & " tasks");
>         end if;
>     end loop;
> 
> end Crazy_Tasks;



^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: dynamic multithreading
@ 2002-11-18 12:13 Grein, Christoph
  2002-11-18 13:38 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 47+ messages in thread
From: Grein, Christoph @ 2002-11-18 12:13 UTC (permalink / raw)


> >with Ada.Text_IO;
> >with Ada.Unchecked_Deallocation;
> >with System;
> >
> >procedure Crazy_Tasks is
> >
> >    task type T is
> >        pragma Priority (System.Priority'Last);
> >        entry Foo;
> >    end T;
> >
> >    type Access_T is access T;
> >
> >    task body T is
> >    begin
> >        select
> >            accept Foo;
> >        else
> >            null;
> >        end select;
> >    end T;
> >
> >    procedure Free is new Ada.Unchecked_Deallocation (T, Access_T);
> >
> >    type Counter is mod 2**32;
> >
> >    Count : Counter := 0;
> >    TV    : Access_T;
> >
> >begin
> >
> >    loop
> >        TV := new T; -- should terminate immediately
> >        while not TV.all'Terminated loop
> >            delay 0.0;
> >        end loop;
> >        -- Free (TV);
> >        Count := Count + 1;
> >        if Count mod 50_000 = 0 then
> >            Ada.Text_IO.Put_Line (Counter'Image (Count) & " tasks");
> >        end if;
> >    end loop;
> >
> >end Crazy_Tasks;
> 
> This does not leak in ObjectAda 7.2 under Windows. [Trumpets!]

I do not understand... Even with Free commented out doesn't it leak?



^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: dynamic multithreading
@ 2002-11-19  5:28 Grein, Christoph
  0 siblings, 0 replies; 47+ messages in thread
From: Grein, Christoph @ 2002-11-19  5:28 UTC (permalink / raw)


> Well, since the Ada Standard says that anything allocated with "new"
> will _not_ be "garbage collected", I do _not_ expect the "run-time
> system" to do "free" for me.

Where, please, does it say that? There is nothing in the standard that prevents a GC. Fact is however that no current compiler implements one because of 
induced problems in real-time systems by unpredictable timing.

Note that there is a pragma Controlled that prevents automatic GC. So far this 
pragma is void for current compilers.

So at least your statement is correct that you should clean up things yourself.



^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: dynamic multithreading
@ 2002-11-19  6:38 Grein, Christoph
  2002-11-19  9:13 ` Lutz Donnerhacke
  0 siblings, 1 reply; 47+ messages in thread
From: Grein, Christoph @ 2002-11-19  6:38 UTC (permalink / raw)


From: Lutz Donnerhacke <lutz@iks-jena.de>
> 
> * Pascal Obry wrote:
> > !!!!! How is this possible ? A "new" without a "Free" and you claim no 
memory
> > leak !!!!!
> 
> Simple. The access variable has a local scope and all objects associated
> with it are automatically freed when the type goes out of scope. You may
> limit the pool size of this access type ...

This is not true in general!

Every access type has an assciated storage pool. If this pool is not defined 
upon declaration, a default storage pool is used.

There is nothing in the standard that says that all allocated objects of an 
access type are freed when the access type goes out of scope. How could it, 
since this might be a global default storage pool.

There is however RM 13.11(18): If Storage_Size is defined for an access type, 
all storage is reclaimed if the (master of) the type goes out of scope.

So you have to limit the pool if you want such a kind of garbage collection.



^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: dynamic multithreading
@ 2002-11-19  6:46 Grein, Christoph
  0 siblings, 0 replies; 47+ messages in thread
From: Grein, Christoph @ 2002-11-19  6:46 UTC (permalink / raw)


From: Lutz Donnerhacke <lutz@iks-jena.de>
> > If the inner variable goes out of scope it should not free up the rest of
> > the objects.
> 
>   declare
>      type A_Access is access A;
>      a : A_Access := new A;        -- Instance 1.
>   begin
>      a := new A;                   -- Instance 2: Leaks memory (Instance 1)
>      declare
>        b : A_Access := a;
>      begin
>        b := new A;                 -- Instance 3.
>        a := b;                     -- Leaks memory (Instance 2)
>      end;
>   end;                             -- Frees all three instances.

Not true, see me other mail.

You need 'Storag_Size on A_Access for this statement to become true.



^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: dynamic multithreading
@ 2002-11-19  6:49 Grein, Christoph
  2002-11-20 18:20 ` Matthew Heaney
  2002-11-27 15:55 ` John English
  0 siblings, 2 replies; 47+ messages in thread
From: Grein, Christoph @ 2002-11-19  6:49 UTC (permalink / raw)


> http://www.adapower.com/alg/smartp.html

There is another implementation of referece counted pointers, Safe_Pointers, in my home 
page. This has been published in Ada Letters some years ago.

See http://home.T-Online.de/home/Christ-Usch.Grein/Ada/



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

end of thread, other threads:[~2002-11-27 15:55 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-14 13:12 dynamic multithreading Artiom Ivanov
2002-11-14 13:49 ` David Marceau
2002-11-14 14:14 ` Björn Lundin
2002-11-14 17:07   ` Thierry Lelegard
2002-11-14 18:59     ` tmoran
2002-11-14 22:04       ` Robert A Duff
2002-11-15  9:27       ` Jean-Pierre Rosen
2002-11-17 23:02     ` AG
2002-11-17  5:17       ` tmoran
2002-11-17 12:40       ` Simon Wright
2002-11-18  9:11       ` Thierry Lelegard
2002-11-18 12:12         ` Dmitry A. Kazakov
2002-11-18 16:18           ` Pascal Obry
2002-11-18 16:25             ` Lutz Donnerhacke
2002-11-18 16:21               ` Simon Wright
2002-11-19  9:03                 ` Lutz Donnerhacke
2002-11-19 21:41                   ` Simon Wright
2002-11-18 16:28               ` Preben Randhol
2002-11-18 16:30                 ` Lutz Donnerhacke
2002-11-18 16:35                   ` Preben Randhol
2002-11-18 16:44                     ` Lutz Donnerhacke
2002-11-18 18:58                       ` Preben Randhol
2002-11-19  9:09                         ` Lutz Donnerhacke
2002-11-18 19:00                       ` Preben Randhol
2002-11-19  9:11                         ` Lutz Donnerhacke
2002-11-19  9:32                           ` Preben Randhol
2002-11-19 11:18                             ` Lutz Donnerhacke
2002-11-19 12:42                       ` Georg Bauhaus
2002-11-19  9:00             ` Dmitry A. Kazakov
2002-11-18 14:30       ` Stephen Leake
2002-11-18 17:41         ` David C. Hoos
2002-11-14 14:29 ` David C. Hoos
2002-11-14 18:37 ` Jeffrey Carter
2002-11-14 22:03 ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
2002-11-18  9:22 Grein, Christoph
2002-11-18 12:25 ` Thierry Lelegard
2002-11-18 13:32   ` Dmitry A. Kazakov
2002-11-18 16:20     ` Pascal Obry
2002-11-18 12:13 Grein, Christoph
2002-11-18 13:38 ` Dmitry A. Kazakov
2002-11-19  5:28 Grein, Christoph
2002-11-19  6:38 Grein, Christoph
2002-11-19  9:13 ` Lutz Donnerhacke
2002-11-19  6:46 Grein, Christoph
2002-11-19  6:49 Grein, Christoph
2002-11-20 18:20 ` Matthew Heaney
2002-11-27 15:55 ` John English

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