This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pthread & its bug


-----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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]