473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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.

Dec 14 '06 #1
1 2247
cranfic wrote:
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.
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?

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Dec 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bastian Hammer | last post by:
Hi I´m wondering why there are so few examples with Semaphore. Is it obsolete? I´ve got a Class Data. It offers 2 Threads methods for updating, editing, .. a private dictionary. Now I...
0
by: dede | last post by:
Dear community, having written a working example for using Semphores on a windows client, I created a little "server-application" that does the following: A Server continously "listens/tails"...
1
by: rushik | last post by:
Hello all, I m facing an interesting problem related to semaphore in php. We are using a huge business application running on LAMP. For database operations we are maintaining centralized DB...
2
by: Vandana Sharma | last post by:
Hi, I am trying to run my application (32-bit) on HP-UX 11.22i (64-bit) and am getting the above message while dynamically loading libdb2.so from my application. I am using dlopen as follows: ...
2
by: techi_C | last post by:
Hi I'm getting a problem while removing semaphore from system. Before removing semaphore I'm checking the usage count of a smaphore. // checking usage count usage_count =...
0
by: Samuel R. Neff | last post by:
I'm having trouble creating a Semaphore with read-access rights for everyone. Originally I was trying to use this code: semaphore = new Semaphore(maxLocks, maxLocks, "RwLock#" + name); but...
0
by: Justin | last post by:
When creating an executible received this error during the linking... g++32 -L/usr/lib/x86_64-redhat-linux3E/lib64 -o confusion cdb.o conindb.o confusdb.o confusion.o ../../arc/lib/arc.a...
1
by: Ajb181 | last post by:
hi all. i have a template class that i can not link. there is no problem when i add the method def's inside the header file but as soon as i move them out i get a link error where i define the...
2
by: noashira | last post by:
Hi All, I'll be happy to get your opinionn this, i have a webservice that uses Semaphore to access shared (VB) resources and i noticed that the semaphore could not make locks using the WaitOne()...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.