OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 3:35 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Conditional Suspension/Resumption of Threads
PostPosted: Sat Aug 05, 2023 10:25 pm 
Offline

Joined: Sat Aug 05, 2023 9:49 pm
Posts: 1
Hello everyone,
I am still relatively new to operating systems and I am learning about POSIX with the intention of eventually developing my own OS from scratch. In POSIX, it seems there is an option to suspend a thread until some condition is met.

I designed a similar mechanism which allows for entire logical expressions to be evaluated rather than just one conditional variable. Furthermore, it can be used to both suspend the thread if the thread is active/running and resume the thread if it is stopped.

What are your thoughts? I thought this would be a good extension, but I would like to know your opinion.

Thanks!


Top
 Profile  
 
 Post subject: Re: Conditional Suspension/Resumption of Threads
PostPosted: Wed Aug 09, 2023 6:10 am 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
So from what I understand, you are suspending the thread, and creating an evaluation function that either returns true or false ? this function is executed each time the scheduler finds the thread suspended and if the functions returns true the thread is no longer suspended ?

Personnaly, for example with a disk driver I will just suspend the thread, wait for the interrupt and then the interrupt handler will resume the thread, the thread is looping SuspendThread() until the condition is met (which is probably some value or boolean set by the interrupt handler or a process waiting for IPC), if it's not (for e.g. some other thread tries to wake up the thread) it just suspends itself again. A second SuspendThread() could be dangerous though, It may result in a deadlock but I will fix it later.


Top
 Profile  
 
 Post subject: Re: Conditional Suspension/Resumption of Threads
PostPosted: Wed Aug 09, 2023 6:24 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
Stkyrdknmblz wrote:
Hello everyone,
In POSIX, it seems there is an option to suspend a thread until some condition is met.

If you mean condition variables, you are misunderstanding what they are, I think.

Quote:
I designed a similar mechanism which allows for entire logical expressions to be evaluated rather than just one conditional variable.

A POSIX condition variable is just a synchronisation device. It does not reflect the actual condition itself. You can already tie "entire logical expressions" to condition variables in POSIX; an application does this by signalling the condition variable when it detects (by whatever means) that the logical expression has become true.

Quote:
Furthermore, it can be used to both suspend the thread if the thread is active/running and resume the thread if it is stopped.

POSIX condition variables achieve both these goals. A thread suspends on the condition variable after checking the condition, determining that it is false, and deciding to wait until another thread makes it true. When another thread makes the condition true, it signals the condition variable and the waiting thread then resumes.

It sound like you plan to make this suspension/resumption automatic, rather than requiring explicit action by the application. As well as being difficult to implement (assuming it as general as you make it sound), I think this would be less useful since it makes it much more difficult to understand when the thread might become blocked. Also, you need some way of assigning which thread(s) should be blocked when the condition is false. That is normally explicit since a thread itself chooses to wait.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 44 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