[ create a new paste ] login | about

Link: http://codepad.org/biVZol0j    [ raw code | output | fork ]

C, pasted on Dec 29:
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
typedef struct _test
{
    int a;
    pthread_mutex_t mutex;
    pthread_cond_t cond;
} test;
test mytest= {0,PTHREAD_MUTEX_INITIALIZER,PTHREAD_COND_INITIALIZER};
void *proc(void *ptr)
{

    pthread_detach(pthread_self());
    pthread_mutex_lock(&mytest.mutex);
    while(mytest.a!=5)
    {
        pthread_cond_wait(&mytest.cond,&mytest.mutex);
    }
    printf("%d\n",mytest.a);
    pthread_mutex_unlock(&mytest.mutex);
    return NULL;
}
int main()
{
    pthread_t id;
    pthread_create(&id,NULL,proc,NULL);
    sleep(1);
    while(mytest.a!=10)
    {
        pthread_mutex_lock(&mytest.mutex);
        mytest.a++;
        pthread_cond_signal(&mytest.cond);
        pthread_mutex_unlock(&mytest.mutex);
    }
    return 0;
}


Output:
1
2
3
4
In function `main':
undefined reference to `pthread_create'
In function `proc':
undefined reference to `pthread_detach'


Create a new paste based on this one


Comments: