OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 4:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Implement semaphore using pipe?
PostPosted: Fri Mar 22, 2024 3:02 am 
Offline
Member
Member

Joined: Fri Jun 28, 2013 1:48 am
Posts: 65
I'm thinking if we can provide semaphore as a special type of pipe. Semaphores are just pipes without data.

Semaphore is a shared variable, tasks can up/down its value. Tasks might switch to pending state during up/down.

Pipe is a shared buffer, with a variable indicating current buffer size. Tasks can write to a pipe, increasing the buffer size. Tasks can read from a pipe, decreasing the buffer size. Writing and reading pipe might pend the caller task.

If we remove the data copy part from the pipe, then it becomes semaphore. And mutex is just pipe without data and size limit set to ONE.

So we can provide pipe, semaphore and mutex using one code base?

Scheduling related code is difficult to debug. Doing so could make kernel simpler.

_________________
Reinventing the Wheel, code: https://github.com/songziming/wheel


Top
 Profile  
 
 Post subject: Re: Implement semaphore using pipe?
PostPosted: Fri Mar 22, 2024 9:21 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1605
This idea is nothing new. I remember a text about "make -j" talking about using pipes as semaphores. Personally, though, I think that simply implementing futexes, and then implementing pipes, semaphores, mutexes, rwlocks, and barriers with them is the better idea. And futexes are a fundamentally very simple system, in which you merely suspend and awaken threads.

_________________
Carpe diem!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 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