티스토리 뷰
SQLite 단일 쓰레드에서 사용하는데는 큰 어려움이 없지만,
쓰레드 적용하면 동시 접근이 안되어 CriticalSection(임계영역)을 사용한다.
1
2
3
4
5
6 |
EnterCriticalSection(&h임계영역);
int nResult = sqlite3_open(pSimulDlg->GetSQLiteDB파일명(), &pDB); // DB열기
nResult = sqlite3_exec(pDB, strSQL, NULL, NULL, &pErr); // SQL 쿼리 실행
sqlite3_close(pDB); // DB닫기
LeaveCriticalSection(&h임계영역);
|
cs |
A 쓰레드에서 임계영역에 진입해서 DB 사용중일때 B 쓰레드에서 DB 접근하기 위해 EnterCriticalSection() 호출하면 B 쓰레드는 A쓰레드가 LeaveCriticalSection() 를 호출할때까지 대기 상태가 된다.
동기화 불필요한 MySQL 참고 : http://petra.tistory.com/1074
- 동시 접근하면 에러가 발생하는데, Client/Server 환경의 모 프로그램은 SQLite를 사용한다. 구현 방법이 궁금....