This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB 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]

Multithreading failing in Mandrake 10.1


Hi all!




I'm having some proble trying to debug a multithreaded app in my


Mandrake 10.1 box. I have GNU gdb 6.2-2mdk (Mandrakelinux)

gcc
version 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk) and kernel 2.6.9.




I've appended a little test to show the bahaviour I'm having problems.

You can compile it with:

g++ -Wall -D_THREAD_SAFE -DREENTRANT -lpthread -ggdb test_gdb.cpp


This program works correctly in a console but under gdb i always

get n error in the sem_wait function with the next errno:


Cannot sem_wait(&SEM_2). Interrupted system call



Program exited with code 01




Thanks for your time,
Jorge



----- test_gdb.cpp -----8<------------------------------------------------





#include <stdio.h>

#include <unistd.h>

#include <stdlib.h>

#include <errno.h>

#include <pthread.h>

#include <semaphore.h>

#include <string.h>

#include <time.h>





sem_t SEM_2;

sem_t SEM_1;





void *ThreadCreate1(void *arg)

{

   time_t t;



   printf("<Thread1> -> Sleep for 2 seconds before sem_post(&SEM_1)\n");



   sleep(2);

   time(&t);

   printf("<Thread1> -> thread sem_post(&SEM_1) now: %s\n",ctime(&t));

   if(sem_post(&SEM_1) != 0)

   {

       printf("Cannot sem_post. %s\n", strerror(errno));

       exit(1);

   }



   return NULL;

}





void *ThreadCreate2(void *arg)

{

   time_t t;



   printf("<Thread2> -> Sleep for 4 seconds before sem_post(&SEM_2)\n");



   sleep(4);

   time(&t);

   printf("<Thread2> -> thread sem_post(&SEM_2) now: %s\n",ctime(&t));

   if(sem_post(&SEM_2) != 0)

   {

       printf("Cannot sem_post. %s\n", strerror(errno));

       exit(1);

   }



   return NULL;

}







int main()

{

   pthread_t m_Thread1,m_Thread2;

   time_t t;

   int value = 0xFFFF;



   if(sem_init(&SEM_1,0,0) != 0)

   {

       printf("Cannot sem_init(&SEM_1,0,0). %s\n", strerror(errno));

       exit(1);

   }



   if(sem_init(&SEM_2,0,0) != 0)

   {

       printf("Cannot sem_init(&SEM_2,0,0). %s\n", strerror(errno));

       exit(1);

   }



   time(&t);

   printf("Now: %s\n",ctime(&t));



   if ( pthread_create(&m_Thread1, NULL, ThreadCreate1, NULL) != 0)

   {

       printf("Cannot create thread. %s\n", strerror(errno));

       exit(1);

   }



   if ( pthread_create(&m_Thread2, NULL, ThreadCreate2, NULL) != 0)

   {

       printf("Cannot create thread. %s\n", strerror(errno));

       exit(1);

   }



   printf("\n\n");





   //----------------------------------------------------------------------

   printf("<Main> -> Wait 2 seconds for sem_post on SEM1\n");

   if(sem_getvalue(&SEM_1,&value) != 0)

   {

       printf("Cannot sem_getvalue. %s\n", strerror(errno));

       exit(1);

   }

   printf("<Main> -> Main sem_getvalue SEM1 is %d\n",value);



   if(sem_wait(&SEM_1) != 0)

   {

       printf("Cannot sem_wait(&SEM_1). %s\n", strerror(errno));

       exit(1);

   }



   time(&t);

   printf("<Main> -> sem_post on SEM1: %s\n\n",ctime(&t));





   //----------------------------------------------------------------------

   printf("<Main> -> Wait 2 seconds for sem_post on SEM2\n");

   if(sem_getvalue(&SEM_2,&value) != 0)

   {

       printf("Cannot sem_getvalue. %s\n", strerror(errno));

       exit(1);

   }

   printf("<Main> -> sem_getvalue SEM2 is %d\n",value);



   if(sem_trywait(&SEM_2) == 0)

   {

       printf("SEM_2 Cannot be posted yet. \n");

       exit(1);

   }



   if(sem_wait(&SEM_2) != 0)

   {

       printf("Cannot sem_wait(&SEM_2). %s\n", strerror(errno));

       exit(1);

   }

   time(&t);

   printf("<Main> -> sem_post on SEM2: %s\n\n",ctime(&t));





   return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]