This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use std::mt19937, std::thread and std::atomic to simplify tests

These tests that hammer shared_ptr and weak_ptr to test the
thread-safety of the reference counting were originally written for
the TR1 smart pointers, and so pre-date std::thread etc.

This refactors them to use C++11 std::thread and std::atomic (with
relaxed memory ordering, since we don't need to know the counter value
until after we've joined all the worker threads).

I also used the std::mt19937 typedef that uses the same parameters as
the test lists explicitly (mt19937 produces uint_fast32_t not unsigned
long, but that doesn't change anything here) and replaced the
non-uniform modulus operation with std::uniform_int_distribution.

To verify that after the changes we still test what we're trying to
test, I changed the shared_ptr code to remove the synchronization in
_M_add_ref_lock and saw the tests fail.

	* testsuite/20_util/shared_ptr/thread/ Use
	std::mt19937, std::thread and std::atomic to simplify test.
	* testsuite/20_util/shared_ptr/thread/ Likewise.

Tested x86_64-linux (8 HT cores) and powerpc64-linux (160 cores).

Committed to trunk.

Attachment: patch.txt
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]