linux - 在 Linux 2.4 上使用 pthread - 出现 "incomplete type"编译错误

标签 linux pthreads incomplete-type

我正在研究 Linux 2.4(为我的操作系统类(class)做硬件), 我想使用pthread来实现读写锁。 在 rw_lock.c 中我有:

#include <pthread.h>
#include <stdlib.h>
#include "rw_lock.h"

struct readers_writers_t
{
    int prio;
    int number_of_readers;
    pthread_cond_t no_readers;
    int number_of_writers;
    int number_of_waiting_writers;
    pthread_cond_t no_writers;
    pthread_mutex_t lock;
};

[functions...]

在 rw_lock.h 中我有:

typedef struct readers_writers_t readers_writers;

在另一个 C 文件(链表的实现)中,我有:

#include "rw_lock.h"

struct LinkedList
{
    ListNode* head;
    ListNode* tail;
    readers_writers rwLock;
};

(and more functions,includes etc').

我得到(一个)编译错误:

"rwLock has incomplete type".

我不知道为什么会出现此错误(或如何修复它......)。

感谢帮助,谢谢!

最佳答案

您需要将结构定义从源文件移动到头文件。

rw_lock.h 应该是:

#ifndef  SOME_UNIQUE_STRING_MY_RW_LOCK_H
#define  SOME_UNIQUE_STRING_MY_RW_LOCK_H

#include <pthread.h>

struct readers_writers_t
{
    int prio;
    int number_of_readers;
    pthread_cond_t no_readers;
    int number_of_writers;
    int number_of_waiting_writers;
    pthread_cond_t no_writers;
    pthread_mutex_t lock;
};
typedef struct readers_writers_t readers_writers;

#endif

关于linux - 在 Linux 2.4 上使用 pthread - 出现 "incomplete type"编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6011528/

相关文章:

linux - 如何获取 UDP 套接字的排队数据量?

linux - 我们需要测试混合的 windows-Linux 环境。是否有同时支持两者的自动化工具?

linux - ltrace()如何显示rand()

C 线程 (pthread_create) 未按预期工作

c++ - pthread 与 NSThread : which is faster

c - ps 中的僵尸线程(对于用 c 编写的线程程序)

python - 在 for 循环中更改脚本执行后

c - stat.h 文件访问文件描述符 open() 黑客利用的艺术

c++ - 不完整类型的 std::unique_ptr 无法编译

c++ - 具有类型删除析构函数的 unique_ptr 不太有效(有警告)