comp.lang.ada
 help / color / mirror / Atom feed
From: Wiktor Moskwa <wiktorDOTmoskwa@gmail.com>
Subject: GNAT and large number of threads
Date: Thu, 26 Apr 2007 22:50:49 +0000 (UTC)
Date: 2007-04-26T22:50:49+00:00	[thread overview]
Message-ID: <f0rac9$dip$1@nemesis.news.tpi.pl> (raw)

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



             reply	other threads:[~2007-04-26 22:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-26 22:50 Wiktor Moskwa [this message]
2007-04-26 23:56 ` GNAT and large number of threads Gene
2007-04-27  5:46   ` Stefan Bellon
2007-04-27 15:39   ` Wiktor Moskwa
2007-04-27  4:49 ` Jeffrey R. Carter
2007-04-27 14:52   ` Wiktor Moskwa
2007-04-27 18:45 ` Alex R. Mosteo
2007-04-27 18:51   ` Pascal Obry
replies disabled

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