File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -321,6 +321,11 @@ public:
321321 my_context() {
322322 initialize_stack_memory(m_stack);
323323 }
324+ ~my_context () {
325+ // ‼️ The most derived context must call cancel in its destructor
326+ cancel ();
327+ // If memory was allocated, deallocate it here...
328+ }
324329
325330private:
326331 void do_schedule(async::blocked_by p_state,
@@ -330,6 +335,21 @@ private:
330335};
331336```
332337
338+ #### Initialization
339+
340+ In order to create a usable custom context, the stack memory must be
341+ initialized with a call to ` initialize_stack_memory(span) ` with a span to the
342+ memory for the stack. There is no requirements of where this memory comes from
343+ except that it be a valid source. Such sources can be array thats member of
344+ this object, dynamically allocated memory that the context has sole ownership
345+ of, or it can point to statically allocated memory that it has sole control and
346+ ownership over.
347+
348+ #### Destruction
349+
350+ The custom context must call ` cancel() ` before deallocating the stack memory.
351+ Once cancel completes, the stack memory may be deallocated.
352+
333353### Using basic_context with sync_wait
334354
335355``` cpp
@@ -340,6 +360,10 @@ public:
340360 simple_context() {
341361 initialize_stack_memory(m_stack);
342362 }
363+
364+ ~simple_context () {
365+ cancel ();
366+ }
343367};
344368
345369simple_context ctx;
You can’t perform that action at this time.
0 commit comments