comp.lang.ada
 help / color / mirror / Atom feed
* "multithread"
@ 2005-04-02 22:37 Jean-Baptiste CAMPESATO
  2005-04-03  1:34 ` "multithread" Jim Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Jean-Baptiste CAMPESATO @ 2005-04-02 22:37 UTC (permalink / raw)


Hello,
I want to create a function wich can called "several times at the same 
time", MultiThread.
I found task and i tested :
In ADS :
        -- Tache pour le traitement du client
        task Traitement is
                entry Go(Client:Socket_Type);
        end Traitement;
-----------------------------------------------
In ADB :
        task body Traitement is
        begin
                accept Go(Client:Socket_Type) do
                        put_line("Tache.");
                        Close_Socket(Client);
                end Go;
        end Traitement;
------------------------------------------------
In the loop wich call Traitement:
                loop
                        -- On accepte le client
                        Accept_Socket (Server, Client, Address);
                        -- Et on crᅵᅵ un thread pour lui
                        Traitement.Go(Client);
                end loop;


And the first time i call the task it's Ok, but at the second time i've a
"TASKING_ERROR".

Somebody can help me ?

Thanks.



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

* Re: "multithread"
  2005-04-02 22:37 "multithread" Jean-Baptiste CAMPESATO
@ 2005-04-03  1:34 ` Jim Rogers
  2005-04-03  7:30   ` "multithread" Jean-Baptiste CAMPESATO
  2005-04-03  7:12 ` "multithread" Martin Dowie
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Jim Rogers @ 2005-04-03  1:34 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1954 bytes --]

Jean-Baptiste CAMPESATO <camje_lemon@nospam.a2lf.org> wrote in 
news:pan.2005.04.02.22.37.39.88996@nospam.a2lf.org:

> Hello,
> I want to create a function wich can called "several times at the same 
> time", MultiThread.
> I found task and i tested :
> In ADS :
>         -- Tache pour le traitement du client
>         task Traitement is
>                 entry Go(Client:Socket_Type);
>         end Traitement;
> -----------------------------------------------
> In ADB :
>         task body Traitement is
>         begin
>                 accept Go(Client:Socket_Type) do
>                         put_line("Tache.");
>                         Close_Socket(Client);
>                 end Go;
>         end Traitement;
> ------------------------------------------------
> In the loop wich call Traitement:
>                 loop
>                         -- On accepte le client
>                         Accept_Socket (Server, Client, Address);
>                         -- Et on cr�� un thread pour lui
>                         Traitement.Go(Client);
>                 end loop;
> 
> 
> And the first time i call the task it's Ok, but at the second time i've 
a
> "TASKING_ERROR".
Task Traitement terminates at the end of its first execution. Tasks are 
not
callable after they terminate. You need to create a loop in the 
Traitement
to allow it to accept the Go entry as many times as necessary.

task body Traitement is
begin
   loop
      select
         accept Go(Client : Socket_Type) do
            Put_Line("Tache.");
            Close_Socket(Client);
         or 
            terminate;
      end select;
   end loop;
end Traitement;


The selective accept with a terminate alternative should provide you
with the functionality you want. The task will continue to loop through
the selection of the entry Go until the the task that calls the Go entry
terminates. Task Traitement will then automatically terminate cleanly.

Jim Rogers




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

* Re: "multithread"
  2005-04-02 22:37 "multithread" Jean-Baptiste CAMPESATO
  2005-04-03  1:34 ` "multithread" Jim Rogers
@ 2005-04-03  7:12 ` Martin Dowie
  2005-04-03  8:40 ` "multithread" Martin Krischik
  2005-04-03 22:27 ` "multithread" Jeffrey Carter
  3 siblings, 0 replies; 11+ messages in thread
From: Martin Dowie @ 2005-04-03  7:12 UTC (permalink / raw)


Jean-Baptiste CAMPESATO wrote:
> Hello,
> I want to create a function wich can called "several times at the same 
> time", MultiThread.
> I found task and i tested :
> In ADS :
>         -- Tache pour le traitement du client
>         task Traitement is
>                 entry Go(Client:Socket_Type);
>         end Traitement;
> -----------------------------------------------
> In ADB :
>         task body Traitement is
>         begin

loop

>                 accept Go(Client:Socket_Type) do
>                         put_line("Tache.");
>                         Close_Socket(Client);
>                 end Go;

end loop;

