-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4554 trying a boost mutex class, mostly to see if it compiles
- Loading branch information
Janik Zikovsky
committed
Jan 18, 2012
1 parent
f6fc190
commit 5dd3ae3
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef MUTEXTEST_H | ||
#define MUTEXTEST_H | ||
|
||
#include <cxxtest/TestSuite.h> | ||
#include "MantidKernel/MultiThreaded.h" | ||
#include <boost/thread.hpp> | ||
|
||
using namespace Mantid::Kernel; | ||
|
||
boost::shared_mutex _access; | ||
void reader() | ||
{ | ||
boost::shared_lock< boost::shared_mutex > lock(_access); | ||
// do work here, without anyone having exclusive access | ||
} | ||
|
||
void conditional_writer() | ||
{ | ||
boost::upgrade_lock< boost::shared_mutex > lock(_access); | ||
// do work here, without anyone having exclusive access | ||
|
||
if (true) | ||
{ | ||
boost::upgrade_to_unique_lock< boost::shared_mutex > uniqueLock(lock); | ||
// do work here, but now you have exclusive access | ||
} | ||
|
||
// do more work here, without anyone having exclusive access | ||
} | ||
|
||
void unconditional_writer() | ||
{ | ||
boost::unique_lock< boost::shared_mutex > lock( _access ); | ||
// do work here, with exclusive access | ||
} | ||
|
||
|
||
class MutexTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
|
||
void test_1() | ||
{ | ||
|
||
} | ||
|
||
}; | ||
|
||
|
||
#endif /* MUTEXTEST_H */ | ||
|
||
|