comp.lang.ada
 help / color / mirror / Atom feed
* About task-safeness
@ 2011-02-02 20:51 mockturtle
  2011-02-02 21:01 ` Vinzent Hoefler
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: mockturtle @ 2011-02-02 20:51 UTC (permalink / raw)


Dear all,
I have a question (better, two questions) about packages and concurrence.  

We have a software, a fairly complex one, that makes use of tasks. (Just to give you the context, it is a network communication software that can have several connections open at once and every connection is handled by a task.)   Data structure that are designed to be shared among different tasks are implemented as protected objects, but it came to my mind that  an innocent-looking package (that maybe provides some general-purpose functions) could have some "internal state" represented by some variable global to the package.  (For example, a package defining some type of object could keep the number of allocated objects, so it can give to each object a unique ID.)  If such a package was used  by two  different tasks, and the counter was not protected, obscure bugs can arise.  This type of structure maybe is not very recommended, but it happens... :-(   

Of course, one could do a review of all the packages to check for this type of problems, but since an Ada compiler has the good habit of protecting you from yourself, I searched for a way to have the compiler to check the task-safety of the packages used by tasks.  

My first tentative was to ask that all the packages with-ed by a package that defines a task should be Pure (a Pure package cannot have any global variables).      Unfortunately, I soon discovered that asking for Pure-ity is too strong a requirement: all the ancestors must be Pure and no un-Pure package can be used.  Although such constraints make perfectly sense, they prevent you from using several standard (and useful) packages such as Unbounded_Strings, all (?) the Containers hierarchy and GNAT.Sockets (which turns out handy in a networking program...:-). (To be honest, my action of Pure-fication was not useless; while making my packages Pure, I caught a global counter in a package...) So, my first question is: 

   * Can you suggest a way to have the compiler to check for some task-safety of packages?  Even a technique for a non-totally exhaustive  check could be useful.

The thoughts above triggered in me another question.  Consider, for example, the Ordered_Maps package.  That package is not Pure (it cannot be, since it would prevent the use of named access types), so how can I be granted that the package does not have some "hidden" and unprotected state?  Please note that I am *not* asking for an *object* of type Ordered_Map to be task-safe, if I need I can wrap it in a protected object; I am asking for the *package* to be task-safe.  Note that if, say, Ordered_Maps has some hidden status, two task can modify the status at the same time by accessing to two Maps, even if the Maps have been wrapped inside two different protected  objects.  So, my second question is

  * Am I granted (maybe by some obscure paragraph of our beloved RM ;-) that the standard packages are task-safe? (I would be surprised if they weren't, but it is nice to be sure...)

Sorry for the quite long message and thank you for any help.



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

end of thread, other threads:[~2011-02-04  0:33 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-02 20:51 About task-safeness mockturtle
2011-02-02 21:01 ` Vinzent Hoefler
2011-02-02 21:14   ` mockturtle
2011-02-02 22:16     ` Maciej Sobczak
2011-02-02 22:28       ` Shark8
2011-02-02 22:40         ` Peter C. Chapin
2011-02-03  8:33           ` Dmitry A. Kazakov
2011-02-03 17:59       ` Vinzent Hoefler
2011-02-02 22:38 ` J-P. Rosen
2011-02-03  2:44 ` Randy Brukardt
2011-02-03  8:53   ` Niklas Holsti
2011-02-03 11:07     ` Georg Bauhaus
2011-02-03 11:22       ` AdaMagica
2011-02-03 18:13         ` Jeffrey Carter
2011-02-04  0:33     ` Randy Brukardt

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