>         end Traitement;
> ------------------------------------------------
> In the loop wich call Traitement:
>                 loop
>                         -- On accepte le client
>                         Accept_Socket (Server, Client, Address);
>                         -- Et on crᅵᅵ un thread pour lui
>                         Traitement.Go(Client);
>                 end loop;
> 
> 
> And the first time i call the task it's Ok, but at the second time i've a
> "TASKING_ERROR".
> 
> Somebody can help me ?
> 
> Thanks.

For a start.

Cheers

-- Martin



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

* Re: "multithread"
  2005-04-03  1:34 ` "multithread" Jim Rogers
@ 2005-04-03  7:30   ` Jean-Baptiste CAMPESATO
  0 siblings, 0 replies; 11+ messages in thread
From: Jean-Baptiste CAMPESATO @ 2005-04-03  7:30 UTC (permalink / raw)


Le Sun, 03 Apr 2005 01:34:48 +0000, Jim Rogers a ᅵcritᅵ:

> Jean-Baptiste CAMPESATO <camje_lemon@nospam.a2lf.org> wrote in 
> news:pan.2005.04.02.22.37.39.88996@nospam.a2lf.org:
> 
>> Hello,
>> I want to create a function wich can called "several times at the same 
>> time", MultiThread.
>> I found task and i tested :
>> In ADS :
>>         -- Tache pour le traitement du client
>>         task Traitement is
>>                 entry Go(Client:Socket_Type);
>>         end Traitement;
>> -----------------------------------------------
>> In ADB :
>>         task body Traitement is
>>         begin
>>                 accept Go(Client:Socket_Type) do
>>                         put_line("Tache.");
>>                         Close_Socket(Client);
>>                 end Go;
>>         end Traitement;
>> ------------------------------------------------
>> In the loop wich call Traitement:
>>                 loop
>>                         -- On accepte le client
>>                         Accept_Socket (Server, Client, Address);
>>                         -- Et on crᅵᅵ un thread pour lui
>>                         Traitement.Go(Client);
>>                 end loop;
>> 
>> 
>> And the first time i call the task it's Ok, but at the second time i've 
> a
>> "TASKING_ERROR".
> Task Traitement terminates at the end of its first execution. Tasks are 
> not
> callable after they terminate. You need to create a loop in the 
> Traitement
> to allow it to accept the Go entry as many times as necessary.
> 
> task body Traitement is
> begin
>    loop
>       select
>          accept Go(Client : Socket_Type) do
>             Put_Line("Tache.");
>             Close_Socket(Client);
>          or 
>             terminate;
>       end select;
>    end loop;
> end Traitement;
> 
> 
> The selective accept with a terminate alternative should provide you
> with the functionality you want. The task will continue to loop through
> the selection of the entry Go until the the task that calls the Go entry
> terminates. Task Traitement will then automatically terminate cleanly.
> 
> Jim Rogers

Thanks a lot for Jim Rogers and Martin Dowie :))
It's ok :)



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

* Re: "multithread"
  2005-04-02 22:37 "multithread" Jean-Baptiste CAMPESATO
  2005-04-03  1:34 ` "multithread" Jim Rogers
  2005-04-03  7:12 ` "multithread" Martin Dowie
@ 2005-04-03  8:40 ` Martin Krischik
  2005-04-03  9:07   ` "multithread" Jean-Baptiste CAMPESATO
  2005-04-03 22:27 ` "multithread" Jeffrey Carter
  3 siblings, 1 reply; 11+ messages in thread
From: Martin Krischik @ 2005-04-03  8:40 UTC (permalink / raw)


Jean-Baptiste CAMPESATO wrote:

> Hello,
> I want to create a function wich can called "several times at the same
> time", MultiThread.

Apart from the tips you allready got: If you want Go to be called more then
once "at the same time" you will need a "task type" instead of a simple
task.



> I found task and i tested :
> In ADS :
>         -- Tache pour le traitement du client
>         task Traitement is
>                 entry Go(Client:Socket_Type);
>         end Traitement;

         task type Traitement is
                 entry Go(Client:Socket_Type);
         end Traitement;

       type Traitement_Access is access Traitement ;

> -----------------------------------------------
> In ADB :
>         task body Traitement is
>         begin
>                 accept Go(Client:Socket_Type) do
>                         put_line("Tache.");
>                         Close_Socket(Client);
>                 end Go;
>         end Traitement;
> ------------------------------------------------
> In the loop wich call Traitement:
>                 loop
>                         -- On accepte le client
>                         Accept_Socket (Server, Client, Address);

Inside the loop you would need to create a new task from the task type:

     declare
          New_Traitement  : Traitement_Access := new Traitement 
     begin                      
          -- Et on crᅵᅵ un thread pour lui
          New_Traitement.Go(Client);
    end;
  
>                 end loop;

And now it get's tricky - because this is the one point where garbage
collection is really missing. Garbage collection is only an optional
feature and standart Ada compilers haven't got it.

But you never know when the task is finished so you never know when to free
the memory allocated for the task.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

* Re: "multithread"
  2005-04-03  8:40 ` "multithread" Martin Krischik
