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 X-Received: by 10.182.102.34 with SMTP id fl2mr17854978obb.16.1405574299700; Wed, 16 Jul 2014 22:18:19 -0700 (PDT) X-Received: by 10.182.105.101 with SMTP id gl5mr258456obb.4.1405574299076; Wed, 16 Jul 2014 22:18:19 -0700 (PDT) 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!news.glorb.com!h18no2903932igc.0!news-out.google.com!gf2ni864igb.0!nntp.google.com!h18no1536850igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 16 Jul 2014 22:18:18 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=73.179.102.101; posting-account=wEPvUgoAAABrLeiz_LRhQ3jeEhyfWVMH NNTP-Posting-Host: 73.179.102.101 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <50bdb713-7ce1-411b-810b-9bdee1d26b7a@googlegroups.com> Subject: Timeouts in Ada From: NiGHTS Injection-Date: Thu, 17 Jul 2014 05:18:19 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:20986 Date: 2014-07-16T22:18:18-07:00 List-Id: First of all I just want to say how much I appreciate the help you have giv= en me so far with the questions I have had. For this next question I am interested in creating a "wrapper" around certa= in tasks that should have a timeout period. I feel this feature is part of = what makes Ada so good at keeping a software running stable. There are plen= ty of network and I/O tasks that I would love to have a "fallback" plan in = the event that they take too long to execute.=20 For study on this subject I am using this as a reference: http://en.wikibooks.org/wiki/Ada_Programming/Tasking#Timeout I am looking at Ex. 10.=20 task Password_Server is entry Check (User, Pass : in String; Valid : out Boolean); entry Set (User, Pass : in String); end Password_Server; ... User_Name, Password : String (1 .. 8); ... Put ("Please give your new password:"); Get_Line (Password); select Password_Server.Set (User_Name, Password); Put_Line ("Done"); or delay 10.0; Put_Line ("The system is busy now, please try again later."); end select; Now as an Ada beginner with a strong background in C/Asm I interpret this e= xample in the following way... 1. "select" creates a thread which runs the body of "select" or the body of= "or". Or maybe it creates two threads for each and blocks its own thread u= ntil one finishes. 2. In either case the variables in scope where "select" was run will be acc= essible to both the thread created to deal with the body of "select" and th= e body of "or" 3. The "Password_Server" task is run in its very own thread so it has its o= wn internal scope of variables. So this would mean that the "select" body i= s dealing with two nested threads. 4. If the "select" body completes before the "or" body is completed, the "o= r" thread is terminated. If the "or" body completes before the "select" bod= y completes, the "select" body and the Password_Server (if applicable) is t= erminated. 5.a. If both threads happen to reach the "Put_Line" command of each body, b= oth threads will terminate and there would be a conflict of information -- = It will confuse the user with printing both "Done" AND "The system is busy"= . If this was a more mission-critical operation, both the main operation an= d its fallback plan may execute at the same time. In other words I don't se= e how this is atomic, and if its not atomic how could this possibly be usef= ul to anyone? 5.b. Terminating threads while its doing things (while writing to shared me= mory? performing network operations mid-way?) sounds disastrous, but it see= ms like the only way this could possibly function in Ada. Now keep in mind these are all assumptions I made in order to make sense of= what I am reading. So far in my self-study of Ada 80% of everything had to= be assumed with the help of trial and error because no literature that I h= ave read explained WHY things happen, only superficial usage syntax. Its ra= ther annoying but that is why I am so thrilled to be able to ask this quest= ion here. Thank you again for all your help!