sync on a smp system (again)
Posted: Tue Nov 15, 2005 2:36 am
Ok, I haven?t done much in the last few weeks, but this is because I can?t solve my problem. We had a discussion about the thread locking - the scheduler gets the spinlock of a thread when this thread will run and it gives it back when this thread has finished - and I took the idea of pype. This worked in the beginning.
I think I have to explain the problem again in detail. My OS works an a smp machine, but not if I?m using semaphores
I have 2 threads and both only print a number. I lock the print function with a semaphore. The code works for a short time and then I get a page fault, because there is a field in a struc, which is NULL and this field can?t be NULL! The problem occures when the semaphore calls the function to add the thread to the ready queue.
This is the function:
I load the head of the queue into eax and then I test if eax is NULL and it isn?t. So I load ebx with the end of the queue and this value can?t be NULL, but it is and so it gives me a page fault when it wants to use ebx as a base pointer.
-> see the next post
I think I have to explain the problem again in detail. My OS works an a smp machine, but not if I?m using semaphores
I have 2 threads and both only print a number. I lock the print function with a semaphore. The code works for a short time and then I get a page fault, because there is a field in a struc, which is NULL and this field can?t be NULL! The problem occures when the semaphore calls the function to add the thread to the ready queue.
This is the function:
Code: Select all
;----------------------------
PROC scheduler_add_scheduler, ptr2thread
;----------------------------
BEGIN
cli
CALL spinlock_acquire, schdl_spin
;----------------------------
; add thread to ready queue
mov esi,[ptr2thread] ;esi= actThread
mov ebx,1
mov ecx,[esi+thread_t.dyn_prio]
mov edi,[ready_queue_ptr]
shl ebx,cl
or [ready_queue_bitmap],ebx
mov eax,[edi+4*ecx] ;eax= firstThread
xor edx,edx
test eax,eax
jz .first
mov ebx,[eax+thread_t.prev] ;ebx= firstThread.prev= lastThread
mov [esi+thread_t.prev],ebx ;actThread.prev= lastThread
mov [esi+thread_t.next],edx ;actThread.next= NULL
mov [eax+thread_t.prev],esi ;firstThread.prev= actThread
mov [ebx+thread_t.next],esi ;lastThread.next= actThread
jmp .end
;----------------------------
; it is the 1st thread in this priority queue
align 4
.first:
mov [esi+thread_t.prev],esi ;actThread.prev= firstThread.prev= actThread
mov [esi+thread_t.next],eax ;actThread.next= firstThread.next= NULL
mov [edi+4*ecx],esi
;----------------------------
align 4
.end:
or dword[schdl_flags],SCHEDULER_RESCHEDULE
CALL spinlock_release, schdl_spin
sti
RETURN
ENDP
;----------------------------
-> see the next post