@ 2005-04-03  9:07   ` Jean-Baptiste CAMPESATO
  2005-04-03 11:13     ` "multithread" Martin Krischik
  0 siblings, 1 reply; 11+ messages in thread
From: Jean-Baptiste CAMPESATO @ 2005-04-03  9:07 UTC (permalink / raw)


Le Sun, 03 Apr 2005 10:40:10 +0200, Martin Krischik a ᅵcritᅵ:

> Jean-Baptiste CAMPESATO wrote:
> 
>> Hello,
>> I want to create a function wich can called "several times at the same
>> time", MultiThread.
> 
> Apart from the tips you allready got: If you want Go to be called more then
> once "at the same time" you will need a "task type" instead of a simple
> task.
> 
> 
> 
>> I found task and i tested :
>> In ADS :
>>         -- Tache pour le traitement du client
>>         task Traitement is
>>                 entry Go(Client:Socket_Type);
>>         end Traitement;
> 
>          task type Traitement is
>                  entry Go(Client:Socket_Type);
>          end Traitement;
> 
>        type Traitement_Access is access Traitement ;
> 
>> -----------------------------------------------
>> In ADB :
>>         task body Traitement is
>>         begin
>>                 accept Go(Client:Socket_Type) do
>>                         put_line("Tache.");
>>                         Close_Socket(Client);
>>                 end Go;
>>         end Traitement;
>> ------------------------------------------------
>> In the loop wich call Traitement:
>>                 loop
>>                         -- On accepte le client
>>                         Accept_Socket (Server, Client, Address);
> 
> Inside the loop you would need to create a new task from the task type:
> 
>      declare
>           New_Traitement  : Traitement_Access := new Traitement 
>      begin                      
>           -- Et on crᅵᅵ un thread pour lui
>           New_Traitement.Go(Client);
>     end;
>   
>>                 end loop;
> 
> And now it get's tricky - because this is the one point where garbage
> collection is really missing. Garbage collection is only an optional
> feature and standart Ada compilers haven't got it.
> 
> But you never know when the task is finished so you never know when to free
> the memory allocated for the task.
> 
> Martin

Ok thanks.
But the answer of Jim Rogers works for me :/.
It's strange.



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

* Re: "multithread"
  2005-04-03  9:07   ` "multithread" Jean-Baptiste CAMPESATO
@ 2005-04-03 11:13     ` Martin Krischik
  2005-04-03 12:14       ` "multithread" Jean-Baptiste CAMPESATO
  2005-04-03 13:24       ` "multithread" Jean-Baptiste CAMPESATO
  0 siblings, 2 replies; 11+ messages in thread
From: Martin Krischik @ 2005-04-03 11:13 UTC (permalink / raw)


Jean-Baptiste CAMPESATO wrote:

> Le Sun, 03 Apr 2005 10:40:10 +0200, Martin Krischik a ᅵcritᅵ:
> 
>> Jean-Baptiste CAMPESATO wrote:
>> 
>>> Hello,
>>> I want to create a function wich can called "several times at the same
>>> time", MultiThread.
>> 
>> Apart from the tips you allready got: If you want Go to be called more
>> then once "at the same time" you will need a "task type" instead of a
>> simple task.
>> 
>> 
>> 
>>> I found task and i tested :
>>> In ADS :
>>>         -- Tache pour le traitement du client
>>>         task Traitement is
>>>                 entry Go(Client:Socket_Type);
>>>         end Traitement;
>> 
>>          task type Traitement is
>>                  entry Go(Client:Socket_Type);
>>          end Traitement;
>> 
>>        type Traitement_Access is access Traitement ;
>> 
>>> -----------------------------------------------
>>> In ADB :
>>>         task body Traitement is
>>>         begin
>>>                 accept Go(Client:Socket_Type) do
>>>                         put_line("Tache.");
>>>                         Close_Socket(Client);
>>>                 end Go;
>>>         end Traitement;
>>> ------------------------------------------------
>>> In the loop wich call Traitement:
>>>                 loop
>>>                         -- On accepte le client
>>>                         Accept_Socket (Server, Client, Address);
>> 
>> Inside the loop you would need to create a new task from the task type:
>> 
>>      declare
>>           New_Traitement  : Traitement_Access := new Traitement
>>      begin
>>           -- Et on crᅵᅵ un thread pour lui
>>           New_Traitement.Go(Client);
>>     end;
>>   
>>>                 end loop;
>> 
>> And now it get's tricky - because this is the one point where garbage
>> collection is really missing. Garbage collection is only an optional
>> feature and standart Ada compilers haven't got it.
>> 
>> But you never know when the task is finished so you never know when to
>> free the memory allocated for the task.
>> 
>> Martin
> 
> Ok thanks.
> But the answer of Jim Rogers works for me :/.
> It's strange.

