未检测到多线程库

时间:2012-10-18 19:53:54

标签: c windows multithreading mingw posix

这是一个简单的代码,我在eclipse中学习Windows 7操作系统上的多线程编程。

pthread_mutex_t double_release_001_glb_mutex_;
pthread_mutex_t * double_release_001_glb_mutex = & double_release_001_glb_mutex_;

void double_release_001_glb_mutex_lock () {}
void double_release_001_glb_mutex_unlock () {}

int double_release_001_glb_data = 0;

void * double_release_001_tsk_001 (void * pram)
{

    pthread_mutex_lock (double_release_001_glb_mutex);
    double_release_001_glb_data = (double_release_001_glb_data% 100) + 1;

    pthread_mutex_unlock (double_release_001_glb_mutex);
    return NULL;
}

void double_release_001 ()
{
    pthread_t tid1;
    pthread_mutex_init (double_release_001_glb_mutex, NULL);
    pthread_create (& tid1, NULL, double_release_001_tsk_001, NULL);
    pthread_join (tid1, NULL);
    pthread_mutex_destroy (double_release_001_glb_mutex);
}

void double_release_001_tskentry_001 ()
{
    while (1)
    {
        if (rand ())
        {
            double_release_001_tsk_001 (NULL);
        }
    }
}

但是当我构建它时,我得到一个错误说

Description Resource    Path    Location    Type
undefined reference to `_imp__pthread_create'   
undefined reference to `_imp__pthread_create'       
undefined reference to `_imp__pthread_create'   
undefined reference to `_imp__pthread_create'

我已加入pthread.h。有人可以帮助我。

1 个答案:

答案 0 :(得分:0)

将此选项添加到链接器:-lpthread