头文件中结构体互相引用的问题

先上代码看下错误的例子:

typedef struct _thread{
    int       id;                        /* friendly id               */
    pthread_t pthread;                   /* pointer to actual thread  */
    thpool_handle_t thpool_p;            /* access to thpool          */
} thread_t;


/* Threadpool
 * threadpool has many threads, and he should to access each threads, threads pointer array to save all threads pointer */
typedef struct _thpool{
    thread_t**   threads;                  /* pointer to threads        */
    volatile int num_threads_alive;      /* threads currently alive   */
    volatile int num_threads_working;    /* threads currently working */
    pthread_mutex_t  thcount_lock;       /* used for thread count etc */
    jobqueue*  jobqueue_p;               /* pointer to the job queue  */
} thpool_t, *thpool_handle_t;

编译提示:
./include/thread_pool.h:31:5: error: unknown type name ‘thpool_handle_t’

 

修改如下解决:

struct _thread;
struct _thpool;
typedef struct _thread thread_t;
typedef struct _thpool thpool_t, *thpool_handle_t;

typedef struct _thread{
    int       id;                        /* friendly id               */
    pthread_t pthread;                   /* pointer to actual thread  */
    thpool_handle_t thpool_p;            /* access to thpool          */
} thread_t;


/* Threadpool
 * threadpool has many threads, and he should to access each threads, threads pointer array to save all threads pointer */
typedef struct _thpool{
    thread_t**   threads;                  /* pointer to threads        */
    volatile int num_threads_alive;      /* threads currently alive   */
    volatile int num_threads_working;    /* threads currently working */
    pthread_mutex_t  thcount_lock;       /* used for thread count etc */
    jobqueue*  jobqueue_p;               /* pointer to the job queue  */
} thpool_t, *thpool_handle_t;

 

转载于:https://www.cnblogs.com/biglucky/p/6349862.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值