zoukankan      html  css  js  c++  java
  • 头文件中结构体互相引用的问题

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

    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;
  • 相关阅读:
    冒泡排序
    线程同步
    线程取消
    线程分离
    第3月第2天 find symbolicatecrash 生产者-消费者 ice 引用计数
    第3月第1天 GCDAsyncSocket dispatch_source_set_event_handler runloop
    第2月第25天 BlocksKit
    第2月第24天 coretext 行高
    第2月第6天 iOS 运行时添加属性和方法
    第2月第5天 arc invocation getReturnValue
  • 原文地址:https://www.cnblogs.com/biglucky/p/6349862.html
Copyright © 2011-2022 走看看