List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:May 11 1999 4:54pm
Subject:Re: Threaded applications using mysql
View as plain text  
>>>>> "Sasha" == Sasha Pachev <sasha@stripped> writes:

<cut>

>> Hi!
>> 
>> You can use a global handle as long as you ensure that no other thread
>> calls access the handle until you have called mysql_store_result().
>> 
>> Regards,
>> Monty
>> 

Sasha> So does than mean that you can do something like this:

Sasha> MYSQL dbh;
Sasha> mysql_connect(&dbh, "localhost", "scott", "tiger");
Sasha> scream_if_error(&dbh);
Sasha> mysql_select_db("test");

Sasha> switch(fork())
Sasha>  {
Sasha>    case -1: scream_bloody_murder_and_die("Cannot fork");
Sasha>    case 0: mysql_query(&dbh, "insert into test values
Sasha> (1,'hello1');                   break;
Sasha>    default: mysql_query(&dbh, "insert into test values
Sasha> (2,'hello2');                   break;
Sasha>  }

No;  fork() will not work().  If you use pthread_create() instead of
fork it will work().

(fork() will inherit file descriptors which isn't that nice in this context)

Regards,
Monty
Thread
Threaded applications using mysqlShane Wegner5 May
  • Re: Threaded applications using mysqlChristian Mack5 May
    • Re: Threaded applications using mysqlMichael Widenius11 May
  • Re: Threaded applications using mysqlSasha Pachev11 May
    • Re: Threaded applications using mysqlMichael Widenius11 May