mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Get threadtest2.c working again after being long neglected. (CVS 3562)
FossilOrigin-Name: 06216d0d3be38bfabda9f5f450a5eaccd20b52b9
This commit is contained in:
@ -39,12 +39,13 @@ volatile int all_stop = 0;
|
||||
** global variable to stop all other activity. Print the error message
|
||||
** or print OK if the string "ok" is seen.
|
||||
*/
|
||||
int check_callback(void *notUsed, int argc, char **argv, char **notUsed2){
|
||||
int check_callback(void *pid, int argc, char **argv, char **notUsed2){
|
||||
int id = (int)pid;
|
||||
if( strcmp(argv[0],"ok") ){
|
||||
all_stop = 1;
|
||||
fprintf(stderr,"pid=%d. %s\n", getpid(), argv[0]);
|
||||
fprintf(stderr,"id: %s\n", id, argv[0]);
|
||||
}else{
|
||||
/* fprintf(stderr,"pid=%d. OK\n", getpid()); */
|
||||
/* fprintf(stderr,"%d: OK\n", id); */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -53,13 +54,13 @@ int check_callback(void *notUsed, int argc, char **argv, char **notUsed2){
|
||||
** Do an integrity check on the database. If the first integrity check
|
||||
** fails, try it a second time.
|
||||
*/
|
||||
int integrity_check(sqlite *db){
|
||||
int integrity_check(sqlite *db, int id){
|
||||
int rc;
|
||||
if( all_stop ) return 0;
|
||||
/* fprintf(stderr,"pid=%d: CHECK\n", getpid()); */
|
||||
/* fprintf(stderr,"%d: CHECK\n", id); */
|
||||
rc = sqlite3_exec(db, "pragma integrity_check", check_callback, 0, 0);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
||||
fprintf(stderr,"pid=%d, Integrity check returns %d\n", getpid(), rc);
|
||||
fprintf(stderr,"%d, Integrity check returns %d\n", id, rc);
|
||||
}
|
||||
if( all_stop ){
|
||||
sqlite3_exec(db, "pragma integrity_check", check_callback, 0, 0);
|
||||
@ -70,21 +71,24 @@ int integrity_check(sqlite *db){
|
||||
/*
|
||||
** This is the worker thread
|
||||
*/
|
||||
void *worker(void *notUsed){
|
||||
void *worker(void *workerArg){
|
||||
sqlite *db;
|
||||
int id = (int)workerArg;
|
||||
int rc;
|
||||
int cnt = 0;
|
||||
fprintf(stderr, "Starting worker %d\n", id);
|
||||
while( !all_stop && cnt++<10000 ){
|
||||
if( cnt%1000==0 ) printf("pid=%d: %d\n", getpid(), cnt);
|
||||
if( cnt%100==0 ) printf("%d: %d\n", id, cnt);
|
||||
while( (sqlite3_open(DB_FILE, &db))!=SQLITE_OK ) sched_yield();
|
||||
sqlite3_exec(db, "PRAGMA synchronous=OFF", 0, 0, 0);
|
||||
integrity_check(db);
|
||||
/* integrity_check(db, id); */
|
||||
if( all_stop ){ sqlite3_close(db); break; }
|
||||
/* fprintf(stderr, "pid=%d: BEGIN\n", getpid()); */
|
||||
/* fprintf(stderr, "%d: BEGIN\n", id); */
|
||||
rc = sqlite3_exec(db, "INSERT INTO t1 VALUES('bogus data')", 0, 0, 0);
|
||||
/* fprintf(stderr, "pid=%d: END rc=%d\n", getpid(), rc); */
|
||||
/* fprintf(stderr, "%d: END rc=%d\n", id, rc); */
|
||||
sqlite3_close(db);
|
||||
}
|
||||
fprintf(stderr, "Worker %d finished\n", id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -100,7 +104,7 @@ int main(int argc, char **argv){
|
||||
char *zJournal = sqlite3_mprintf("%s-journal", DB_FILE);
|
||||
unlink(DB_FILE);
|
||||
unlink(zJournal);
|
||||
free(zJournal);
|
||||
sqlite3_free(zJournal);
|
||||
}
|
||||
sqlite3_open(DB_FILE, &db);
|
||||
if( db==0 ){
|
||||
@ -114,7 +118,7 @@ int main(int argc, char **argv){
|
||||
}
|
||||
sqlite3_close(db);
|
||||
for(i=0; i<sizeof(aThread)/sizeof(aThread[0]); i++){
|
||||
pthread_create(&aThread[i], 0, worker, 0);
|
||||
pthread_create(&aThread[i], 0, worker, (void*)i);
|
||||
}
|
||||
for(i=0; i<sizeof(aThread)/sizeof(aThread[i]); i++){
|
||||
pthread_join(aThread[i], 0);
|
||||
|
Reference in New Issue
Block a user