OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: SMP and the lost + wake-up problem
PostPosted: Fri Jan 29, 2021 12:34 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Sounds reasonable. Essentially you are adding a spinlock in the TCB to say that the thread is actually running.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: SMP and the lost + wake-up problem
PostPosted: Fri Jan 29, 2021 1:15 pm 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 am
Posts: 401
kzinti wrote:
I might have found another problem... You could end up with a CPU picking up a "suspended" thread that is not yet really suspended:

Code:
CPU 1 thread A                  CPU 2 thread B

A: enter monitor
A: try to get mutex (fail)
A: queue in wait list
A: leave monitor
                                 B: enter monitor
                                 B: release mutex
                                 B: wakeup thread A
                                 B: leave monitor
                                 B: schedule()
                                 A: thread A starts to run
A: schedule()
C: thread C starts to run


How would your code prevent the above from happening? This is basically revisiting something I previously mentioned: when you add the current thread the the monitor's wait list, it is still running. The CPU is still using it's stack and address space at a minimum. That stack should not be used by another CPU until your thread switch completes on the current CPU.

PS: I am not trying to point out flaws in your implementation, I am just trying to fix mine and understand how to do it :).


I'm just glad I've got other eyes on my code. Much of this is virgin code that has not seen the light of day in the real world, it being unreleased as it is.

I think you're right, and your later suggestion of a spin lock in the TCB itself would be a perfect solution to this.

Thanks!


Top
 Profile  
 
 Post subject: Re: SMP and the lost + wake-up problem
PostPosted: Fri Jan 29, 2021 6:59 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Of course the problem with this spinlock or flag inside the TCB is that after the switch, you need to know what was the task that was running before the switch. I am not sure I like this.

I've also looked into using futexes and I am not sure it solves the problem. But in light of the above, I might try to implement futexes nevertheless since I want them in the end for my user space locking needs.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group