Basic questions about theLOCK, it doesn't work as I thought.
Posted: Wed Sep 09, 2009 2:05 am
Hello,.
Currently I'm implementing some synchronization methods such as spinlock, semaphore, mutex, ...
But those are not working correctly,. so I paste some codes from my kernel to here.
Would you let me know what I've missed?
Thank you..
When I enable the "nop" instruction, only one thread works, (there are 3 threads are exists)
but if I disable "nop" instruction, no threads are woking,. and the kernel starting to busy-waiting.
Currently I'm implementing some synchronization methods such as spinlock, semaphore, mutex, ...
But those are not working correctly,. so I paste some codes from my kernel to here.
Would you let me know what I've missed?
Thank you..
Code: Select all
void spinlock_lock(spin_lock_t *handle)
{
// while (handle->lock) DbgPrint("a %p\n", kthread_get_current());
// handle->lock = 1;
// return;
// cursor_set_pos(0, 0);
// DbgPrint("===== [Task %p] =====\n", kthread_get_current());
asm __volatile__ (
// "cli\n"
"clc\n"
"1:\n"
"lock; btsl $0, %0\n"
// "sti\n"
// "nop; nop; nop; nop\n"
// "nop; nop; nop; nop\n"
// "cli\n"
"jc 1b\n"
// "sti\n"
:
: "m"(handle->lock)
: "memory"
);
// PANIC("Locked %d\n", handle->lock);
// if (handle->lock > 1) PANIC("Error\n");
}
but if I disable "nop" instruction, no threads are woking,. and the kernel starting to busy-waiting.
