fiber.cpp

来自「The Spectral Toolkit is a C++ spectral t」· C++ 代码 · 共 56 行

CPP
56
字号
//// spectral toolkit // copyright (c) 2005 university corporation for atmospheric research// licensed under the gnu general public license//#include "fiber.h"namespace spectral{  /// Fiber destructor.  fiber::~fiber() {}    /// Fiber constructor.  Initializes thread attributes.  fiber::fiber()  {    running=0;    pthread_attr_init(&attr);    pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);    pthread_attr_setscope(&attr,PTHREAD_SCOPE_SYSTEM);  }    /// Thread creation method.  Starts thread associated with this object  /// which in turn invokes the virtual start method.  /// \return 0 for success, pthread_create error code otherwise  int fiber::spawn()  {    int r=pthread_create(&tid,&attr,fiber_wrapper,this);    if(r==0)      running=1;    return(r);   }  /// Thread join method.  Blocks until thread function returns if the thread   /// is running, otherwise returns immediately.  /// \return pointer returned from pthread_join    void* fiber::join()  {    void *status=0;    if(running)      pthread_join(tid,&status);    return(status);  }}  void* fiber_wrapper(void *object){  spectral::fiber *F=(spectral::fiber*)object;  F->start();  return(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?