From d140157952404d061c1e9df5c133d3ace735b73f Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 13 Nov 2018 09:25:42 +0100 Subject: Fix race in test code seen it fail at > 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 --- sal/qa/rtl/doublelock/rtl_doublelocking.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'sal') 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); -- cgit