Async Reliability · 19 min · free with an account

Pinning Intuition

Lesson preview · about 30%

Promise that a value will not move in memory.

Core idea

Pin protects location-sensitive values after they are pinned; it does not make every value immovable from creation.

Start with the idea

Pin protects location-sensitive values after they are pinned; it does not make every value immovable from creation. Most users interact through pinned futures while libraries handle the unsafe construction details.

Some future state machines can contain references into their own stored state while suspended. Moving such a value after those references become valid could invalidate them. Pin<P> is a contract that the value reached through pointer P will not be moved again if the value's type relies on pinning. It is not a magical freeze of every value from birth, and it does not mean the surrounding pointer variable can never move.

Many ordinary types are Unpin, so pinning adds no movement restriction for them.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Concurrency & Async