9 Ağustos 2017 Çarşamba

context

continuation Sınıfı
Şu satırı dahil ederiz.
#include <boost/context/continuation.hpp>
Constructor
Şöyle yaparız.
ctx::continuation source=ctx::callcc
(
  [](ctx::continuation && sink)
  {
    ...
    return std::move(sink);
   }
);
get_data metodu
Şöyle yaparız.
std::cout << source.get_data<int>() << " ";
resume metodu
Şöyle yaparız.
source=source.resume();
fcontext_t tipi
Şöyledir.
typedef void * fcontext_t;
make_fcontext metodu
İmzası şöyle
fcontext_t BOOST_CONTEXT_CALLDECL make_fcontext (void * sp, std::size_t size,
void (* fn)( intptr_t) );
Açıklaması şöyle
Depending on your CPU architecture, the stack might grow upwards (towards higher addresses) or downwards (towards lower addresses, as is the case on x86). This is generally hard-coded in the instruction set by the way the push and pop instructions modify the stack pointer. For example, the x86 push instruction subtracts from [er]?sp.

make_fcontext expects the stack pointer to have sufficient space in the architecture-specific direction needed by the platform. On x86, this means there must be available space before the pointer, not after. By passing the pointer you received from malloc directly, you are violating this contract.

This is why the stack_allocator abstractions exists. They return pointers that point to the right end of the stack, depending on the architecture.

(As a side note, I believe all architectures currently supported by Boost.Context have downwards-growing stacks.)
Şöyle yaparız.
// context-function
void f(intptr);


// creates a new stack
std::size_t size = 8192;
void* sp = ...;

// context fc uses f() as context function
// fcontext_t is placed on top of context stack
// a pointer to fcontext_t is returned
fcontext_t fc(make_fcontext(sp,size,f));

Hiç yorum yok:

Yorum Gönder