|
|
d73fd1 |
From bdc374bfbb0ca34ddb40713eb51d8535fdf11952 Mon Sep 17 00:00:00 2001
|
|
|
d73fd1 |
From: Stephan Bergmann <sbergman@redhat.com>
|
|
|
d73fd1 |
Date: Wed, 31 Jul 2019 16:27:33 +0200
|
|
|
d73fd1 |
Subject: [PATCH 2/2] Avoid deadlock in TestIndexSearcher
|
|
|
d73fd1 |
|
|
|
d73fd1 |
---
|
|
|
d73fd1 |
src/test/search/TestIndexSearcher.cpp | 51 +++++++++++++++++++++------
|
|
|
d73fd1 |
1 file changed, 41 insertions(+), 10 deletions(-)
|
|
|
d73fd1 |
|
|
|
d73fd1 |
diff --git a/src/test/search/TestIndexSearcher.cpp b/src/test/search/TestIndexSearcher.cpp
|
|
|
d73fd1 |
index 02c21aaf..a6dde5ba 100644
|
|
|
d73fd1 |
--- a/src/test/search/TestIndexSearcher.cpp
|
|
|
d73fd1 |
+++ b/src/test/search/TestIndexSearcher.cpp
|
|
|
d73fd1 |
@@ -8,9 +8,11 @@
|
|
|
d73fd1 |
|
|
|
d73fd1 |
DEFINE_MUTEX(searchMutex);
|
|
|
d73fd1 |
DEFINE_CONDITION(searchCondition);
|
|
|
d73fd1 |
+bool searchReady;
|
|
|
d73fd1 |
|
|
|
d73fd1 |
DEFINE_MUTEX(deleteMutex);
|
|
|
d73fd1 |
DEFINE_CONDITION(deleteCondition);
|
|
|
d73fd1 |
+bool deleteReady;
|
|
|
d73fd1 |
|
|
|
d73fd1 |
_LUCENE_THREAD_FUNC(searchDocs, _searcher) {
|
|
|
d73fd1 |
|
|
|
d73fd1 |
@@ -19,15 +21,20 @@ _LUCENE_THREAD_FUNC(searchDocs, _searcher) {
|
|
|
d73fd1 |
Query * query = QueryParser::parse(_T("one"), _T("content"), &an);
|
|
|
d73fd1 |
Hits * hits = searcher->search(query);
|
|
|
d73fd1 |
|
|
|
d73fd1 |
-// _LUCENE_SLEEP(9999); //make sure that searchMutex is being waited on...
|
|
|
d73fd1 |
+ {
|
|
|
d73fd1 |
+ SCOPED_LOCK_MUTEX(searchMutex);
|
|
|
d73fd1 |
+ searchReady = true;
|
|
|
d73fd1 |
+ CONDITION_NOTIFYALL(searchCondition);
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
|
|
|
d73fd1 |
- CONDITION_NOTIFYALL(searchCondition);
|
|
|
d73fd1 |
SCOPED_LOCK_MUTEX(deleteMutex);
|
|
|
d73fd1 |
|
|
|
d73fd1 |
_CLLDELETE(hits);
|
|
|
d73fd1 |
_CLLDELETE(query);
|
|
|
d73fd1 |
|
|
|
d73fd1 |
- CONDITION_WAIT(deleteMutex, deleteCondition);
|
|
|
d73fd1 |
+ while (!deleteReady) {
|
|
|
d73fd1 |
+ CONDITION_WAIT(deleteMutex, deleteCondition);
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
_LUCENE_THREAD_FUNC_RETURN(0);
|
|
|
d73fd1 |
}
|
|
|
d73fd1 |
|
|
|
d73fd1 |
@@ -55,13 +62,24 @@ void testEndThreadException(CuTest *tc) {
|
|
|
d73fd1 |
|
|
|
d73fd1 |
// this sequence is OK: delete searcher after search thread finish
|
|
|
d73fd1 |
{
|
|
|
d73fd1 |
+ searchReady = false;
|
|
|
d73fd1 |
+ deleteReady = false;
|
|
|
d73fd1 |
+
|
|
|
d73fd1 |
IndexSearcher * searcher = _CLNEW IndexSearcher(&ram;;
|
|
|
d73fd1 |
_LUCENE_THREADID_TYPE thread = _LUCENE_THREAD_CREATE(&searchDocs, searcher);
|
|
|
d73fd1 |
- SCOPED_LOCK_MUTEX(searchMutex);
|
|
|
d73fd1 |
|
|
|
d73fd1 |
- CONDITION_WAIT(searchMutex, searchCondition);
|
|
|
d73fd1 |
-// _LUCENE_SLEEP(9999); //make sure that deleteMutex is being waited on...
|
|
|
d73fd1 |
- CONDITION_NOTIFYALL(deleteCondition);
|
|
|
d73fd1 |
+ {
|
|
|
d73fd1 |
+ SCOPED_LOCK_MUTEX(searchMutex);
|
|
|
d73fd1 |
+ while (!searchReady) {
|
|
|
d73fd1 |
+ CONDITION_WAIT(searchMutex, searchCondition);
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
+
|
|
|
d73fd1 |
+ {
|
|
|
d73fd1 |
+ SCOPED_LOCK_MUTEX(deleteMutex);
|
|
|
d73fd1 |
+ deleteReady = true;
|
|
|
d73fd1 |
+ CONDITION_NOTIFYALL(deleteCondition);
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
|
|
|
d73fd1 |
_LUCENE_THREAD_JOIN(thread);
|
|
|
d73fd1 |
|
|
|
d73fd1 |
@@ -71,14 +89,27 @@ void testEndThreadException(CuTest *tc) {
|
|
|
d73fd1 |
|
|
|
d73fd1 |
// this produces memory exception: delete searcher after search finish but before thread finish
|
|
|
d73fd1 |
{
|
|
|
d73fd1 |
+ searchReady = false;
|
|
|
d73fd1 |
+ deleteReady = false;
|
|
|
d73fd1 |
+
|
|
|
d73fd1 |
IndexSearcher * searcher = _CLNEW IndexSearcher(&ram;;
|
|
|
d73fd1 |
_LUCENE_THREADID_TYPE thread = _LUCENE_THREAD_CREATE(&searchDocs, searcher);
|
|
|
d73fd1 |
- SCOPED_LOCK_MUTEX(searchMutex);
|
|
|
d73fd1 |
|
|
|
d73fd1 |
- CONDITION_WAIT(searchMutex, searchCondition);
|
|
|
d73fd1 |
+ {
|
|
|
d73fd1 |
+ SCOPED_LOCK_MUTEX(searchMutex);
|
|
|
d73fd1 |
+ while (!searchReady) {
|
|
|
d73fd1 |
+ CONDITION_WAIT(searchMutex, searchCondition);
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
+
|
|
|
d73fd1 |
searcher->close();
|
|
|
d73fd1 |
_CLLDELETE(searcher);
|
|
|
d73fd1 |
- CONDITION_NOTIFYALL(deleteCondition);
|
|
|
d73fd1 |
+
|
|
|
d73fd1 |
+ {
|
|
|
d73fd1 |
+ SCOPED_LOCK_MUTEX(deleteMutex);
|
|
|
d73fd1 |
+ deleteReady = true;
|
|
|
d73fd1 |
+ CONDITION_NOTIFYALL(deleteCondition);
|
|
|
d73fd1 |
+ }
|
|
|
d73fd1 |
|
|
|
d73fd1 |
_LUCENE_THREAD_JOIN(thread);
|
|
|
d73fd1 |
}
|
|
|
d73fd1 |
--
|
|
|
d73fd1 |
2.21.0
|
|
|
d73fd1 |
|