Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / December 2006

Tip: Looking for answers? Try searching our database.

why link to DB2 'libdb2' library cause the semaphore misbehavior?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cranfic - 14 Dec 2006 16:16 GMT
Please help...

To make it simple, I have a simple test C program which calls my
semphore library functions only.  (It doesn't call any db2 function at
all).  And the following is the test program:

#include    "hasem.h"
#include    <semaphore.h>
#include     <stdio.h>

int
main(int argc, char **argv)
{
    haSem    hasem;
    int    val;

    if (argc != 2)
    {
        printf("usage: semgetvalue <name>\n");
        exit(1);
    }

    strcpy(hasem.semName, argv[1]);
    //Creating binary semaphore
    //if (!semCreate(&hasem))
    //Creating counting semaphore
    if (!semCreateCounting(&hasem,1))
    {
       printf("Failed to create semaphore\n");
    }
    if (!semGetValue(&hasem, &val))
    {
       printf("Failed to get semaphore value.(try 1)\n");
    }
    else
    {
       printf("value = %d(try 1)\n", val);
    }
    /****************/
    if (!semWait(&hasem))       // sem_wait() wrapper function
    {
       printf("Failed to secure semaphore.\n");
    }
    if (!semGetValue(&hasem, &val))
    {
       printf("Failed to get semaphore value.(try 2)\n");
    }
    else
    {
       printf("value = %d(try 2)\n", val);
    }

    /****************/
    if (!semPost(&hasem))     //sem_post() wrapper function
    {
       printf("Failed to post semaphore.\n");
    }
    if (!semGetValue(&hasem, &val))
    {
       printf("Failed to get semaphore value.(try 3)\n");
    }
    else
    {
       printf("value = %d(try 3)\n", val);
    }

    if (!semDestroy(&hasem))
    {
       printf("Failed to unlink semDestroy().\n");
    }

    exit(0);
}

Without link to libdb2 the result is:
(gcc -g -O2 -D_REENTRANT -Wall -D__EXTENSIONS__ -I ~qq/rxgui/inc  -c -o
hursemgetvalue.o hursemgetvalue.c
gcc -g -O2 -D_REENTRANT -Wall -D__EXTENSIONS__ -o hursemgetvalue
hursemgetvalue.o ~qq/rxgui/S*/obj/libhasem.a -lrt -lposix4 )

value = 1(try 1)
value = 0(try 2)
value = 1(try 3)

But if I link to libdb2 as well, the executable runs with incorrect
behavior.  And the following is the printf output:
(gcc -g -Wall -I ~qq/rxgui/inc  -c -o hursemgetvalue.o hursemgetvalue.c

gcc -o hursemgetvalue hursemgetvalue.o ~qq/rxgui/S*/obj/libhasem.a
-lrt -lposix4 -R/export/home/db2eee1a/sqllib/lib -ldb2)

value = 0(try 1)
value = 0(try 2)
value = 0(try 3)

As you can see, the semaphore value is always 0 and doesn't perform
locking function as well.  I don't know if it's a DB2 bug or me making
a mistake somewhere.  Any help or direction is greatly appreciated.
The DB2 SDK version is 7.2.9 on Solaris 8 and I am using gcc compiler.
Knut Stolze - 18 Dec 2006 16:47 GMT
> Please help...
>
[quoted text clipped - 95 lines]
> a mistake somewhere.  Any help or direction is greatly appreciated.
> The DB2 SDK version is 7.2.9 on Solaris 8 and I am using gcc compiler.

First question: any chance on moving to a supported DB2 version like V8 or,
better yet, V9.

What would also be interesting to know are the definitions of your various
sem* functions.  The POSIX semaphore functions are not mixed case, e.g.
sem_destroy and not semDestroy.

And finally, what's the output of the linkage editor?

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.