Yony
Yony

Reputation: 680

How to urgently inform task in Ada?

I have a task that perform sequential logic, and I want to stop this task from performing its logic from another task. Is there a way to do that without causing a rendezvous? How can I suspend the task? Thanks in advance.

Upvotes: 1

Views: 365

Answers (3)

T.E.D.
T.E.D.

Reputation: 44804

You might look at protecting whatever this operation or data is by implementing it inside a protected object.

It sounds to me like you are looking for some kind of locking scheme. It is fairly easy to implement all kinds of different locking schemes with Ada protected objects, and this way you don't need explicit handshaking between specific tasks.

Upvotes: 1

Marc C
Marc C

Reputation: 8522

Generally it's better to structure your sequential logic with "check points", such as a protected object flag, where a brief test can be made to see if there's been a signal to abort. Protected objects are designed to be a lightweight concurrency mechanism to support this sort of fast test.

Does it really need to be interruptible at any point in the statement sequence? Is the cost of the few extra micro- or milliseconds needed to complete a statement block or iteration and make a flag check really that unacceptable? How often do you anticipate needing to abort the processing sequence?

Having well-defined checkpoints at which to test for a signal to prematurely terminate processing can ensure that the sequence exits in a known state, which aids verifying correct operation and debugging if something goes awry.

Upvotes: 2

Rommudoh
Rommudoh

Reputation: 1804

You can use Asynchronous Transfer of Control and put the part you want to stop into the abortable_part, or directly use abort to kill the task.

If you use GNAT, you could have a look at the GNAT.Tasking package.

Upvotes: 3

Related Questions