MultiThread in Solaris 10

Hi -
Has anybody have problems with multithread applications in Solaris10? I have a multithreaded application which was earlier compiled in Solaris 8 with Forte and works fine. The same was compiled successfully, however I did not include any of the recommended flags, but on execution gets a signal from sched. Any ideas as to why sched should keep sending SIGALRM signal to this process? The thread is calling recvfrom() socket call. Is there something wrong with the socket?The programme was complied with just -lpthread . Help will greatly be appreciated. Thanks in advance.

Hi -
Found the problem. From Solaris 10 onwards, signal policy for threads have changed. Now signal set by a thread is deliviered to the process instead of a thread. That means all the threads created by the process will inherit the signal. Now signal handling must be done in the thread with masking of signals not needed in a thread.
Regards

Similar Messages

  • Multithreading in solaris 8

    Hi,
    Below is the multithreaded code for reading and writing a file. Multithreading is implemented to achieve performance when compared to sequential read and write.
    The pthread API is used for multithreading.
    This experiment is carried out on Solaris 8 OS. 4 CPU machine.
    The sample program shown below.
    #include <stdio.h>
    #include <string.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <time.h>
    #include <stdlib.h>
    #include <pthread.h>
    #define MAX_BUF_SIZE 128
    int ReadFile(int fd, char **buf);
    int WriteFile(int fd, int noOfFd, char buf, int len);
    void fun(void arg);
    struct Node
    char *buf;
    int fd;
    int len;
    int flag;
    struct Node DataArr[2][1000];
    int main()
    int readFd;
    int writeFd[2];
    char *buffer = NULL;
    int i;
    int len;
    time_t vTi;
    struct tm startTime, endTime;
    int index = 0;
    pthread_t tid[2];
    pthread_attr_t atrid[2];
    time(&vTi);
    startTime = localtime(&vTi);
    printf(" start time : %02d-%02d-%02d:%02d-%02d-%02d\n", startTime->tm_mon+1, startTime->tm_mday, startTime->tm_year+1900, startTime->tm_hour, startTime->tm_min, startTime->tm_sec);
    if ((readFd = open("Ascii1.cc.com", O_RDONLY)) < 0)
    perror("open failed");
    exit(1);
    for (i = 0; i< 2; i++)
    char filename[128];
    int *iptr = NULL;
    iptr = (int *)malloc(sizeof(int));
    *iptr = i;
    sprintf(filename,"%s%d","Output",i+1);
    if ((writeFd[i] = creat(filename, 0644)) < 0)
    perror("create failed");
    exit(1);
    if (pthread_attr_init(&atrid) < 0)
    perror("attribut init failed");
    exit(1);
    if (pthread_attr_setscope(&atrid[i], PTHREAD_SCOPE_SYSTEM) < 0)
    perror("attribute setscope failed");
    exit(1);
    if (pthread_create(&tid[i], &atrid[i], fun, (void *)iptr) < 0)
    perror("thread create failed");
    exit(1);
    memset(&DataArr[i], 0, 1000*sizeof(struct Node));
    do
    len = ReadFile(readFd, &buffer);
    for (i = 0; i < 2; i++)
    while (DataArr[i][index].flag != 0);
    if (len > 0)
    DataArr[i][index].buf = (char *)malloc(len);
    DataArr[i][index].buf = buffer;
    DataArr[i][index].fd = writeFd[i];
    DataArr[i][index].len = len;
    DataArr[i][index].flag = 1;
    index++;
    if (index == 1000)
    index = 0;
    if (len > 0)
    free(buffer);
    else if (len == 0)
    printf("End of file\n");
    for (i = 0; i < 2;i++)
    pthread_attr_destroy(&atrid[i]);
    pthread_join(tid[i], NULL);
    break;
    } while (1);
    close(readFd);
    for (i = 0; i< 2; i++)
    close(writeFd[i]);
    time(&vTi);
    endTime = localtime(&vTi);
    printf(" end time : %02d-%02d-%02d:%02d-%02d-%02d\n", endTime->tm_mon+1, endTime->tm_mday, endTime->tm_year+1900, endTime->tm_hour, endTime->tm_min, endTime->tm_sec);
    return 0;
    int ReadFile(int fd, char **buf)
    char buffer[MAX_BUF_SIZE];
    int len;
    if ((len = read(fd, buffer, MAX_BUF_SIZE)) < 0)
    perror("read failed");
    return -1;
    buffer[len] = '\0';
    if (len != 0)
    buf = (char)malloc(len*sizeof(char));
    strcpy(*buf,buffer);
    return len;
    int WriteFile(int fd, int noOfFd, char buf, int len)
    int i;
    for (i = 0; i < noOfFd; i++)
    if (write(fd[i], buf, len) < 0)
    perror("write failed");
    return -1;
    return 0;
    void fun(void arg)
    int applno;
    char *buffer = NULL;
    int fd;
    int len;
    int count = 0;
    applno = *((int *)arg);
    free((int*)arg);
    while (1)
    while(DataArr[applno][count].flag != 1);
    buffer = DataArr[applno][count].buf;
    fd = DataArr[applno][count].fd;
    len = DataArr[applno][count].len;
    DataArr[applno][count].flag = 0;
    count++;
    if (count == 1000)
    count = 0;
    if (len > 0)
    WriteFile(&fd, 1, buffer, len);
    free(buffer);
    else if(len == 0)
    break;
    return NULL;
    The query is according to truss report below. The report shows following system calls which are called frequently. Why and when these calls occur and can we reduce these number of calls. If yes, how? Cuz these calls take a significant amount of time.
    lwp_sema_wait .02 933
    lwp_sema_post .19 933
    lwp_mutex_wakeup .05 1071
    lwp_mutex_lock .07 1490
    Truss output with command truss -a pid
    syscall seconds calls errors
    _exit                    .00       1
    read 3.35 19220
    write 1.63 38441
    open .00 7 1
    close .00 11
    creat .01 2
    time .00 2
    brk .28 1129
    stat .00 9 4
    getpid .00 1
    ioctl .00 1
    execve .00 1
    sigprocmask .00 4
    sigaction .00 4
    sigfillset .00 1
    getcontext .00 1
    mmap .00 22
    mprotect .00 11
    munmap .00 5
    getrlimit .00 1
    memcntl .00 3
    sysconfig .00 3
    lwp_sema_wait .02 933
    lwp_sema_post .19 933
    lwp_create .00 12
    lwp_exit .00 2
    lwp_continue .00 5
    lwp_self .00 5
    lwp_mutex_wakeup .05 1071
    lwp_mutex_lock .07 1490
    lwp_cond_wait .00 6
    lwp_cond_signal .00 5
    llseek .00 1
    door_create .00 1
    door_info .00 1
    door_return .00 1
    door_bind .00 2
    lwp_schedctl .00 8
    resolvepath .00 1
    signotifywait .00 1
    lwp_sigredirect .00 1
    sys totals: 5.60 63359 5
    usr time: 2.60
    elapsed: 8.42

    Hi All,
    Iam expecting some reply for this query. I know the query is little big, but please spare some of your precious time to reply for this.
    Thanks in advance.

  • Process killed by SIGALRM randomly

    Hi,
    We have been observing a strange thing happening to our server processes (multithreaded) on Solaris 5.7. After running the servers for a while, they will be killed by "Alarm Clock". We are never explicitly using alarm in our code. So, the only thing that we can think of is the implementation of sleep because we do use sleep indirectly.
    According to the POSIX standard, sleep can be implemented using alarm. The default action to SIGALRM is terminating the process. It seems to be the case now. So if sleep is implemented using alarm, is it possible that the signal handler that sleep registers somehow got lost and the default action is used? Could it be related to multithreaded applications with signals?
    I appreciate any relevant information.
    Thanks in advance,
    Miranda

    Hi,
    We are using version 7 Solaris. And I believe we are having the latest thread patch and kernel. Please correct me if I am wrong. Our kernel ID is Generic_106541-14. The patch we have for libthread is 106980-15.
    We are not using usleep and we are using nanosleep. That's why we are suspecting that it's the implementation of some OS functions using alarm that causes this problem. Since the POSIX standard indicates that sleep can be implemented using alarm. Besides, I found another piece of information from the alarm(2) man page:
    Calling alarm() in a multithreaded process linked with
    -lthread (Solaris threads) and not with -lpthread (POSIX
    threads) currently behaves in the following fashion:
    o if the calling thread is a bound thread, the resulting
    SIGALRM is delivered to the bound thread's LWP, i.e.
    to the calling thread. There is a bug currently that
    this signal is not maskable via thr_sigsetmask(3T) on
    this bound thread.
    o if the calling thread is an unbound thread, the
    resulting SIGALRM is sent to the LWP on which the
    thread was running when it issued the call to alarm().
    This is neither a per-process semantic, nor a per-
    thread semantic, since the LWP could change threads
    after the call to alarm() but before the SIGALRM
    delivery, causing some other thread to get it possi-
    bly. Hence this is basically a bug.
    Our programs currently do not link with -lpthread, they only have -mt. And I believe we are using unbound threads. So according to the man page, there is a bug if sleep is implemented using alarm and SIGALRM is being sent to the wrong thread!? Does linking with -lpthread help? Should I get rid of the -mt?
    FYI, the output of the program when it is being killed is:
    <My program's output>
    Alarm Clock
    You can get the output above very easily by sending SIGALRM to any process which does not catch SIGALRM.
    Thanks,
    Miranda

  • Multithreading issue on Solaris 8 branded zone

    Hi,
    We are facing a multithreading problem in Solaris 8 container (branded zone) on Solaris 10.
    The core file shows 2 LWPs for a single thread.
    First LWP
    (dbx) lwp
    current LWP ($lwp) is l@1403
    (dbx) print this->m_ThreadId->m_IdImpl.m_PosixId
    this->m_ThreadId.m_IdImpl.m_PosixId = 1404U
    Second LWP
    (dbx) lwp
    current LWP ($lwp) is l@1404
    (dbx) print this->m_ThreadId->m_IdImpl.m_PosixId
    this->m_ThreadId.m_IdImpl.m_PosixId = 1404U
    Another point to note is that dbx returns 'MT support is disabled' for this program even though it has been built using the -mt option. The dbx version is Sun Dbx Debugger 7.5 2005/10/13.
    As far as I have read, the Solaris 8 branded zone uses the alternate T2 thread library. Note also that this program is linked with the alternate thread library @ /usr/lib/lwp.
    This alternate thread library is supposed to use the 1:1 thread model.
    Can someone explain why are we then seeing 2 LWPs for a single thread ?
    Thanks,
    Best regards,
    Raj Iyer

    This error messages are output by
    cssd which is a input method of Japanese.
    If you don't use Japanese input method cs00, you can stop it by following method.
    # /etc/init.d/loc.ja.cssd stop
    # mv /etc/rc2.d/S90loc.ja.cssd /etc/rc2.d/_S90loc.ja.cssd

  • Solaris 6 binary on Solaris 8 ( Multithreaded application.)

    I have to explore further, but I like to know whether any of you have faced similar problem.
    We have multithreaded server. A thread in detached mode will be created to serve each new connection. The binary was compiled on 32bit solaris environment and it was running fine on solaris 6 machines.
    Recently we switched to Solaris 8 machines. We used the same binary that was compiled on solaris 6. One problem I am noticing is some of the threads are idle and are alive for 3-4 days. We have timeouts enforced between successive transactions, inspite of that threads are alive for longer duration. We use "poll".
    Do you see any problem in Solaris 8 w.r.t Poll/Select syscall or Detached threads ( we use POSIX APIs) that were compiled on Solaris 6 ?.
    I would also like to give anyother information that would help you in identifying the problem.
    Thanks
    Mega

    we have ported our product to solaris 5.7 from solaris5.6. With this version we are unable to install the product on solaris 5.6. It is unable to find the following libraries in 5.6, while installing and finally it is failing.
    libMrm.so.4
    libXm.so.4
    libgen.so.3
    Is there any way to make my product work on both versions of solaris?

  • How to Debug C++ Multithreaded Application in Solaris

    Hi All,
    I am working in Solaris Sparc 5.8 Machine. I need to debug Multithreaded C++ Application in Unix Environment.
    I am using dbx debugger.
    Please explain me how to debug multithreaded applications. if possible please explain me with example.
    Thanks in Advance.
    Thanks & Regards,
    Vasu

    1. Look over the dbx manual that comes with Sun Studio. Dbx includes many features for debugging MT code.
    2. If you have specific questions after reading the manual and trying out the features, ask them in the debugger forum:
    http://forum.sun.com/forum.jspa?forumID=257

  • Migrating to Solaris 9 - C++ Multithreaded X.25 application turning undead

    We have an older multithreaded C++ X.25 application that's been running without a problem for years (24x7). We upgraded the sun server from Solaris 8 to 9 and now, occasionally, the application stops working, but doesn't stop running. X.25 continues at a lower level - interrupts and RRs go back and forth, but the application level doesn't respond. The application's trace log simply stops and no errors are generated. The application has to be killed and restarted. Then after a while, it does it again about once or twice a week, I believe.
    The people who do support have looked at it, and can't find anything, so I've been asked to look into it.
    But it's on a production server on a customer site, so I don't actually have access to the server. All I can do is make changes to the application and have it installed on their server to run again.
    I looked at the changes from Solaris 8 to 9 and the only one that seemed like it could have an impact is the changes to the multithreading implementation. I did come across a hint that there was a change somehow to interrupts and the last trace log messages was printed during a sigalrm interrupt. But that's not as likely because the change seemed to refer more to whether interrupts were considered idle time or not.
    This application doesn't actually need to be multithreaded - the guy who wrote it 9 years ago was new to C++ and mutlithreading (had just taken a course) and got a bit carried away. It's a bit of a convoluted monster and everyone hates to touch it - which is why I (Ms. contractor) get it :-) One option is to remove the threads, but this application is in a lot of sites and the company is reluctant right now to let me make such a drastic change. It mike be required though, because they are planning to upgrade other customers to Solaris 9 and they don't want to face this problem with the busier customers.
    Has anyone come across any problems with threading moving to Solaris 9? Or does anyone have any suggestion for any debugging that I can add to the applicaton itself to help clear up the mystery?
    Any help or advice is appreciated,
    Stefani

    You replacement for operator new violates the requirements of the C++ standard, and a program using it has undefined behavior. The program could fail to compile, fail to link, fail in unknown ways at run time, or (by accident) do what you want it to do.
    You can write your own "placement new" operator that has any exception behavior that you want. But if you replace the library version of operator new, you must follow exactly the requirements listed in the C++ standard, sections 3.7.3 "Dynamic storage duration", and 18.4 "Dynamic memory management".
    I can't reproduce all the text here, but in particular a replacement operator new must have the signature
    void* operator new(std::size_t) throw(std::bad_alloc); // single-object form
    void* operator new(std::size_t) throw(std::bad_alloc); // array form

  • Multithreaded Programming on Solaris

    Hi,
    I'd like to ask a question regarding multithreaded programming using C/C++ on Solaris. I wanna write a program that can fork a child process to execute a command line call. How can the parent process terminate the child process if the child process cannot complete in a reasonable amount of time? Any help would be greatly appreciated. Thank you.

    Set an alarm timer in the parent process. Waitid for the child to complete.
    - If the child completes, cancel the timer with alarm(0).
    - If the timer pops, issue a kill -15/9 to the child process, then waitid to clean up the zombie. You can check for EINTR returned from your waitid and kill the child then if you don't want to do it in the interrupt handler.
    Dave

  • Solaris vs Linux For Multithreaded Application

    Hi all,
    I am having a Multithreaded Java application which is used to monitor devices in a network (NMS). After collecting the data from the devices, this will update the data in the database. (Usualy there will be lot of device around 25000) . There will be lot of database updation. I am planning to run this application in a server.
    But now I am confused in selecting which platform (which os) I have to use. There are two options for me. Either to use Linux or Solaris.
    Can anyone help me in selecting the platform. Since my application is multithreaded , please tell me which of these OS will give the best performance
    Thanks in advance

    There's no way to tell which one performs better without testing it. Both have reasonably mature and stable multitasking and multi threading. Why don't you write the application and try it on both platforms?

  • Multithreaded Programming in Solaris

    Hi,
    I'd like to ask a question regarding multithreaded programming using C/C++ on Solaris. I wanna write a program that can fork a child process to execute a command line call. How can the parent process terminate the child process if the child process cannot complete in a reasonable amount of time? Any help would be greatly appreciated. Thank you.

    more multiprocess than multithreaded..
    use fork1() to get a new process, but the parent gets the pid of the child as the return of fork1().
    The parent needs to then wait()/waitpid() for the child to exit so it can reap the status and not leave zombies around.
    Prior to blocking in wait/waitpid you can use alarm() to get a signal delivered after n seconds. That will interrupt the wait/waitpid, whose return code and errno can be checked to see if the wait was interrupted. If it was interrupted you can kill the child with kill() if not the alarm can be cancelled with alarm(0).
    Whilst you wait/waitpig the child process can then exec() the program you want it to run or the child could call system()
    For advanced usage you can get the child to put itself into a new process group so that kill can get the child and all its children..
    tim

  • Signals in Multithreaded Application on Solaris 10.

    HI All,
    I need to know are the signal handlers are inherited by threads.
    Assume I have defined a signal handler (assume for SIGCHLD )in main function before the creation of threads, and after that I create 5 threads. Can anyone please tell me if the signal SIGCHLD comes to any of the 5 threads will it be handled as signal handler defined earlier.
    Any comments will be appreciated.
    Regards,
    Rahul.

    What do you mean by 'linux application'? Right now, you'd have to recompile the program from source on Solaris or install a precompiled Solaris package.
    After the release of project Janus, you might have some other choices to run Linux binaries directly on a Solaris (x86) machine.
    Darren

  • Multithreaded behavior of new Solaris 8 /dev/poll

    When one thread is blocked in the ioctl for the /dev/poll device
    (to retrieve the fd's with events), a write from a different thread
    to add to the set appears to block indefinitely.
    I figured this ability (to add to the set from a different thread
    with no mutexing) was a great feature, but it looks like the
    write call blocks indefinitely. Before I invest in the unfortunate
    workaround, I wondered if anyone had dealt with this before.
    Thanks.

    I have not yet extracted a simple program, but the basics are:
    Thread one:
    fd1 = open()
    fd2 = open()
    fdp = open("/dev/poll"..)
    ioctl(fdp, DP_POLL, ...)
    Thread two (later):
    write(fdp, {struct with fd1, and POLLIN});
    ... much successful operation of the first thread receiving
    events from the ioctl, and properly "dispatching" them
    write(fdp, {struct fd1, and POLLREMOVE);
    It is this second write that hangs indefinitely.
    The only way I get it to NOT hang is by giving the
    ioctl(DP_POLL) in the first thread a timeout.
    When the ioctl returns due to timeout, the second thread that was hung in
    "write", finally returns.
    (my email is [email protected])
    Thanks for any ideas or help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Limitation on LD_LIBRARY_PATH on Solaris box

    Hi All,
    I am using Tuxedo v8.0 on Solaris 2.8 box. This tuxedo server guides other servers to start up after issuing "tmboot -y" command. Following error I can see if the LD_LIBRARY_PATH is too long.
    <i>"CMDTUX_CAT:819: INFO: Process id=1281 Assume started (pipe)."</i>
    Is there any limitation that LD_LIBRARY_PATH should not me more than some pre defined characters?
    Thanks in advance.
    -Pijush

    As Wayne points out, there are some temporary variables of size 2048 used to
    manipulate LD_LIBRARY_PATH in tmsyncproc(), the function where the problem
    is occurring. A long value of LD_LIBRARY_PATH can overwrite the values in
    these temporary variables. If you keep LD_LIBRARY_PATH shorter than this,
    you should be fine.
    <Pijush Koley> wrote in message news:[email protected]...
    Thanks for the reply.<p>
    You are right. I received one core file at $APPDIR. But the strange thingis I got the core from the "tmboot" binary. Here is the back trace which I
    received when LD_LIBRARY_PATH is too long. <p>
    >
    ===========================================
    user1@TNUTF8 /proj1/appdir>file core <br>
    core: ELF 64-bit MSB core file SPARCV9 Version 1, from'tmboot'<br>
    >
    user1@TNUTF8 /proj1/appdir>dbx /proj1/3p/tuxedo8.0/bin/tmboot core <br>
    Reading tmboot <br>
    core file header read successfully <br>
    Reading ld.so.1 <br>
    Reading libm.so.1 <br>
    Reading libgpnet.so.71 <br>
    Reading libtux.so.71 <br>
    Reading libbuft.so.71 <br>
    Reading libfml.so.71 <br>
    Reading libfml32.so.71 <br>
    Reading libengine.so.71 <br>
    Reading libpthread.so.1 <br>
    Reading librt.so.1 <br>
    Reading libsocket.so.1 <br>
    Reading libnsl.so.1 <br>
    Reading libthread.so.1 <br>
    Reading libc.so.1 <br>
    Reading libaio.so.1 <br>
    Reading libdl.so.1 <br>
    Reading libmp.so.2 <br>
    Reading libc_psr.so.1 <br>
    Reading en_US.ISO8859-1.so.2 <br>
    Reading registry.so <br>
    detected a multithreaded program <br>
    t@1 (l@1) terminated by signal SEGV (no mapping at the fault address) <br>
    0x0000000100006430: __do_misaligned_ldst_instr+0x01d4: ldx [%g4 +0x8], %o0 <br>
    dbx: warning: invalid frame pointer <br>
    (/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) where <br>
    current thread: t@1 <br>
    =>[1] __do_misaligned_ldst_instr(0xffffffff7fff4f90, 0xffffffff7fff5050,0xd25c2000, 0x2f33702f726f7365, 0x1, 0xb), at 0x100006430 <br>
    [2] __misalign_trap_handler(0x7474652f6c69623a, 0xffffffff7fffe20c, 0x0,0x100598020, 0x0, 0x100126c40), at 0x100007680 <br>
    [3] tmsyncproc(0xffffffff7ecacea0, 0x100136f58, 0xffffffff7fff6bd8,0x0, 0x1, 0xffffffff7fff6bc0), at
    0xffffffff7eb2e0d4 <br>
    (/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) exit <br>
    ================================ <p>
    But I did not receive any error when LD_LIBRARY_PATH is not too long. <br>
    Any pointers?<p>
    Thanks in advance. <br>
    -Pijush

  • Pro*c multithreaded application has memory leak

    Hi there,
    I posted this message a week ago in OCI section, nobody answer me.
    I am really curious if my application has a bug or the pro*c has a bug.
    Anyone can compile the sample code and test it easily.
    I made multithreaded application which queries dynamic SQL, it works.
    But the memory leaks when i query the SQL statement.
    The more memory leaks, the more i query the SQL statement, even same SQL
    statement.
    I check it with top, shell command.
    My machine is SUN E450, Solaris 8. Oracle 9.2.0.1
    Compiler : gcc (GCC) 3.2.2
    I changed source code which is from
    $(ORACLE_HOME)/precomp/demo/proc/sample10.pc
    the sample10 doesn't need to be multithreaded. But i think it has to work
    correctly if i changed it to multithreaded application.
    the make file and source code will be placed below.
    I have to figure out the problem.
    Please help
    Thanks in advance,
    the make file is below
    HOME = /user/jkku
    ORA = $(ORACLE_HOME)
    CC = gcc
    PROC = proc
    LC_INCL = -I$(HOME)/work/dbmss/libs/include
    lc_incl = include=$(HOME)/work/dbmss/libs/include
    SYS_INCL =
    sys_incl =
    ORA_INCL = -I. \
    -I$(ORA)/precomp/public \
    -I$(ORA)/rdbms/public \
    -I$(ORA)/rdbms/demo \
    -I$(ORA)/rdbms/pbsql/public \
    -I$(ORA)/network/public \
    -DSLMXMX_ENABLE -DSLTS_ENABLE -D_SVID_GETTOD
    INCLUDES = $(LC_INCL) $(SYS_INCL) $(ORA_INCL)
    includes = $(lc_incl) $(sys_incl)
    LC_LIBS =
    SYS_LIBS = -lpthread -lsocket -lnsl -lrt
    ORA_LIBS = -L$(ORA)/lib/ -lclntsh
    LIBS = $(LC_LIBS) $(SYS_LIBS) $(ORA_LIBS)
    # Define C Compiler flags
    CFLAGS += -D_Solaris64_ -m64
    CFLAGS += -g -D_REENTRANT
    # Define pro*c Compiler flags
    PROCFLAGS += THREADS=YES
    PROCFLAGS += CPOOL=YES
    # Our object files
    PRECOMPS = sample10.c
    OBJS = sample10.o
    .SUFFIXES: .o .c .pc
    .c.o:
    $(CC) -c $(CFLAGS) $(INCLUDES) $*.c
    .pc.c:
    $(PROC) $(PROCFLAGS) $(includes) $*.pc $*.c
    all: sample10
    sample10: $(PRECOMPS) $(OBJS)
    $(CC) $(CFLAGS) -o sample10 $(OBJS) $(LIBS)
    clean:
    rm -rf *.o sample10 sample10.c
    the source code is below which i changed the oracle sample10.pc to
    multithreaded application.
    Sample Program 10: Dynamic SQL Method 4
    This program connects you to ORACLE using your username and
    password, then prompts you for a SQL statement. You can enter
    any legal SQL statement. Use regular SQL syntax, not embedded SQL.
    Your statement will be processed. If it is a query, the rows
    fetched are displayed.
    You can enter multi-line statements. The limit is 1023 characters.
    This sample program only processes up to MAX_ITEMS bind variables and
    MAX_ITEMS select-list items. MAX_ITEMS is #defined to be 40.
    #include <stdio.h>
    #include <string.h>
    #include <setjmp.h>
    #include <sqlda.h>
    #include <stdlib.h>
    #include <sqlcpr.h>
    /* Maximum number of select-list items or bind variables. */
    #define MAX_ITEMS 40
    /* Maximum lengths of the names of the
    select-list items or indicator variables. */
    #define MAX_VNAME_LEN 30
    #define MAX_INAME_LEN 30
    #ifndef NULL
    #define NULL 0
    #endif
    /* Prototypes */
    #if defined(__STDC__)
    void sql_error(void);
    int oracle_connect(void);
    int alloc_descriptors(int, int, int);
    int get_dyn_statement(void);
    void set_bind_variables(void);
    void process_select_list(void);
    void help(void);
    #else
    void sql_error(/*_ void _*/);
    int oracle_connect(/*_ void _*/);
    int alloc_descriptors(/*_ int, int, int _*/);
    int get_dyn_statement(/* void _*/);
    void set_bind_variables(/*_ void -*/);
    void process_select_list(/*_ void _*/);
    void help(/*_ void _*/);
    #endif
    char *dml_commands[] = {"SELECT", "select", "INSERT", "insert",
    "UPDATE", "update", "DELETE", "delete"};
    EXEC SQL INCLUDE sqlda;
    EXEC SQL INCLUDE sqlca;
    EXEC SQL BEGIN DECLARE SECTION;
    char dyn_statement[1024];
    EXEC SQL VAR dyn_statement IS STRING(1024);
    EXEC SQL END DECLARE SECTION;
    EXEC ORACLE OPTION (ORACA=YES);
    EXEC ORACLE OPTION (RELEASE_CURSOR=YES);
    SQLDA *bind_dp;
    SQLDA *select_dp;
    /* Define a buffer to hold longjmp state info. */
    jmp_buf jmp_continue;
    char *db_uid="dbmuser/dbmuser@dbmdb";
    sql_context ctx;
    int err_sql;
    enum{
    SQL_SUCC=0,
    SQL_ERR,
    SQL_NOTFOUND,
    SQL_UNIQUE,
    SQL_DISCONNECT,
    SQL_NOTNULL
    int main()
    int i;
    EXEC SQL ENABLE THREADS;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL WHENEVER NOT FOUND DO sql_not_found();
    /* Connect to the database. */
    if (connect_database() < 0)
    exit(1);
    EXEC SQL CONTEXT USE :ctx;
    /* Process SQL statements. */
    for (;;)
    /* Allocate memory for the select and bind descriptors. */
    if (alloc_descriptors(MAX_ITEMS, MAX_VNAME_LEN, NAME_LEN) != 0)
    exit(1);
    (void) setjmp(jmp_continue);
    /* Get the statement. Break on "exit". */
    if (get_dyn_statement() != 0)
    break;
    EXEC SQL PREPARE S FROM :dyn_statement;
    EXEC SQL DECLARE C CURSOR FOR S;
    /* Set the bind variables for any placeholders in the
    SQL statement. */
    set_bind_variables();
    /* Open the cursor and execute the statement.
    * If the statement is not a query (SELECT), the
    * statement processing is completed after the
    * OPEN.
    EXEC SQL OPEN C USING DESCRIPTOR bind_dp;
    /* Call the function that processes the select-list.
    * If the statement is not a query, this function
    * just returns, doing nothing.
    process_select_list();
    /* Tell user how many rows processed. */
    for (i = 0; i < 8; i++)
    if (strncmp(dyn_statement, dml_commands, 6) == 0)
    printf("\n\n%d row%c processed.\n", sqlca.sqlerrd[2], sqlca.sqlerrd[2] == 1 ? '\0' : 's');
    break;
    /* Close the cursor. */
    EXEC SQL CLOSE C;
    /* When done, free the memory allocated for pointers in the bind and
    select descriptors. */
    for (i = 0; i < MAX_ITEMS; i++)
    if (bind_dp->V != (char *) 0)
    free(bind_dp->V);
    free(bind_dp->I); /* MAX_ITEMS were allocated. */
    if (select_dp->V != (char *) 0)
    free(select_dp->V);
    free(select_dp->I); /* MAX_ITEMS were allocated. */
    /* Free space used by the descriptors themselves. */
    SQLSQLDAFree(ctx, bind_dp);
    SQLSQLDAFree(ctx, select_dp);
    } /* end of for(;;) statement-processing loop */
    disconnect_database();
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    EXEC SQL COMMIT WORK RELEASE;
    puts("\nHave a good day!\n");
    return;
    * Allocate the BIND and SELECT descriptors using sqlald().
    * Also allocate the pointers to indicator variables
    * in each descriptor. The pointers to the actual bind
    * variables and the select-list items are realloc'ed in
    * the set_bind_variables() or process_select_list()
    * routines. This routine allocates 1 byte for select_dp->V
    * and bind_dp->V, so the realloc will work correctly.
    alloc_descriptors(size, max_vname_len, max_iname_len)
    int size;
    int max_vname_len;
    int max_iname_len;
    int i;
    * The first sqlald parameter determines the maximum number of
    * array elements in each variable in the descriptor. In
    * other words, it determines the maximum number of bind
    * variables or select-list items in the SQL statement.
    * The second parameter determines the maximum length of
    * strings used to hold the names of select-list items
    * or placeholders. The maximum length of column
    * names in ORACLE is 30, but you can allocate more or less
    * as needed.
    * The third parameter determines the maximum length of
    * strings used to hold the names of any indicator
    * variables. To follow ORACLE standards, the maximum
    * length of these should be 30. But, you can allocate
    * more or less as needed.
    if ((bind_dp =
    SQLSQLDAAlloc(ctx, size, max_vname_len, max_iname_len)) ==
    (SQLDA *) 0)
    fprintf(stderr,
    "Cannot allocate memory for bind descriptor.");
    return -1; /* Have to exit in this case. */
    if ((select_dp =
    SQLSQLDAAlloc(ctx, size, max_vname_len, max_iname_len)) == (SQLDA *)
    0)
    fprintf(stderr,
    "Cannot allocate memory for select descriptor.");
    return -1;
    select_dp->N = MAX_ITEMS;
    /* Allocate the pointers to the indicator variables, and the
    actual data. */
    for (i = 0; i < MAX_ITEMS; i++) {
    bind_dp->I = (short *) malloc(sizeof (short));
    select_dp->I = (short *) malloc(sizeof(short));
    bind_dp->V = (char *) malloc(1);
    select_dp->V = (char *) malloc(1);
    return 0;
    int get_dyn_statement()
    char *cp, linebuf[256];
    int iter, plsql;
    for (plsql = 0, iter = 1; ;)
    if (iter == 1)
    printf("\nSQL> ");
    dyn_statement[0] = '\0';
    fgets(linebuf, sizeof linebuf, stdin);
    cp = strrchr(linebuf, '\n');
    if (cp && cp != linebuf)
    *cp = ' ';
    else if (cp == linebuf)
    continue;
    if ((strncmp(linebuf, "EXIT", 4) == 0) ||
    (strncmp(linebuf, "exit", 4) == 0))
    return -1;
    else if (linebuf[0] == '?' ||
    (strncmp(linebuf, "HELP", 4) == 0) ||
    (strncmp(linebuf, "help", 4) == 0))
    help();
    iter = 1;
    continue;
    if (strstr(linebuf, "BEGIN") ||
    (strstr(linebuf, "begin")))
    plsql = 1;
    strcat(dyn_statement, linebuf);
    if ((plsql && (cp = strrchr(dyn_statement, '/'))) ||
    (!plsql && (cp = strrchr(dyn_statement, ';'))))
    *cp = '\0';
    break;
    else
    iter++;
    printf("%3d ", iter);
    return 0;
    void set_bind_variables()
    int i, n;
    char bind_var[64];
    /* Describe any bind variables (input host variables) */
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    bind_dp->N = MAX_ITEMS; /* Initialize count of array elements. */
    EXEC SQL DESCRIBE BIND VARIABLES FOR S INTO bind_dp;
    /* If F is negative, there were more bind variables
    than originally allocated by sqlald(). */
    if (bind_dp->F < 0)
    printf ("\nToo many bind variables (%d), maximum is %d\n.",
    -bind_dp->F, MAX_ITEMS);
    return;
    /* Set the maximum number of array elements in the
    descriptor to the number found. */
    bind_dp->N = bind_dp->F;
    /* Get the value of each bind variable as a
    * character string.
    * C contains the length of the bind variable
    * name used in the SQL statement.
    * S contains the actual name of the bind variable
    * used in the SQL statement.
    * L will contain the length of the data value
    * entered.
    * V will contain the address of the data value
    * entered.
    * T is always set to 1 because in this sample program
    * data values for all bind variables are entered
    * as character strings.
    * ORACLE converts to the table value from CHAR.
    * I will point to the indicator value, which is
    * set to -1 when the bind variable value is "null".
    for (i = 0; i < bind_dp->F; i++)
    printf ("\nEnter value for bind variable %.*s: ",
    (int)bind_dp->C, bind_dp->S);
    fgets(bind_var, sizeof bind_var, stdin);
    /* Get length and remove the new line character. */
    n = strlen(bind_var) - 1;
    /* Set it in the descriptor. */
    bind_dp->L = n;
    /* (re-)allocate the buffer for the value.
    sqlald() reserves a pointer location for
    V but does not allocate the full space for
    the pointer. */
    bind_dp->V = (char *) realloc(bind_dp->V, (bind_dp->L + 1));
    /* And copy it in. */
    strncpy(bind_dp->V, bind_var, n);
    /* Set the indicator variable's value. */
    if ((strncmp(bind_dp->V, "NULL", 4) == 0) ||
    (strncmp(bind_dp->V, "null", 4) == 0))
    *bind_dp->I = -1;
    else
    *bind_dp->I = 0;
    /* Set the bind datatype to 1 for CHAR. */
    bind_dp->T = 1;
    return;
    void process_select_list()
    int i, null_ok, precision, scale;
    if ((strncmp(dyn_statement, "SELECT", 6) != 0) &&
    (strncmp(dyn_statement, "select", 6) != 0))
    select_dp->F = 0;
    return;
    /* If the SQL statement is a SELECT, describe the
    select-list items. The DESCRIBE function returns
    their names, datatypes, lengths (including precision
    and scale), and NULL/NOT NULL statuses. */
    select_dp->N = MAX_ITEMS;
    EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;
    /* If F is negative, there were more select-list
    items than originally allocated by sqlald(). */
    if (select_dp->F < 0)
    printf ("\nToo many select-list items (%d), maximum is %d\n",
    -(select_dp->F), MAX_ITEMS);
    return;
    /* Set the maximum number of array elements in the
    descriptor to the number found. */
    select_dp->N = select_dp->F;
    /* Allocate storage for each select-list item.
    sqlprc() is used to extract precision and scale
    from the length (select_dp->L).
    sqlnul() is used to reset the high-order bit of
    the datatype and to check whether the column
    is NOT NULL.
    CHAR datatypes have length, but zero precision and
    scale. The length is defined at CREATE time.
    NUMBER datatypes have precision and scale only if
    defined at CREATE time. If the column
    definition was just NUMBER, the precision
    and scale are zero, and you must allocate
    the required maximum length.
    DATE datatypes return a length of 7 if the default
    format is used. This should be increased to
    9 to store the actual date character string.
    If you use the TO_CHAR function, the maximum
    length could be 75, but will probably be less
    (you can see the effects of this in SQL*Plus).
    ROWID datatype always returns a fixed length of 18 if
    coerced to CHAR.
    LONG and
    LONG RAW datatypes return a length of 0 (zero),
    so you need to set a maximum. In this example,
    it is 240 characters.
    printf ("\n");
    for (i = 0; i < select_dp->F; i++)
    char title[MAX_VNAME_LEN];
    /* Turn off high-order bit of datatype (in this example,
    it does not matter if the column is NOT NULL). */
    sqlnul ((unsigned short *)&(select_dp->T), (unsigned short
    *)&(select_dp->T), &null_ok);
    switch (select_dp->T)
    case 1 : /* CHAR datatype: no change in length
    needed, except possibly for TO_CHAR
    conversions (not handled here). */
    break;
    case 2 : /* NUMBER datatype: use sqlprc() to
    extract precision and scale. */
    sqlprc ((unsigned int *)&(select_dp->L), &precision,
    &scale);
    /* Allow for maximum size of NUMBER. */
    if (precision == 0) precision = 40;
    /* Also allow for decimal point and
    possible sign. */
    /* convert NUMBER datatype to FLOAT if scale > 0,
    INT otherwise. */
    if (scale > 0)
    select_dp->L = sizeof(float);
    else
    select_dp->L = sizeof(int);
    break;
    case 8 : /* LONG datatype */
    select_dp->L = 240;
    break;
    case 11 : /* ROWID datatype */
    case 104 : /* Universal ROWID datatype */
    select_dp->L = 18;
    break;
    case 12 : /* DATE datatype */
    select_dp->L = 9;
    break;
    case 23 : /* RAW datatype */
    break;
    case 24 : /* LONG RAW datatype */
    select_dp->L = 240;
    break;
    /* Allocate space for the select-list data values.
    sqlald() reserves a pointer location for
    V but does not allocate the full space for
    the pointer. */
    if (select_dp->T != 2)
    select_dp->V = (char *) realloc(select_dp->V,
    select_dp->L + 1);
    else
    select_dp->V = (char *) realloc(select_dp->V,
    select_dp->L);
    /* Print column headings, right-justifying number
    column headings. */
    /* Copy to temporary buffer in case name is null-terminated */
    memset(title, ' ', MAX_VNAME_LEN);
    strncpy(title, select_dp->S, select_dp->C);
    if (select_dp->T == 2)
    if (scale > 0)
    printf ("%.*s ", select_dp->L+3, title);
    else
    printf ("%.*s ", select_dp->L, title);
    else
    printf("%-.*s ", select_dp->L, title);
    /* Coerce ALL datatypes except for LONG RAW and NUMBER to
    character. */
    if (select_dp->T != 24 && select_dp->T != 2)
    select_dp->T = 1;
    /* Coerce the datatypes of NUMBERs to float or int depending on
    the scale. */
    if (select_dp->T == 2)
    if (scale > 0)
    select_dp->T = 4; /* float */
    else
    select_dp->T = 3; /* int */
    printf ("\n\n");
    /* FETCH each row selected and print the column values. */
    EXEC SQL WHENEVER NOT FOUND GOTO end_select_loop;
    for (;;)
    EXEC SQL FETCH C USING DESCRIPTOR select_dp;
    /* Since each variable returned has been coerced to a
    character string, int, or float very little processing
    is required here. This routine just prints out the
    values on the terminal. */
    for (i = 0; i < select_dp->F; i++)
    if (*select_dp->I < 0)
    if (select_dp->T == 4)
    printf ("%-*c ",(int)select_dp->L+3, ' ');
    else
    printf ("%-*c ",(int)select_dp->L, ' ');
    else
    if (select_dp->T == 3) /* int datatype */
    printf ("%*d ", (int)select_dp->L,
    *(int *)select_dp->V);
    else if (select_dp->T == 4) /* float datatype */
    printf ("%*.2f ", (int)select_dp->L,
    *(float *)select_dp->V);
    else /* character string */
    printf ("%-*.*s ", (int)select_dp->L,
    (int)select_dp->L, select_dp->V);
    printf ("\n");
    end_select_loop:
    return;
    void help()
    puts("\n\nEnter a SQL statement or a PL/SQL block at the SQL> prompt.");
    puts("Statements can be continued over several lines, except");
    puts("within string literals.");
    puts("Terminate a SQL statement with a semicolon.");
    puts("Terminate a PL/SQL block (which can contain embedded
    semicolons)");
    puts("with a slash (/).");
    puts("Typing \"exit\" (no semicolon needed) exits the program.");
    puts("You typed \"?\" or \"help\" to get this message.\n\n");
    int connect_database()
    err_sql = SQL_SUCC;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL WHENEVER NOT FOUND DO sql_not_found();
    EXEC SQL CONTEXT ALLOCATE :ctx;
    EXEC SQL CONTEXT USE :ctx;
    EXEC SQL CONNECT :db_uid;
    if(err_sql != SQL_SUCC){
    printf("err => connect database(ctx:%ld, uid:%s) failed!\n", ctx, db_uid);
    return -1;
    return 1;
    int disconnect_database()
    err_sql = SQL_SUCC;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL WHENEVER NOT FOUND DO sql_not_found();
    EXEC SQL CONTEXT USE :ctx;
    EXEC SQL COMMIT WORK RELEASE;
    EXEC SQL CONTEXT FREE:ctx;
    return 1;
    void sql_error()
    printf("err => %.*s", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
    printf("in \"%.*s...\'\n", oraca.orastxt.orastxtl, oraca.orastxt.orastxtc);
    printf("on line %d of %.*s.\n\n", oraca.oraslnr, oraca.orasfnm.orasfnml,
    oraca.orasfnm.orasfnmc);
    switch(sqlca.sqlcode) {
    case -1: /* unique constraint violated */
    err_sql = SQL_UNIQUE;
    break;
    case -1012: /* not logged on */
    case -1089:
    case -3133:
    case -1041:
    case -3114:
    case -3113:
    /* �6�Ŭ�� shutdown�ǰų� �α��� ���°� �ƴҶ� ��b�� �õ� */
    /* immediate shutdown in progress - no operations are permitted */
    /* end-of-file on communication channel */
    /* internal error. hostdef extension doesn't exist */
    err_sql = SQL_DISCONNECT;
    break;
    case -1400:
    err_sql = SQL_NOTNULL;
    break;
    default:
    err_sql = SQL_ERR;
    break;
    EXEC SQL CONTEXT USE :ctx;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    EXEC SQL ROLLBACK WORK;
    void sql_not_found()
    err_sql = SQL_NOTFOUND;

    Hi Jane,
    What version of Berkeley DB XML are you using?
    What is your operating system and your hardware platform?
    For how long have been the application running?
    What is your current container size?
    What's set for EnvironmentConfig.setThreaded?
    Do you know if containers have previously not been closed correctly?
    Can you please post the entire error output?
    What's the JDK version, 1.4 or 1.5?
    Thanks,
    Bogdan

  • App crash when using JAVA callbacks from native threads in solaris

    Hi all,
    Sorry for putting the thread here. I did use the native methods forum, I wasnt lucky. I Hope more people would look into this forum, which brings me here.
    I have a solaris application which crashes when I try to callback the JAVA methods and variables from the native code. The description of the problem is below
    Written a native library, the library is multithreaded (i.e) I create a thread using pthread_create() in the native code which performs the operation of calling a JAVA method from the native code. The routine of calling the JAVA method works perfectly elsewhere outside the new thread.
    There are two scenarios I've tested it in
    1. I created a thread (say X) from the main thread (say Y) and made the y to wait until the X is complete using the pthread_join(). The JAVA callbacks works fine when called from Y but the app crashes if done from X.
    2. Did not make the Y to wait until the X is complete, hoping that both will run paralelly and even the the App crashes.
    And to be precise the Y is the thread where the native method is called from JAVA.
    I have tested for any memory leaks or stack corruption by removing the JAVA callbacks and bulding a executable and using purify, the report doesnot hint any such occurances.
    The linker options used for building the shared library is as follows
    ${GPP} ${INC} -G ${LIB} -mt -g -lCstd -lCrun -lpthread ${OBJS} -o <lib-name>
    I wonder if we can create threads in the native code when using JAVA callbacks and even if we can whether it would be appropiate to use the callbacks with in the threads
    Looking forward for any help.
    Regards,
    Vamsi

    Guys... can't any one help me with this problem :(

Maybe you are looking for

  • Do i need an apple tv base for every tv in my home

    Do I need an apple tv base and a computer for each tv in my home.  If not, how can I watch netflix, etc in another room.  Thanks  sgarbo

  • Lookup in another list when filtering in a view

    Hello, I need help with a public view for a list. This is my filter now: <View Name="{F9165834-6860-4EB5-A7FE-D96CE334DF70}" Type="HTML" DisplayName="My group - not assigned" Url="/sites/RomaniaL1SD/Lists/Opened tickets/My group not assigned.aspx" Le

  • Creating arrow navigation with a photo gallery

    I am in the process of creating my own phtoography website. I created all the pages in Photoshop, sliced them and am now using dreamweaver to add interactivity. The class I took showed us how to make remote rollover images with small thumbnails that

  • Will my new desktop for christmas run starcraft 2?

    heres my new desktop im getting: http://www.bestbuy.com/site/Gateway+-+Desktop+/+AMD+A-Series+Processor+/+4GB+Memory+/+1TB+Hard+Drive... will it be able to run starcraft 2 on atleast low? Solved! Go to Solution.

  • Re: Cancel Skype Number subscription (or at least ...

    I have the same problem and as a busy doctor in a developing country with slow internet this experience has wasted so much valuable time I could have used productively. I will move to Viber if this is not resoved quickly. dickybeach