POSIX thread-safe application on Solaris 2.6
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Licensing & Editions, Platform-Specific Issues
Hi, I wrote a client program that connect to Informix database using POSIX thread-safe library in SDK 2.40 on Solaris 2.6. I have no problems when compiling the code, but, got an error "Illegal Instruction (coredump)" when the program is run. The following is the details that I gathered from gdb. ------------------------------------------------------------------------ Details from gdb ------------------------------------------------------------------------ misssa$ gdb ./th-query GNU gdb 4.18 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "sparc-sun-solaris2.6"... (gdb) break main Breakpoint 1 at 0x1247c: file th-query.ec, line 51. (gdb) run Starting program: /informix/home/tphuttas/radx/new-acct/./th-query [New LWP 2 ] [New LWP 3 ] Breakpoint 1, main (argc=1, argv=0xeffffabc) at th-query.ec:51 51 EXEC SQL prepare stm1 from 'select log_username, log_ropw from userlogin where log_username = ? '; (gdb) info thread 6 Thread 3 0xef3e7c14 in _swtch () from /usr/lib/libthread.so.1 5 Thread 2 (LWP 2) 0xef3397e8 in _signotifywait () from /usr/lib/libc.so.1 * 4 Thread 1 (LWP 1) main (argc=1, argv=0xeffffabc) at th-query.ec:51 3 LWP 3 0xef3368b4 in door_restart () from /usr/lib/libc.so.1 2 LWP 2 0xef3397e8 in _signotifywait () from /usr/lib/libc.so.1 1 LWP 1 main (argc=1, argv=0xeffffabc) at th-query.ec:51 (gdb) n [New LWP 4 ] 52 EXEC SQL declare cur1 cursor for stm1; (gdb) info thread 7 LWP 4 0xef339654 in ___lwp_cond_wait () from /usr/lib/libc.so.1 6 Thread 3 0xef3e7c14 in _swtch () from /usr/lib/libthread.so.1 5 Thread 2 (LWP 2) 0xef3397e8 in _signotifywait () from /usr/lib/libc.so.1 * 4 Thread 1 (LWP 1) main (argc=1, argv=0xeffffabc) at th-query.ec:52 3 LWP 3 0xef3368b4 in door_restart () from /usr/lib/libc.so.1 2 LWP 2 0xef3397e8 in _signotifywait () from /usr/lib/libc.so.1 1 LWP 1 main (argc=1, argv=0xeffffabc) at th-query.ec:52 (gdb) n Program received signal SIGILL, Illegal instruction. 0x22f8c in uname () (gdb) where #0 0x22f8c in uname () #1 0xef62c80c in rhostname () from /export/home/tphuttas/informix/lib/esql/libthos.so #2 0xef6ea934 in getPInfo () from /export/home/tphuttas/informix/lib/libthasf.so #3 0xef6e8a34 in cmInit () from /export/home/tphuttas/informix/lib/libthasf.so #4 0xef6de884 in asfInit () from /export/home/tphuttas/informix/lib/libthasf.so #5 0xef6e0f98 in ASF_Call () from /export/home/tphuttas/informix/lib/libthasf.so #6 0xef7411e4 in asf_init () from /export/home/tphuttas/informix/lib/esql/libthsql.so #7 0xef742580 in sqli_connect_open_tcb () from /export/home/tphuttas/informix/lib/esql/libthsql.so #8 0xef7423ec in sqli_connect_open () from /export/home/tphuttas/informix/lib/esql/libthsql.so #9 0x124e4 in main (argc=1, argv=0xeffffabc) at th-query.ec:52 (gdb) list 52 47 pthread_t thread1, thread2; 48 char msg1[100] = "test\\0" , msg2[100]; 49 50 EXEC SQL connect to 'mydb@ifxserver' as 'conn1' user 'thods' using :pw ; 51 EXEC SQL prepare stm1 from 'select log_username, log_ropw from userlogin where log_username = ? '; 52 EXEC SQL declare cur1 cursor for stm1; 53 EXEC SQL set connection 'conn1' dormant; 54 pthread_mutex_init(&mutex, (pthread_mutexattr_t *) NULL); 55 i = pthread_create(&thread1, (pthread_attr_t *) NULL, (void *(*) (void *))query, (void *)msg1); 56 (gdb) quit ------------------------------------------------------------------------ The source code is: ------------------------------------------------------------------------ #include <stdio.h> #include <string.h> #include <pthread.h> pthread_mutex_t mutex; EXEC SQL include sqlda; EXEC SQL include sqltypes; EXEC SQL include /export/home/tphuttas/informix/demo/esqlc/exp_chk.ec; #define WARNNOTIFY 1 #define NOWARNNOTIFY 0 EXEC SQL BEGIN DECLARE SECTION; string uname[100]; string username[100], ropw[100]; string pw[10] = "thepasswd\\0"; EXEC SQL END DECLARE SECTION; void query(void *ptr) { char *u; u = (char *) ptr; pthread_mutex_lock(&mutex); stcopy(u, uname); EXEC SQL set connection 'conn1'; EXEC SQL open cur1 using :uname ; for (;;) { EXEC SQL fetch cur1 into :username, :ropw; if(strncmp(SQLSTATE, "00", 2) != 0) { break; } fprintf(stdout, "%s:%s\\n", username, ropw); } fflush(stdout); EXEC SQL set connection 'conn1' dormant; pthread_mutex_unlock(&mutex); pthread_exit(0); } int main(int argc, char *argv[]) { int i; pthread_t thread1, thread2; char msg1[100] = "test\\0" , msg2[100]; EXEC SQL connect to 'mydb@ifxserver' as 'conn1' user 'thods' using :pw ; EXEC SQL prepare stm1 from 'select log_username, log_ropw from userlogin where log_username = ? '; EXEC SQL declare cur1 cursor for stm1; EXEC SQL set connection 'conn1' dormant; pthread_mutex_init(&mutex, (pthread_mutexattr_t *) NULL); i = pthread_create(&thread1, (pthread_attr_t *) NULL, (void * (*) (void *))query, (void *)msg1); sleep(30); EXEC SQL disconnect all; exit(0); } ------------------------------------------------------------------------ Did I missed something? Any help is appreciated. Best regards, Thodsaporn Phuttasupa Shin Satellite Plc. E-mail: thodsaporn@cscoms.net Sent via Deja.com http://www.deja.com/ Before you buy.