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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bd6afd90718a4783,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.germany.com!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail From: Wiktor Moskwa Newsgroups: comp.lang.ada Subject: GNAT and large number of threads Date: Thu, 26 Apr 2007 22:50:49 +0000 (UTC) Organization: tp.internet - http://www.tpi.pl/ Message-ID: NNTP-Posting-Host: abol138.neoplus.adsl.tpnet.pl X-Trace: nemesis.news.tpi.pl 1177627849 13913 83.8.27.138 (26 Apr 2007 22:50:49 GMT) X-Complaints-To: usenet@tpi.pl NNTP-Posting-Date: Thu, 26 Apr 2007 22:50:49 +0000 (UTC) User-Agent: slrn/0.9.8.1pl1 (Debian) Xref: g2news1.google.com comp.lang.ada:15329 Date: 2007-04-26T22:50:49+00:00 List-Id: Hi, I'm using GNAT GPL 2006 on Linux x86. Recently I had a problem with creating large number of tasks(*) in my Ada program. I create tasks in a loop and when I reach the limit of stack address space the main thread freezes - no exceptions, nothing. Using ltrace tool reveals: ... pthread_create(0x9656e98, 0xbffca3d0, 0x80c3280, 0x9656e58, 10256) = 0 pthread_create(0x965a670, 0xbffca3d0, 0x80c3280, 0x965a630, 10256) = 0 pthread_create(0xbfd86048, 0xbffca3d0, 0x80c3280, 0xbfd86008, 10256)= 12 --- SIGSEGV (Segmentation fault) --- Error 12 is ENOMEM (the system lacked the necessary resources to create another thread). GNAT seems to completely ignore this error. Quick search in GNAT GPL sources shows that only EAGAIN error is taken into account, others are silently ignored. ======================================================================= [file: s-taprop-linux.adb; procedure: Create_Task] Result := pthread_create (T.Common.LL.Thread'Access, Attributes'Access, Thread_Body_Access (Wrapper), To_Address (T)); pragma Assert (Result = 0 or else Result = EAGAIN); Succeeded := Result = 0; Result := pthread_attr_destroy (Attributes'Access); pragma Assert (Result = 0); Set_Priority (T, Priority); ======================================================================= Succeeded (out paramter) is set to False in my case but I guess that pthread_attr_destroy or Set_Priority cannot be invoked after failure of pthread_create. I'm not sure because I don't know neither pthreads nor GNAT compiler. Nevertheless it looks like a GNAT bug to me, what do you think? My question is how can my program predict/calculate (approximetly) the maximum number of tasks that can be created with known maximum stack size per task (specified with pragma Storage_Size)? [*] I'm writing a simulator of a distributed protocol wiht one task per node so I really need large number of threads to simulate many nodes. Thanks, Wiktor -- Wiktor Moskwa