summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-11-13 09:25:42 +0100
committerStephan Bergmann <sbergman@redhat.com>2018-11-13 14:11:59 +0100
commitd140157952404d061c1e9df5c133d3ace735b73f (patch)
tree167962bd5d0bcbc10e9272df6b5288d7ff90bfdb
parent607ab542d043c24bfbd6a08bb62fbebd095114e3 (diff)
Fix race in test code
seen it fail at <https://ci.libreoffice.org/job/lo_tb_master_win/19591/> > Value in Thread #1 is 0 > Value in Thread #2 is 0 > C:/cygwin/home/tdf/lode/jenkins/workspace/lo_tb_master_win/sal/qa/rtl/doublelock/rtl_doublelocking.cxx:199:rtl_DoubleLocking::getValue::getValue_002 > assertion failed > - Expression: nValueOK != 0 > - getValue() failed, wrong value expected. > > rtl_DoubleLocking::getValue::getValue_002 finished in: 1267ms Change-Id: I6ac85a9ff4da8c046412add40c9447ee53ef8d7e Reviewed-on: https://gerrit.libreoffice.org/63320 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--sal/qa/rtl/doublelock/rtl_doublelocking.cxx7
1 files changed, 5 insertions, 2 deletions
diff --git a/sal/qa/rtl/doublelock/rtl_doublelocking.cxx b/sal/qa/rtl/doublelock/rtl_doublelocking.cxx
index 1975057e33e3..cba75e99f728 100644
--- a/sal/qa/rtl/doublelock/rtl_doublelocking.cxx
+++ b/sal/qa/rtl/doublelock/rtl_doublelocking.cxx
@@ -80,6 +80,7 @@ namespace ThreadHelper
*/
class OGetThread : public osl::Thread
{
+ osl::Mutex m_mutex;
sal_Int32 m_nOK;
sal_Int32 m_nFails;
@@ -92,8 +93,8 @@ public:
m_sConstStr = CONST_TEST_STRING;
}
- sal_Int32 getOK() { return m_nOK; }
- sal_Int32 getFails() {return m_nFails;}
+ sal_Int32 getOK() { osl::MutexGuard g(m_mutex); return m_nOK; }
+ sal_Int32 getFails() {osl::MutexGuard g(m_mutex); return m_nFails;}
protected:
@@ -108,10 +109,12 @@ protected:
OUString aStr = Gregorian::get();
if (aStr == m_sConstStr)
{
+ osl::MutexGuard g(m_mutex);
m_nOK++;
}
else
{
+ osl::MutexGuard g(m_mutex);
m_nFails++;
}
ThreadHelper::thread_sleep_tenth_sec(1);