Prehaps "Go" executes so fast that you never notice the difference ;-).

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

* Re: "multithread"
  2005-04-03 11:13     ` "multithread" Martin Krischik
@ 2005-04-03 12:14       ` Jean-Baptiste CAMPESATO
  2005-04-03 13:42         ` "multithread" Adrian Knoth
  2005-04-03 13:24       ` "multithread" Jean-Baptiste CAMPESATO
  1 sibling, 1 reply; 11+ messages in thread
From: Jean-Baptiste CAMPESATO @ 2005-04-03 12:14 UTC (permalink / raw)


Le Sun, 03 Apr 2005 13:13:56 +0200, Martin Krischik a ᅵcritᅵ:

> Jean-Baptiste CAMPESATO wrote:
> 
>> Le Sun, 03 Apr 2005 10:40:10 +0200, Martin Krischik a ᅵcritᅵ:
>> 
>>> Jean-Baptiste CAMPESATO wrote:
>>> 
>>>> Hello,
>>>> I want to create a function wich can called "several times at the same
>>>> time", MultiThread.
>>> 
>>> Apart from the tips you allready got: If you want Go to be called more
>>> then once "at the same time" you will need a "task type" instead of a
>>> simple task.
>>> 
>>> 
>>> 
>>>> I found task and i tested :
>>>> In ADS :
>>>>         -- Tache pour le traitement du client
>>>>         task Traitement is
>>>>                 entry Go(Client:Socket_Type);
>>>>         end Traitement;
>>> 
>>>          task type Traitement is
>>>                  entry Go(Client:Socket_Type);
>>>          end Traitement;
>>> 
>>>        type Traitement_Access is access Traitement ;
>>> 
>>>> -----------------------------------------------
>>>> In ADB :
>>>>         task body Traitement is
>>>>         begin
>>>>                 accept Go(Client:Socket_Type) do
>>>>                         put_line("Tache.");
>>>>                         Close_Socket(Client);
>>>>                 end Go;
>>>>         end Traitement;
>>>> ------------------------------------------------
>>>> In the loop wich call Traitement:
>>>>                 loop
>>>>                         -- On accepte le client
>>>>                         Accept_Socket (Server, Client, Address);
>>> 
>>> Inside the loop you would need to create a new task from the task type:
>>> 
>>>      declare
>>>           New_Traitement  : Traitement_Access := new Traitement
>>>      begin
>>>           -- Et on crᅵᅵ un thread pour lui
>>>           New_Traitement.Go(Client);
>>>     end;
>>>   
>>>>                 end loop;
>>> 
>>> And now it get's tricky - because this is the one point where garbage
>>> collection is really missing. Garbage collection is only an optional
>>> feature and standart Ada compilers haven't got it.
>>> 
>>> But you never know when the task is finished so you never know when to
>>> free the memory allocated for the task.
>>> 
>>> Martin
>> 
>> Ok thanks.
>> But the answer of Jim Rogers works for me :/.
>> It's strange.
> 
> Prehaps "Go" executes so fast that you never notice the difference ;-).
> 
> Martin

hello.
I wrote a delay for 5seconds, and executed 3 tasks before 5secons without
error.
Hmm, i will retest your task type to see differences. 
Thanks.



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

* Re: "multithread"
  2005-04-03 11:13     ` "multithread" Martin Krischik
  2005-04-03 12:14       ` "multithread" Jean-Baptiste CAMPESATO
