当前位置: 技术问答>linux和unix
sturct的问题?
来源: 互联网 发布时间:2016-04-15
本文导语: 定义的struct好像有问题 但是看不出来哪里错了 请高人指教 谢谢! 头文件uthread.h中我是这样写的 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #ifndef UTHREAD_H #define UTHREAD_H #include #include #include #include #include #include #include #incl...
定义的struct好像有问题
但是看不出来哪里错了
请高人指教
谢谢!
头文件uthread.h中我是这样写的
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifndef UTHREAD_H
#define UTHREAD_H
#include
#include
#include
#include
#include
#include
#include
#include
/* you might find some of these definitions helpful */
#define THR_QUANTUM_DEFAULT 5 /* default time quantum ms */
#define THR_STACK_DEFAULT 65536 /* default stack bytes */
#define THR_FAILURE -1 /* unable to create thread */
#define THR_NOSUCHTHREAD -1 /* bad access to thread */
#define MAX_JOIN_NUM 100 //maximum joinalbe number of thread
#define MILLION 1000000L //convert sec to msec
#ifdef __CPLUS_PLUS__
// C++: Provide C linkages
namespace "std" {
extern "C" {
#endif
typedef int ThreadId_t;
/* thread states */
typedef enum {
BLOCKED, /* blocked */
RUNNING, /* currently dispatched */
READY, /* in ready queue */
COMPLETED, /* returned from thread */
KILLED, /* killed by another thread
* (you don't need to implement this one)
*/
} ThreadState_t;
typedef enum {
THR_QUIET, /* no information */
THR_SWITCH, /* report thread switch */
THR_SUMMARY /* provide the same information as in thr_summary */
} thr_diagnostic_t;
/* Thread control block
* Add to this structure as you see fit, but you may not
* change the name
*/
typedef struct {
ThreadId_t id; /* unique identifier */
ThreadState_t state;
ucontext_t context; //record context
void *result; //record final result
ThreadId_t j[MAX_JOIN_NUM]; //maxinum number of joinable thread for thr_join
int acn; //record the active number of thread
struct timeval exest; //record start of exe time
struct timeval exendt; //record end of exe time
struct timeval qust; //record start time in READY queue
long qtime; //record end time in READY queue
thr_diagnostic_t debug; //set debug
double acw; //average context switch time
58 TCB *next;
} TCB;
TCB *head;
64 void thr_init(); /* Initialize thread package */
65 void thr_quantum(int N_ms); /* Set time quantum to N ms */
66 ThreadId_t thr_create(void * (*start_fn)(void *), void *arg);
67 void thr_exit(void *result);
68 int thr_join(ThreadId_t id, void **result);
69 void thr_diagnostics(thr_diagnostic_t Verbosity);
70 void thr_summary(FILE *FileHandle);
#ifdef __CPLUS_PLUS
}
}
#endif
#endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在thr_init.c文件中我是这样写的
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "uthread.h"
void thr_init()
{
// initiate thread queue
head = (TCB *)malloc(sizeof(TCB));
head->next = NULL;
head->id = 0;
head->state = RUNNING;
head->result = NULL;
head->acn = 1;
head->qtime = 0;
。。。。。。。。。。。。。。
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile的时候总是有这样的错
"thr_init.c", line 1: warning: invalid white space character in directive (第一行 我就写了个#include "uthread.h" 怎么就invalid了?)
"uthread.h", line 58: syntax error before or at: TCB
"uthread.h", line 64: member cannot be function: thr_init
"uthread.h", line 65: member cannot be function: thr_quantum
"uthread.h", line 66: member cannot be function: thr_create
"uthread.h", line 67: member cannot be function: thr_exit
"uthread.h", line 68: member cannot be function: thr_join
"uthread.h", line 69: member cannot be function: thr_diagnostics
"uthread.h", line 70: member cannot be function: thr_summary
但是看不出来哪里错了
请高人指教
谢谢!
头文件uthread.h中我是这样写的
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifndef UTHREAD_H
#define UTHREAD_H
#include
#include
#include
#include
#include
#include
#include
#include
/* you might find some of these definitions helpful */
#define THR_QUANTUM_DEFAULT 5 /* default time quantum ms */
#define THR_STACK_DEFAULT 65536 /* default stack bytes */
#define THR_FAILURE -1 /* unable to create thread */
#define THR_NOSUCHTHREAD -1 /* bad access to thread */
#define MAX_JOIN_NUM 100 //maximum joinalbe number of thread
#define MILLION 1000000L //convert sec to msec
#ifdef __CPLUS_PLUS__
// C++: Provide C linkages
namespace "std" {
extern "C" {
#endif
typedef int ThreadId_t;
/* thread states */
typedef enum {
BLOCKED, /* blocked */
RUNNING, /* currently dispatched */
READY, /* in ready queue */
COMPLETED, /* returned from thread */
KILLED, /* killed by another thread
* (you don't need to implement this one)
*/
} ThreadState_t;
typedef enum {
THR_QUIET, /* no information */
THR_SWITCH, /* report thread switch */
THR_SUMMARY /* provide the same information as in thr_summary */
} thr_diagnostic_t;
/* Thread control block
* Add to this structure as you see fit, but you may not
* change the name
*/
typedef struct {
ThreadId_t id; /* unique identifier */
ThreadState_t state;
ucontext_t context; //record context
void *result; //record final result
ThreadId_t j[MAX_JOIN_NUM]; //maxinum number of joinable thread for thr_join
int acn; //record the active number of thread
struct timeval exest; //record start of exe time
struct timeval exendt; //record end of exe time
struct timeval qust; //record start time in READY queue
long qtime; //record end time in READY queue
thr_diagnostic_t debug; //set debug
double acw; //average context switch time
58 TCB *next;
} TCB;
TCB *head;
64 void thr_init(); /* Initialize thread package */
65 void thr_quantum(int N_ms); /* Set time quantum to N ms */
66 ThreadId_t thr_create(void * (*start_fn)(void *), void *arg);
67 void thr_exit(void *result);
68 int thr_join(ThreadId_t id, void **result);
69 void thr_diagnostics(thr_diagnostic_t Verbosity);
70 void thr_summary(FILE *FileHandle);
#ifdef __CPLUS_PLUS
}
}
#endif
#endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在thr_init.c文件中我是这样写的
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "uthread.h"
void thr_init()
{
// initiate thread queue
head = (TCB *)malloc(sizeof(TCB));
head->next = NULL;
head->id = 0;
head->state = RUNNING;
head->result = NULL;
head->acn = 1;
head->qtime = 0;
。。。。。。。。。。。。。。
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile的时候总是有这样的错
"thr_init.c", line 1: warning: invalid white space character in directive (第一行 我就写了个#include "uthread.h" 怎么就invalid了?)
"uthread.h", line 58: syntax error before or at: TCB
"uthread.h", line 64: member cannot be function: thr_init
"uthread.h", line 65: member cannot be function: thr_quantum
"uthread.h", line 66: member cannot be function: thr_create
"uthread.h", line 67: member cannot be function: thr_exit
"uthread.h", line 68: member cannot be function: thr_join
"uthread.h", line 69: member cannot be function: thr_diagnostics
"uthread.h", line 70: member cannot be function: thr_summary
|
typedef struct {
......
TCB *next;
} TCB;
is wrong, you should so define:
typedef struct TCB_t{
......
struct TCB_t *next;
} TCB;
......
TCB *next;
} TCB;
is wrong, you should so define:
typedef struct TCB_t{
......
struct TCB_t *next;
} TCB;
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。