Hi everybody!
i'm running my multi-threads program under linux, so in that program i'm tring to do an INSERT, a number x of times. sqlite libraries are compiled with threadsafe, and i have a sqlite3_busy_handler in each connection to database (there is a different connection for each thread), sometimes get an error like "database is locked", and my busy handler function never is called, but sometimes that works, but only in a few threads. sqlite3_busy_timeout doesn't work either �why?!!!
This is my little program:
int handlerBusy(void * ptr, int prior)
{
printf("enter to busy handler\n");
fflush(stdout);
sleep(1);
return(1);
}void * functionThread(void * param)
{
sqlite3 * db=NULL;
int rc;
char * zErrMsg;
int i;i=*((int*)param); pthread_mutex_unlock(&MutexN);
printf("start %d\n", i);
fflush(stdout);
rc = sqlite3_open("/root/testSpeed.db3", &db);
if(rc)
{
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return(NULL);
}
sqlite3_busy_timeout(db, 6000);
sqlite3_busy_handler(db, &handlerBusy, NULL);
sqlite3_exec(db, "PRAGMA default_temp_store = MEMORY;PRAGMA temp_store = MEMORY;", NULL, NULL, &zErrMsg);
rc=sqlite3_exec(db, "INSERT INTO t2 VALUES(NULL, 234, 'DSFDSFDS')", NULL, NULL, &zErrMsg);
if( rc!=SQLITE_OK )
{
fprintf(stdout, "%d: SQL error: %s\n", i, sqlite3_errmsg(db));
fflush(stdout);
}
sqlite3_close(db);
printf("end %d\n", i);
fflush(stdout);
pthread_exit(NULL);
return(NULL);}
int main()
{
int i;
int i2;
........
........
for(i=0;i<atoi(argv[1]);i++)
{
pthread_mutex_lock (&MutexN);
i2=i;
if(pthread_create(&PsockServ, NULL, functionThread, &i2)!=0)
{
perror("pthread_create");
return(1);
}
}
return(0);
}Probably i'm wrong, but where. Somebody can help me?.
Greetings Eng. Xavier Aguila