@ 2005-04-03 13:24       ` Jean-Baptiste CAMPESATO
  1 sibling, 0 replies; 11+ messages in thread
From: Jean-Baptiste CAMPESATO @ 2005-04-03 13:24 UTC (permalink / raw)


Le Sun, 03 Apr 2005 13:13:56 +0200, Martin Krischik a ᅵcritᅵ:

> Jean-Baptiste CAMPESATO wrote:
> 
>> Le Sun, 03 Apr 2005 10:40:10 +0200, Martin Krischik a ᅵcritᅵ:
>> 
>>> Jean-Baptiste CAMPESATO wrote:
>>> 
>>>> Hello,
>>>> I want to create a function wich can called "several times at the same
>>>> time", MultiThread.
>>> 
>>> Apart from the tips you allready got: If you want Go to be called more
>>> then once "at the same time" you will need a "task type" instead of a
>>> simple task.
>>> 
>>> 
>>> 
>>>> I found task and i tested :
>>>> In ADS :
>>>>         -- Tache pour le traitement du client
>>>>         task Traitement is
>>>>                 entry Go(Client:Socket_Type);
>>>>         end Traitement;
>>> 
>>>          task type Traitement is
>>>                  entry Go(Client:Socket_Type);
>>>          end Traitement;
>>> 
>>>        type Traitement_Access is access Traitement ;
>>> 
>>>> -----------------------------------------------
>>>> In ADB :
>>>>         task body Traitement is
>>>>         begin
>>>>                 accept Go(Client:Socket_Type) do
>>>>                         put_line("Tache.");
>>>>                         Close_Socket(Client);
>>>>                 end Go;
>>>>         end Traitement;
>>>> ------------------------------------------------
>>>> In the loop wich call Traitement:
>>>>                 loop
>>>>                         -- On accepte le client
>>>>                         Accept_Socket (Server, Client, Address);
>>> 
>>> Inside the loop you would need to create a new task from the task type:
>>> 
>>>      declare
>>>           New_Traitement  : Traitement_Access := new Traitement
>>>      begin
>>>           -- Et on crᅵᅵ un thread pour lui
>>>           New_Traitement.Go(Client);
>>>     end;
>>>   
>>>>                 end loop;
>>> 
>>> And now it get's tricky - because this is the one point where garbage
>>> collection is really missing. Garbage collection is only an optional
>>> feature and standart Ada compilers haven't got it.
>>> 
>>> But you never know when the task is finished so you never know when to
>>> free the memory allocated for the task.
>>> 
>>> Martin
>> 
>> Ok thanks.
>> But the answer of Jim Rogers works for me :/.
>> It's strange.
> 
> Prehaps "Go" executes so fast that you never notice the difference ;-).
> 
> Martin

You were right.
After gdb-ing i saw :
With type he create Thread for every client, without he create two threads
and the Task wait Go after Go and not every go at the same times.
Thanks.



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

* Re: "multithread"
  2005-04-03 12:14       ` "multithread" Jean-Baptiste CAMPESATO
@ 2005-04-03 13:42         ` Adrian Knoth
  0 siblings, 0 replies; 11+ messages in thread
From: Adrian Knoth @ 2005-04-03 13:42 UTC (permalink / raw)


Jean-Baptiste CAMPESATO <camje_lemon@nospam.a2lf.org> wrote:

[something]

Would you like to fix your mail-relay?

   ----- Transcript of session follows -----
... while talking to nospam.a2lf.org.:
>>> DATA
<<< 554 <camje_lemon@nospam.a2lf.org>: Relay access denied


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Es muss gespart werden, koste es was es wolle!



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

* Re: "multithread"
  2005-04-02 22:37 "multithread" Jean-Baptiste CAMPESATO
                   ` (2 preceding siblings ...)
  2005-04-03  8:40 ` "multithread" Martin Krischik
@ 2005-04-03 22:27 ` Jeffrey Carter
  3 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Carter @ 2005-04-03 22:27 UTC (permalink / raw)


Jean-Baptiste CAMPESATO wrote:

> I want to create a function wich can called "several times at the same 
> time", MultiThread.

All subprograms in Ada are re-entrant. If they don't have side effects, 
they may safely be called from different tasks at the same time.

-- 
Jeff Carter
"Alms for an ex-leper!"
Monty Python's Life of Brian
75



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

end of thread, other threads:[~2005-04-03 22:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-02 22:37 "multithread" Jean-Baptiste CAMPESATO
2005-04-03  1:34 ` "multithread" Jim Rogers
2005-04-03  7:30   ` "multithread" Jean-Baptiste CAMPESATO
2005-04-03  7:12 ` "multithread" Martin Dowie
2005-04-03  8:40 ` "multithread" Martin Krischik
2005-04-03  9:07   ` "multithread" Jean-Baptiste CAMPESATO
2005-04-03 11:13     ` "multithread" Martin Krischik
2005-04-03 12:14       ` "multithread" Jean-Baptiste CAMPESATO
2005-04-03 13:42         ` "multithread" Adrian Knoth
2005-04-03 13:24       ` "multithread" Jean-Baptiste CAMPESATO
2005-04-03 22:27 ` "multithread" Jeffrey Carter

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