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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Maximum Number Of Tasks? Date: Tue, 12 Nov 2013 11:59:13 +0100 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: <8738n1hon2.fsf@adaheads.sparre-andersen.dk> References: NNTP-Posting-Host: monowall.adaheads.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: loke.gir.dk 1384253953 5187 86.48.41.195 (12 Nov 2013 10:59:13 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 12 Nov 2013 10:59:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:fUvwNkrPh1AX5vG2O7n/JFYqBkY= Xref: news.eternal-september.org comp.lang.ada:17621 Date: 2013-11-12T11:59:13+01:00 List-Id: FritzVonBraun wrote: > I was wondering about the maximum number of tasks in Ada but I couldnt > find any info. Probably because it is both compiler, hardware and operating system dependent. > The question is, is a task in Ada technically similar to a thread in > Windows under the hood? That depends on which compiler you use. Some (most?) versions of GNAT use operating system threads to implement tasks. Janus/Ada implements tasks in its own run-time system. > Threads are restricted by the stack size that each thread has > reserved, so in practice the maximum number of threads is about 2000. I just made a quick test on my laptop. It appears that I can create 32041 tasks before I have to do something special to avoid problems. The test was done on a Debian 7.2 system with the GNAT 4.6 compiler distributed with Debian. The test program: with Ada.Text_IO; use Ada.Text_IO; procedure Task_Demo is task type Demo_Task (Index : Positive) is entry Stop; end Demo_Task; type Demo_Task_Reference is access Demo_Task; task body Demo_Task is begin Put_Line (Positive'Image (Index) & " launched."); accept Stop; Put_Line (Positive'Image (Index) & " stopping."); exception when others => Put_Line (Positive'Image (Index) & " terminated by an exception."); end Demo_Task; Collection : array (1 .. 32_041) of Demo_Task_Reference; begin for I in Collection'Range loop Collection (I) := new Demo_Task (Index => I); end loop; delay 1.0; for I in Collection'Range loop Collection (I).Stop; end loop; end Task_Demo; Reducing the stack size for the individual tasks does not seem to make a difference. > The reason I'm asking is that I wonder if Ada provides a more > comfortable solution to the thread pool problem. In C++ for example I > create a number of threads roughly equal to the number of processor > cores and then have a number of Jobs that are distributed over the > threads and which implement a time sharing system by returning control > to the thread which then assigns time to another Job. > > Would I have to do the same in Ada or are tasks meant to be "micro > objects' of which many can be created and the Ada runtime does > effectively what my threadpool system does in C++ That depends on your compiler. Greetings, Jacob -- "Two silk worms had a race. They ended up in a tie."