在vc6里没有读写锁,必须自己实现一个,因为要求效率高一点,所以封装Mutex,CriticSection的就不要了
找了一个linux下的实现:
http://www.ibm.com/developerworks/cn/linux/l-rwlock_writing/index.html
没看懂啊
请问该怎么实现呢?
找了一个linux下的实现:
http://www.ibm.com/developerworks/cn/linux/l-rwlock_writing/index.html
没看懂啊
请问该怎么实现呢?
自己实现锁还是依赖于CriticSection实现的
CriticSection达不到只允许一个人写,但允许多个人读啊
读的读到一半,写的突然一顿写,读的不傻眼了吗?
typedef struct {
volatile unsigned int lock;
#if SPINLOCK_DEBUG
unsigned magic;
#endif
} rwlock_t;#define __build_write_lock_const(rw, helper) \
asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",(%0)\n\t" \
"jnz 2f\n" \
"1:\n" \
".section .text.lock,\"ax\"\n" \
"2:\tpushl %%eax\n\t" \
"leal %0,%%eax\n\t" \
"call " helper "\n\t" \
"popl %%eax\n\t" \
"jmp 1b\n" \
".previous" \
:"=m" (*(volatile int *)rw) : : "memory")
static inline void read_lock(rwlock_t *rw)
{
#if SPINLOCK_DEBUG
if (rw->magic != RWLOCK_MAGIC)
BUG();
#endif
__build_read_lock(rw, "__read_lock_failed");
}
static inline void write_lock(rwlock_t *rw)
{
#if SPINLOCK_DEBUG
if (rw->magic != RWLOCK_MAGIC)
BUG();
#endif
__build_write_lock(rw, "__write_lock_failed");
}
//faint
读的读到一半,写的突然一顿写,读的不傻眼了吗? 你是什么CPU哦,同时运行的线程??