A protected type contains data that tasks can access only through a set of protected operations defined by the developer. There are three kinds of protected operations:
Protected types tend to be very efficient, since high-overhead operations called "full context switches" aren't usually necessary to implement them. Protected types are often implemented using techniques such as interrupt disables, priority ceiling locking, or spin locks. In fact, protected types are often more efficient than using semaphores directly, which is a little surprising; see the Ada Rationale (Part 2, section 9.1.3) if you're curious why protected types can be so efficient. However, this also means that any protected operation should be short and fast; significant processing should be done elsewhere. Protected operations generally should do things like increment or decrement a value, set a flag, set an access value or two, or other similar quick operations. Lengthy operations may increase the maximum system latency (the time it takes for the system to respond to a new situation), which in many systems is a bad thing.
A protected type can be created as a single instance (i.e. a single protected variable) or as a full Ada type. As the latter you can do anything you would do with a regular type, including placing them in records or arrays.
Let's say you're creating a protected type and you want to create an operation that changes the protected type's data. This operation can always occur - it doesn't need to wait for some special circumstance. Which of the following should this operation be?
![]() |
![]() |
![]() |
---|
David A. Wheeler (dwheeler@ida.org)