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 6820647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:26:59+00:00 2026-05-26T21:26:59+00:00

How can I freeze a task? I mean, if I have a task task

  • 0

How can I freeze a task?

I mean, if I have a task

task body My_Task is
begin 
  accept Start;
  loop
    Put ("1");
    Put ("2");
    Put ("3");
    ...
    Put ("n");
  end loop;
end My_Task;

is there a way that I can “freeze” the task in its current state? If, for instance, the execution finished executing Put ("2");, how can I freeze it and later I can turn it to continue? I want to provoque a freeze from outside the task, and also from outside, order it to continue.

Update

I could sure implement, if I had the spec like

type State_Type is
  (RUN,
   FROZEN);

task type My_Task (State : State_Type) is
   entry Start;
end My_Task;

the body

task body My_Task is
begin 
  accept Start;
  loop
    Put ("1");
    Put ("2");
    Put ("3");
    ...
    Put ("n");

    loop 
     if State = RUN then exit; end if;
    end loop;
  end loop;
end My_Task;

but it would not be the case because I had to wait for the nth Put instruction line (i.e., the task would not be actually frozen, because the inside loop would be running).

  • 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-05-26T21:27:00+00:00Added an answer on May 26, 2026 at 9:27 pm

    You can use a “selective accept” to allow your task to be interrupted by an external caller (another task or the main program). You can’t (easily) interrupt a task at an arbitrary point in its execution; instead, the task itself needs to determine when it will accept entry calls.

    So you’ll probably want to replace your sequence

    Put("1");
    Put("2");
    Put("3");
    ...
    Put("n");
    

    by a loop that calls Put once on each iteration, with a select statement that’s executed each time.

    Here’s a demo program that I just threw together. The counter increments once per second (approximately). The counter value is printed if Running is true; otherwise the loop proceeds silently. The main program alternatively calls Pause and Resume every 3 seconds.

    The else clause in the select statement cause it to continue executing if neither entry has been called.

    with Ada.Text_IO; use Ada.Text_IO;
    procedure T is
    
        task Looper is
            entry Pause;
            entry Resume;
        end Looper;
    
        task body Looper is
            Running: Boolean := True;
            Count: Integer := 0;
        begin
            loop
                select
                    accept Pause do
                        Running := False;
                    end;
                or
                    accept Resume do
                        Running := True;
                    end;
                else
                    null;
                end select;
                delay 1.0;
                if Running then
                    Put_Line("Running, Count = " & Integer'Image(Count));
                end if;
                Count := Count + 1;
            end loop;
        end Looper;
    
    begin -- T
        loop
            delay 3.0;
            Looper.Pause;
            delay 3.0;
            Looper.Resume;
        end loop;
    end T;
    

    There may be a more elegant approach than this. It’s been a long time since I’ve really used Ada.

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

Sidebar

Related Questions

How can I freeze Javascript in firebug so that i can inspect the changes
I'm using cx_Freeze to freeze my Python code so I can distribute it as
Can you cast a List<int> to List<string> somehow? I know I could loop through
I use Object#freeze to freeze the value of an object. I can write a
How can I restart gdm or the xserver without logging out? Sometimes, there is
I have tried to freeze orientation using: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Although the display stays in portrait
I have a minor problem where my (new) computer tends to completely freeze up.
I'm trying rewrite xCmd which can start a process on a remote machine. Basically
Got a bit of a mind freeze at the moment. I have the following
Can anyone tell me why this comparison keeps making my app freeze and crash?

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.