pthread & its bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear all,

I'm newbie in multithread programming.I'm practicing that.Now i have
written following code :

My code :

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int g1=0;
int g2=0;
void task1(int *counter);
void task2(int *counter);
int main(int argc,char *argv[])
{
    pthread_t *thr1,*thr2;
    int ret;

    if ((ret = pthread_create(&thr1,NULL,(void *)task1,(void *)&g1)))
    {
        perror("pthread_create : task1");
        exit(EXIT_FAILURE);
    }

    if ((ret = pthread_create(&thr2,NULL,(void *)task2,(void *)&g2)))
    {
        perror("pthread_create : task2");
        exit(EXIT_FAILURE);
    }


    pthread_join(thr2,NULL);
    pthread_join(thr1,NULL);

    cleanup(g1,g2);
    exit(EXIT_SUCCESS);
}//end of main program
void task1(int *counter)
{
    while(*counter < 5 ){
        printf("task1 count: %d\n",*counter);
        (*counter)++;
    }//end of while
}//end of task1 function

void task2(int *counter)
{
    while(*counter < 5 ){
        printf("task2 count: %d\n",*counter);
        (*counter)++;
    }//end of while
}//end of task1 function
void cleanup(int counter1,int counter2)
{
    printf("Total iterations: %d\n",counter1+counter2);
}//end of cleanup function
///////////////////////////END OF
CODE////////////////////////////////////////////////////////

Now when i compile it, I receive following errors:

mohsen@debian:~/test/learning/pthread$ make
gcc -c  test.c
In file included from test.c:3:
/usr/include/pthread.h:285: error: conflicting types for ‘pthread_t’
/usr/include/bits/pthreadtypes.h:152: error: previous declaration of
‘pthread_t’ was here
/usr/include/pthread.h:286: error: conflicting types for ‘pthread_attr_t’
/usr/include/bits/pthreadtypes.h:54: error: previous declaration of
‘pthread_attr_t’ was here
/usr/include/pthread.h:287: error: conflicting types for ‘pthread_key_t’
/usr/include/bits/pthreadtypes.h:82: error: previous declaration of
‘pthread_key_t’ was here
/usr/include/pthread.h:289: error: conflicting types for
‘pthread_mutexattr_t’
/usr/include/bits/pthreadtypes.h:102: error: previous declaration of
‘pthread_mutexattr_t’ was here
/usr/include/pthread.h:290: error: conflicting types for ‘pthread_mutex_t’
/usr/include/bits/pthreadtypes.h:95: error: previous declaration of
‘pthread_mutex_t’ was here
/usr/include/pthread.h:291: error: conflicting types for
‘pthread_condattr_t’
/usr/include/bits/pthreadtypes.h:79: error: previous declaration of
‘pthread_condattr_t’ was here
/usr/include/pthread.h:292: error: conflicting types for ‘pthread_cond_t’
/usr/include/bits/pthreadtypes.h:72: error: previous declaration of
‘pthread_cond_t’ was here
test.c: In function ‘main’:
test.c:13: warning: passing argument 1 of ‘pthread_create’ from
incompatible pointer type
test.c:19: warning: passing argument 1 of ‘pthread_create’ from
incompatible pointer type
test.c:26: warning: passing argument 1 of ‘pthread_join’ from
incompatible pointer type
test.c:27: warning: passing argument 1 of ‘pthread_join’ from
incompatible pointer type
test.c: At top level:
test.c:48: warning: conflicting types for ‘cleanup’
test.c:29: warning: previous implicit declaration of ‘cleanup’ was here
make: *** [main.o] Error 1
mohsen@debian:~/test/learning/pthread$

//////////////////////////////////////


I have retrieved libdir & includedir with pthread_config command.

Please help me .....

Yours,Mohsen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGBG2a/ZBAvBh9bHIRArwvAJ429vihIW7mqsNq4U76vrzCHi7zcwCbBpC3
O07y29P5zpUjfirZOV1vbBk=
=5N0e
-----END PGP SIGNATURE-----

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux