摘要: 源码分析版本:glic-2.9spin_lock加锁pthread_spin_lock:intpthread_spin_lock (lock) pthread_spinlock_t *lock;{ asm ("\n" "1:\t" LOCK_PREFIX "decl %0\n\t" //锁总线,开始加锁,在%0 "jne 2f\n\t" //加锁不成功,jns 汇编指令检查 EFLAGS 寄存器的 SF(符号)位,如果为 0,说明 slock 原来的值为 1,则线程获得锁,然后跳到标签 2 的位置结束本次函数调用。 阅读全文
posted @ 2012-09-27 21:04 北海石松 阅读(3025) 评论(0) 推荐(0) 编辑
摘要: 测试环境:24CPU 2.4GHz ,32G内存实验数据:mutex.cView Code #include <stdio.h>#include <pthread.h>#include <stdlib.h>#include <sys/time.h>#define MAX_LOOP 1000000#define CODE_LEN 10long g_count = 0;int thread_count = 20;int lock_count = 0;int loop_count = 1000000;int code_len = 1;pthread_m 阅读全文
posted @ 2012-09-27 01:48 北海石松 阅读(1526) 评论(0) 推荐(0) 编辑