By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

Mysql Multithreded program getting sagmentation fault

P: 1
I am writing a "C" program using Embedded Mysql that uses two threads performing the following operations in an infinite loop:
- Thread 1 inserts 500 records to the database every 30 seconds and then goes to sleep. (I prepare an insert statement using mysql_stmt_init() and mysql_stmt_prepare(), bind values using mysql_stmt_bind_param(), execute the statement using mysql_stmt_execute() ).
- Thread 2 makes one of 10 pre-defined queries to the database every 5 seconds (using mysql_query() and mysql_store_result) and then goes to sleep.

This runs ok for some time, but then I get a segmentation fault. What could be the problem?

In gdb back trace i am getting -----------------
Expand|Select|Wrap|Line Numbers
  1. #0 0x42073fe0 in _int_free () from /lib/i686/libc.so.6
  2. #1 0x42074a2c in free () from /lib/i686/libc.so.6
  3. #2 0x080efd02 in emb_advanced_command ()
  4. #3 0x080f0224 in emb_stmt_execute ()
  5. #4 0x080ead4c in mysql_stmt_execute ()
  6. #5 0x080e592b in hlpd_Insert(st_mysql*) (MysqlConn=0x84946e0) at hlpd_insert.cpp:147
  7. #6 0x080e534d in main (argc=1, argv=0xbffffa34) at hlpd_benchmark_main.cpp:136
  8. #7 0x420158d4 in __libc_start_main () from /lib/i686/libc.so.6

The same Mysql database connection is used in both the threads.
In first thread i am using
Expand|Select|Wrap|Line Numbers
  1. {
  2.  mysql_server_init()
  3.  MysqlConn = mysql_init( NULL );
  4.  mysql_options(  );
  5.  mysql_options( );
  6.  mysql_real_connect(   );
  7.  
  8.     .
  9.     .
  10.     .
  11.  mysql_close(  );
  12.  mysql_thread_end();
  13.  mysql_server_end();
  14. }
The second thread i am using
Expand|Select|Wrap|Line Numbers
  1. {
  2.  mysql_thread_init();
  3.     .
  4.     .
  5.     .
  6.  mysql_thread_end();
  7. }

Thanks in advance for your help.
Anindya
Nov 3 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.