// wrapper for sqlite3_prepare_v2 which retries creating statements if the db returns SQLITE_BUSY or SQLITE_LOCKED int sql_prepare(sqlite3 *db, const char *sql, sqlite3_stmt **ppStmt, int wait) { #ifdef SQL_DEBUG printf(sql); printf("\n"); fflush(stdout); #endif int rc; char looper[4] = {'|','/','-','\\'}; int looperc = 0; int waited = 0; while (1) { rc = sqlite3_prepare_v2(db,sql,-1,ppStmt,NULL); if (rc == SQLITE_LOCKED || rc == SQLITE_BUSY) { if (wait != 0) { fprintf(stdout,"Database is locked or busy. Waiting %is ... %1c \r", ++waited, looper[looperc]); fflush(stdout); wait--; looperc = ++looperc % sizeof(looper); sleep(1); } else { fprintf(stderr,"Database was locked or busy while creating statement. I've given up.\n"); return rc; } } else { if (waited != 0) printf("\n\n"); return rc; } } } --- [EMAIL PROTECTED] schrieb:
> Hi, > > I am having a scenario where I have one > reader/writer and many writer threads. > All writers are pretty basic (single INSERT INTO; > some sort of a logging info > what a thread has done). > > I believe I will receive many BUSY return codes and > I don't like these > spinlock-like retries. The problem I am having with > this design is that I would > like to complete the thread ASAP, so that I don't > have many threads idling and > consuming resources of my embedded system. > > I was thinking to either: > > a. Use mutex/semaphore before writting to the > database or > > b. Have a (thread safe) list of INSERT INTO strings > that every writer thread > populates and the main reader/writer thread later > executes. > > Is this a good approach? Does anyone have a better > design? I don't want to use > other database, because I think Sqlite is great for > an embedded system that I > am using. > ___________________________________________________________________________ > Najhitrej¹i brezplaèni klicni dostop :: Varno in > zanesljivo po internetu > Obi¹èite http://www.dialup386.com/ > > ----------------------------------------------------------------------------- > To unsubscribe, send email to > [EMAIL PROTECTED] > ----------------------------------------------------------------------------- > > ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------