__sync_add_and_get() 1億次;
pthread_mutex_lock
add;
pthread_mutex_unlock 一億次
8 inline void AddBySync()
9 {
10 int iTep;
11 iTep = __sync_add_and_fetch( &iAtomicVariable, 1 );
12
13 }
24 inline void addByMutex()
25 {
26 pthread_mutex_lock( &mutexLock );
27 iAtomicVariable++;
28 pthread_mutex_unlock( &mutexLock );
29
30 }
使用時間
inline AddBySync using time 1373850 us
inline addByMutex sing time using time 3390161 us;
結果分析發現
mutex一次操作位 33ns,sync_fetch 爲13 ns
(sync using time 1403162 us, mutex using time 4269945 us )