thread.h

来自「initial working phase of the design of s」· C头文件 代码 · 共 51 行

H
51
字号
#ifndef __THREAD_H
#define __THREAD_H

#include "vector.h"

extern volatile struct thread
{
   void(vector::* addr)( void* );
   void* state;
   thread* next;
}* top_thread;

#define BUSY_THREAD ( thread* )1

#include <stdio.h> // printf

void term( int );

inline void spawn( void(vector::* v)( void* ), void* state )
{
   thread* next = ( thread* )top_thread;

//   printf( "+" );
//   fflush( stdout );

   while( next == BUSY_THREAD )

      next = ( thread* )top_thread;

   ( thread* )top_thread = BUSY_THREAD;

//   printf( "-" );
//   fflush( stdout );

//   printf( "%%" );
//   fflush( stdout );

   thread* top = new thread;

//   printf( "%%" );
//   fflush( stdout );

   top -> next = next;
   top -> addr = v; // failure centers on this
   top -> state = state;

   ( thread* )top_thread = top;
}

#endif // __THREAD_H

⌨️ 快捷键说明

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