|
Boost : |
From: Michael van der Westhuizen (r1mikey_at_[hidden])
Date: 2006-07-08 13:21:53
Hi,
On 7/8/06, Peter Dimov <pdimov_at_[hidden]> wrote:
> Actually, the bug in the original seems to be that CAS returns the old value
> in swap_ and not compare_, so how about:
>
> inline int32_t compare_and_swap( int32_t * dest_, int32_t compare_, int32_t
> swap_ )
> {
> __asm__ __volatile__( "cas %0, %2, %1"
> : "+m" (*dest_), "+r" (swap_)
> : "r" (compare_)
> : "memory" );
>
> return swap_;
> }
I've just tested with the above code, and it works perfectly. Test
results below.
Michael
[michael_at_hawk test]$ LD_LIBRARY_PATH=/usr/local/lib timex
./shared_ptr_mt_test_v8
LD_LIBRARY_PATH=/usr/local/lib timex ./weak_ptr_mt_test_v8
LD_LIBRARY_PATH=/usr/local/lib/sparcv9 timex ./shared_ptr_mt_test_v9
LD_LIBRARY_PATH=/usr/local/lib/sparcv9 timex ./weak_ptr_mt_test_v9
Using POSIX threads: 16 threads, 1048576 iterations:
29.290 seconds.
real 15.35
user 27.80
sys 1.50
[michael_at_hawk test]$ LD_LIBRARY_PATH=/usr/local/lib timex ./weak_ptr_mt_test_v8
Using POSIX threads: 16 threads, 16384 * 512 iterations:
393142 locks, 188334 forced rebinds, 8011850 normal rebinds.
370140 locks, 176821 forced rebinds, 8034852 normal rebinds.
379069 locks, 181471 forced rebinds, 8025923 normal rebinds.
385131 locks, 183882 forced rebinds, 8019861 normal rebinds.
386402 locks, 184821 forced rebinds, 8018590 normal rebinds.
371917 locks, 177690 forced rebinds, 8033075 normal rebinds.
354785 locks, 169169 forced rebinds, 8050207 normal rebinds.
386274 locks, 184679 forced rebinds, 8018718 normal rebinds.
365789 locks, 174817 forced rebinds, 8039203 normal rebinds.
386848 locks, 185118 forced rebinds, 8018144 normal rebinds.
391157 locks, 187057 forced rebinds, 8013835 normal rebinds.
393826 locks, 188886 forced rebinds, 8011166 normal rebinds.
379926 locks, 181955 forced rebinds, 8025066 normal rebinds.
368179 locks, 175849 forced rebinds, 8036813 normal rebinds.
376914 locks, 179919 forced rebinds, 8028078 normal rebinds.
393944 locks, 188666 forced rebinds, 8011048 normal rebinds.
57.650 seconds.
real 29.55
user 57.64
sys 0.03
[michael_at_hawk test]$ LD_LIBRARY_PATH=/usr/local/lib/sparcv9 timex
./shared_ptr_mt_test_v9
Using POSIX threads: 16 threads, 1048576 iterations:
29.490 seconds.
real 16.02
user 26.97
sys 2.55
[michael_at_hawk test]$ LD_LIBRARY_PATH=/usr/local/lib/sparcv9 timex
./weak_ptr_mt_test_v9
Using POSIX threads: 16 threads, 16384 * 512 iterations:
388081 locks, 186099 forced rebinds, 8016911 normal rebinds.
364511 locks, 173847 forced rebinds, 8040481 normal rebinds.
369474 locks, 176415 forced rebinds, 8035518 normal rebinds.
383873 locks, 183812 forced rebinds, 8021119 normal rebinds.
384370 locks, 184453 forced rebinds, 8020622 normal rebinds.
383454 locks, 183042 forced rebinds, 8021538 normal rebinds.
388084 locks, 186153 forced rebinds, 8016908 normal rebinds.
371612 locks, 178114 forced rebinds, 8033380 normal rebinds.
372215 locks, 177854 forced rebinds, 8032777 normal rebinds.
381007 locks, 181799 forced rebinds, 8023985 normal rebinds.
377198 locks, 180555 forced rebinds, 8027794 normal rebinds.
375531 locks, 179215 forced rebinds, 8029461 normal rebinds.
383229 locks, 183052 forced rebinds, 8021763 normal rebinds.
399208 locks, 191269 forced rebinds, 8005784 normal rebinds.
404128 locks, 193853 forced rebinds, 8000864 normal rebinds.
372118 locks, 178341 forced rebinds, 8032874 normal rebinds.
37.060 seconds.
real 19.37
user 37.05
sys 0.02
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk