Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:06:21+00:00 2026-06-10T04:06:21+00:00

Let me illustrate this question with code first: with Ada.Text_IO; procedure Test is task

  • 0

Let me illustrate this question with code first:

with Ada.Text_IO;

procedure Test
is

   task type Serving_Task is
      entry Start;
   end Serving_Task;

   task body Serving_Task is begin
      accept Start;
      Ada.Text_IO.Put_Line ("Started");
      loop
         null; --  Blocking operation, eg. accepting on a socket.
         null; --  Processing on blocking operation's result.
      end loop;
      Ada.Text_IO.Put_Line ("Stopped");
   end Serving_Task;

   type Server is tagged limited record
      Serving : Serving_Task;
   end record;

   procedure Start
     (S : in out Server)
   is begin
      Ada.Text_IO.Put_Line ("Starting");
      S.Serving.Start;
   end Start;

   procedure Stop
     (S : in out Server)
   is begin
      Ada.Text_IO.Put_Line ("Stopping");
      -- TODO To implement.
   end Stop;

   Main_Server : Server;

begin
   Ada.Text_IO.Put_Line ("Calling Start");
   Start (Main_Server);
   delay 5.0;
   Ada.Text_IO.Put_Line ("Calling Stop");
   Stop (Main_Server);
end Test;

This is typical server construct – there’s a server task with a loop accepting incoming connections. My question is – what is the best way to implement Stop procedure for Server type.

I’d like it to wait until the serving task blocks on accepting a socket (or just before the blocking call, so every accepted request if fully handled before terminating the task) and exit the loop, so the task can clean up before terminating.

First thing that comes to mind is adding

select
   accept Stop;
or
   delay 0.1;
   exit;
end select;

at the end of the loop, but that’s 0.1 second wasted on each iteration. Seems significant.

I’ve looked at some examples in RM, Lovelace tutorial and Wikibook, but nothing really seemed appropriate.

What is the best practice for such (fairly common I believe) problem in Ada?

And the answer is…

Example solution based on Marc C‘s answer: https://gist.github.com/3413017

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:06:23+00:00Added an answer on June 10, 2026 at 4:06 am

    The way I typically set this up is first by using AdaCore’s GNAT.Sockets package, rather than directly programming the sockets. Since I’ll be using the (socket) select() function (which is wrapped as Check_Selector) to be notified when data is available on the socket, GNAT.Sockets provides an Abort_Selector() procedure that can be invoked from elsewhere. With the task blocked on Check_Selector(), I just wait for data to arrive (Status = Completed) or the flag that it’s time to exit (Status = Aborted).

    See the start of the Monitor_Connections procedure (lines 397-416ish) in the TOMI_4_Ada package TCP_Connect. Monitor_Connections is invoked from task Connection_Monitoring (lines 469-495).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To explain my question, let me first point to this array: <?php $_depends =
My question is best illustrated with a code sample, so let's just start off
Let me illustrate this question with a simplified example. Assume I am building a
To be specific let me illustrate the question with Spring http-remoting example. Suppose we
The following Groovy commands illustrate my problem. First of all, this works ( as
This situation is difficult to explain, so let me illustrate with a picture: Those
To illustrate my question more clearly, let's suppose I have a include.html template with
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
I read this question , which highlights a solution to conditionally insert values into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.