semaphore problems

semaphore problems

Post by Andre′ Kemp » Fri, 06 Jul 2001 20:25:52

I have encountered a strange problem with semaphores.

I'm trying to synchronize several writer-processes which write to a
therefore they are able to lock their write-procedure via a binary
semaphore. the problem
is when one of the servers terminates, the oncetime binary-semaphore
gets incremented to something
greater then 1.

I've tried to change the sem_flg flag of the sembuf structure, with no

Any hints????




int Writer::Run()throw(SemaphoreError){

        int i;
        pid_t pid = getpid();
        semun arg;

        struct sembuf sop_acquire,              //sembuf-struct zur
Dekrementierung der Semaphore
                      sop_release;              //sembuf-struct zur
Inkrementierung der Semaphore

        semun semun_arg;
        //Initialisierung der sembuf-struktur sop_acquire
        sop_acquire.sem_num = WAS;
        sop_acquire.sem_op = -1;
        sop_acquire.sem_flg = SEM_UNDO;

        sop_release.sem_num = WAS;
        sop_release.sem_op = 1;
        sop_release.sem_op = SEM_UNDO;

        while (1){

#ifdef _DEBUG
                cout << "Before Acquiring: " <<
semctl(semid,WAS,GETVAL,arg) << endl << flush;
                        throw SemaphoreError();
#ifdef _DEBUG
                cout << "Locked State    : " <<
semctl(semid,WAS,GETVAL,arg) << endl << flush;

//BEGIN kritischer Abschnitt

                (*db) = i = (rand()%20);

                cout << pid << ": Just wrote " << (*db) << " into
                cout << "Reader_Semaphore : " <<
semctl(semid,RES,GETVAL,semun_arg) << " Writer-Semaphore : " <<
semctl(semid,WRS,GETVAL,semun_arg) << endl;

//ENDE kritischer Abschnitt

                        throw SemaphoreError();
#ifdef _DEBUG
                cout << "After Release   : "
<<semctl(semid,WAS,GETVAL,arg) << endl << flush;

        return (1);



1. Solaris 2.4 semaphore problem?

Has anyone had problems with Solaris semaphores? I am using
an application that uses them, and eventually I have to reboot
the machine due to the get-semaphore routine failing.  It looks
like the application _is_ freeing the semaphores it obtains properly.

Another strange thing is that when the application fails we use
ipcs to delete all semaphores.  This seems to have no effect,  
the semaphore_get routines still fail.


Software Technology, Inc. (STI)      | Space flight/ground software   ^^ .
DC office: (703) 329-9707            | vxWorks BSPs, etc.              .  

2. Toggling the RTS line of a modem

3. linux semaphore problems

4. attempted TCP outbound SMTP port 25 when go to web site

5. Semaphores problem

6. emacs-nox in color??

7. Peculiar semaphore problem on Solaris ..

8. DNS ugly problem!

9. POSIX semaphore problem

10. semaphore problems

11. semaphore problem

12. Semaphore problem w/ Postgresql operating in a jail on FREEBSD

13. Solaris DDI semaphore problems