1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
   |  
sem_t *sema_login = NULL;
sem_t *sema_exit = NULL;
const char *sem_name_login = "loggeur.login";
const char *sem_name_exit = "abcdefgh";
 
bool quitte = true;
 
void* threadLogin(void *p_tsoap)
{
cout << "la thread login est lance \n";
        for(;;)
        {
                sem_wait(sema_login);
cout << "la thread login est relache \n";
         }
}
void* threadExit(void *p_tsoap)
{
        int rtc = 0;
        printf("in exit thread sema_exit ptr %p\n",sema_exit);
        printf("sem_wait rtc %d\n",(rtc=sem_wait(sema_exit)));
        if(errno == EINTR)
        { 
          printf("retry wait\n");
          sem_wait(sema_exit);
        }
        printf("sem_wait finished\n");
        quitte =false;
}
///////////////////////////////////////////////////////////////////////////////////////////////
//
//
//
//
int main(int argc,char *argv[]){
 
        //Creation  semaphore
        //
std::cout << "init semaphore : " << sem_name_login << "\n";
        int     oflag = O_CREAT ;
        sema_login = sem_open(sem_name_login, oflag, 0660, 0);
        sema_exit = sem_open(sem_name_exit, oflag, 0660, 0);
        printf("sem_exit ptr %p\n",sema_exit);
        if(sema_exit == SEM_FAILED)
        {
                cout << "error in exit semaphore initialization " << errno << "\n";
        }
cout << "fin init des semaphore" << endl;
 
        struct soap v_soap;
        struct soap *v_tsoap;
        pthread_t thread1, thread2;
        pthread_t thread3;
 
        //lancement de la thread qui arrete le programme
        pthread_create(&thread3 , NULL , threadExit, (void*)v_tsoap);
        int rtc = pthread_detach(thread3);
 
         pthread_create(&thread2 , NULL , threadLogin , (void*)v_tsoap );
        rtc = pthread_detach(thread2);
 
        soap_end(&v_soap);
 
        while(1)
                usleep(20);
        return(0);} | 
Partager