#mutex
Explore tagged Tumblr posts
digitalthinkerhelp · 1 year ago
Text
Mutex in Operating System with Examples – Complete Guide
Tumblr media
Hello Learners! Today, we are going to cover all possible stuffs about what is mutex in OS (Operating System) and their examples with ease. This is unique article over the internet. So making ensure that at the end of this post; you will definitely fully educate about Mutex in Operating System without getting any hindrance.
‘Mutex in OS’ Tutorial Headlines:
In this section, we will show you all headlines about this entire article; you can check them as your choice; below shown all:
What is Mutex in OS?
How Does Work Mutex in OS?
Types of Mutex Locks
Components of Mutex Locks
Example of Mutual Exclusion
Applications & Uses of Mutex in OS
Advantages of Mutex in OS
Disadvantages of Mutex in OS
Solve: Producer-Consumer Problem with Example
FAQs (Frequently Asked Questions)
Why is Mutex Important in OS?
Why mutex is faster than semaphore?
Why mutex is required?
What Does mutex prevent deadlock?
Can Mutexes be used across different processes?
Let’s Get Started!!
0 notes
jacob-cs · 2 years ago
Text
RUST 122-133 in english
Arc
Tumblr media
위는 잘못된 코드 (타이포 borrow_mut() )
Rc는 쓰레드와 같이 사용할수 없다는 것을 보여준다.
Tumblr media
thread safe가 되기 위해서는 Send, Sync 두개다 가져야 한다
Tumblr media
위와 같이 RefCell의 경우는 Send는 있지만 Sync는 없으므로 thread safe 가 아님
Tumblr media
Arc , Mutex 같이 사용하기
Tumblr media Tumblr media
위 작동하는 코드 (단 타이포 Arc::new(Mutex::new(0))에서  Mutex 가 아니고 RwLock이)
Arc, RwLock 같이 사용한 경우 
Tumblr media Tumblr media
closure
Tumblr media Tumblr media
refs_it 에서 사용된경우는  borrow 방법 (Fn 방법) my_string이 closure안에서 값이 변화되지는 않았기 때문
mutes_it 에서 사용된 경우는 FnMut 방법 이다.  my_string이 closure안에서 값이 변화되었 때문
Tumblr media Tumblr media Tumblr media
위 맞는 코드 단( 타이포  cool_book.year % 2 == 0 )
Tumblr media Tumblr media
impl trait
Tumblr media
위 와 아래는 같은 효과
Tumblr media
Box
Tumblr media Tumblr media
위 array는 스택에 만들어지기 때문에 빠르지만 위와 같이 대용량 사용이 불가능하다 그래서  box를 이용해 heap 대용량 데이터를 저장할수 있다
Tumblr media
위와 같이 사용할수 있을것 같지만 사실은 아니다. 왜냐하면 데이터를 스택에 먼저 만들고 그것을 복사해서 heap에 만들기 때문이다
그래서 아래가 맞는 방법이다
Tumblr media Tumblr media
box는 포인터를 스택에 저장하고 데이터는 힙에 저장하므로
모든 box의 사이즈는 8 바이트로 같다
Tumblr media
box의 값에 접근해서 수정하는 경우 포인터와 같이 * operator를 이용한다
dyn
Tumblr media Tumblr media Tumblr media
channel
Tumblr media Tumblr media
위 타입 T 가 명시 되지 않았기 때문에 패닉
Tumblr media
위는 타입T가 정해졌으므로 패닉하지 않음
Tumblr media Tumblr media Tumblr media
0 notes
thesomebodywho · 3 months ago
Text
Imagine this but without any locks in vanilla C. You'd end up sitting on the toilet, drinking from the faucet, eating a piece of plain white toast while scrolling through Tumblr all at the same time.
Honestly I'm super glad that the OS gives a segmentation fault if the piss() function tries to access the pants register.
Having ADHD is like trying to run asynchronous code on a single-threaded CPU. Sure the OS can try to allocate CPU time for all of the parallel tasks running but it's not efficient, takes a lot of time and is error-prone.
Also don't forget the part where your manager says that we'll try to look at something together later and it's just like he went in and wrote await meeting(); into the middle of the main loop.
Your manager is also connected through a PS/2-port that can just send a CPU interrupt at any time by calling you.
8 notes · View notes
kawaoneechan · 1 year ago
Text
Okay so in a game like Animal Crossing, there's a bunch of things all happening at once. You can have a screen full of villagers walking around doing their thing, balloons flying, bugs bugging, a system in the background to handle hourly background music with chimes in between, all that good stuff, while you're doing your own things.
When you talk to a villager, you and the villager both stop on the spot, and a script takes over. That script then makes the villager turn to the player and a dialogue window appears. There may be a multiple choice thing now — "talk", "gift", or "leave" — and the script won't stop, releasing control to both, until what you've selected plays out.
So you have a villager with an attached script. The villager waits for the script to finish before continuing on their merry way, while the script waits for the villager to finish turning to the player. Once that's done, it picks something to say and eventually ends up opening the dialogue window. The script now has to wait for the message to finish writing, and the very next command is an "if" involving the result of a multiple choice question, so now the script has to wait for that to return.
I was thinking for Project Special K I might implement all that as several Tickable objects. Not unlike in SCI, you'd have a big list of things in the game that all implement a Tick method. In SCI, that'd be the cast, and its members have doit methods. It's the same deal, but Tick also gets a delta-time argument. So the dialogue box gets to be its own thing that implements Tickable, the multiple choice box is as well. Inventory window? Yes.
Also the script interpreter.
But all that wouldn't let the villager wait for the script interpreter, which waits for the dialogue box, right? Script execution should be halted until the dialogue box is dismissed. That one villager's AI should be halted until the interpreter finishes, only moving (or rather, emoting) because of embedded commands in the dialogue box's text stream.
So I figured, what if I gave them something like a mutex variable? The villager would have a bool waiting or whatever, and passes a pointer to that bool to the script interpreter they spawn when the player interacts with them. The interpreter is added to the cast list and starts running the code it was given. When it's done, it not only removes itself from the cast but sets the bool pointer so the villager can tell it's over and done with.
Now every time through the loop, the villager's Tick is called and they can tell "oh, I'm waiting for a script to finish" because their bool isn't set yet. The script interpreter likewise can spawn a dialogue box into the cast and have its own "waiting for that darn dialogue box" bool, in exactly the same way the villager can wait for the script interpreter.
Next trick, the dialogue box should remain on screen even when things are done, so multiple choice answers can have the question remain visible. It should only close when a different style of box is called for, or when the script ends. My idea is to always have a dialogue box object in the cast, idling until called for. When the villager realizes the script has ended, they can simply poke the dialogue box and have it close, if nothing else already did.
97 notes · View notes
emblogicsblog · 5 months ago
Text
Linux System Programming course
The Linux System Programming course is designed to provide a comprehensive understanding of system-level programming in Linux, focusing on core principles that underpin the operation of Linux-based systems. Participants will delve into essential topics such as process management, inter-process communication (IPC), threading, and synchronization techniques. These concepts form the backbone of efficient and scalable application development in Linux environments.
Tumblr media
Through a carefully structured curriculum, the course emphasizes hands-on learning with real-world scenarios and practical projects. Learners will gain proficiency in using system calls, navigating the Linux kernel, and implementing robust programming practices to create high-performance applications. Topics like signal handling, file system manipulation, memory management, and device interfacing are also explored, ensuring a well-rounded skill set.
This course goes beyond theoretical knowledge, aiming to empower participants with the ability to solve complex system-level challenges. By engaging in coding exercises and collaborative projects, learners will develop problem-solving skills and acquire the expertise needed to design and implement Linux-based solutions effectively.
Ideal for software developers, engineers, and IT professionals, the Linux System Programming course equips individuals with advanced capabilities in debugging, optimizing, and enhancing applications for Linux platforms. Whether building distributed systems, optimizing performance-critical applications, or contributing to open-source projects, this course lays the foundation for success in diverse roles.
Graduates of the course will emerge as proficient Linux system programmers, ready to tackle advanced challenges and contribute to innovative Linux-based projects across industries. With an emphasis on both foundational concepts and practical application, this course is a gateway to mastering Linux system programming and excelling in a competitive technological landscape.Linux System Programming course, Linux System Programming, Process Management Training, IPC Linux Course, POSIX Threads Tutorial, Linux Process Synchronization, Advanced Linux Programming, Linux Mutexes Workshop, System Programming with Linux, Linux Inter-Process Communication Course, Linux Threads and Processes Training.
0 notes
vlruso · 2 years ago
Text
Researchers from UT Austin Introduce MUTEX: A Leap Towards Multimodal Robot Instruction with Cross-Modal Reasoning
📣 Exciting news! Researchers from UT Austin have introduced MUTEX, a groundbreaking framework that takes robot capabilities to the next level in assisting humans. By integrating policy learning from various modalities like speech, text, images, and videos, MUTEX enables robots to understand and execute tasks using different forms of communication. 🤖💬📝📷🎥 Learn more about this leap forward in multimodal robot instruction with cross-modal reasoning in our latest blog post: [Link to Blog Post](https://ift.tt/d5vjgUC) The researchers tackled the limitation of existing robotic policy learning methods and developed MUTEX, a game-changer in human-robot collaboration. The framework's training process involves masked modeling and cross-modal matching, resulting in substantial performance improvements. 🚀 This comprehensive blog post reviews the MUTEX framework and dives into its architecture, training process, evaluation results, and future possibilities. 📚📊✨ Don't miss out on this innovative research! Check it out here: [Link to Blog Post](https://ift.tt/d5vjgUC) Stay up to date with the latest AI research, cool projects, and more by joining our ML SubReddit with 30k+ members, Facebook Community with 40k+ followers, Discord Channel, and Email Newsletter. 💡🔬➕ And if you enjoy our work, you don't want to miss out on our informative newsletter! Subscribe now to get AI research news delivered straight to your inbox. 📩 Let's explore the future of robotics together! 🌟 #AI #Robotics #Research #MUTEX #MultimodalLearning #Innovation #Tech #MarkTechPost List of Useful Links: AI Scrum Bot - ask about AI scrum and agile Our Telegram @itinai Twitter -  @itinaicom
0 notes
bayporwave · 10 days ago
Text
Tumblr media
Mutex and Mud Pie
Mutex is a sapient AI working on cloud storage maintenance for a tech company. They have their own RC unit to roam around company grounds and personally chat with co-workers.
Mud Pie is a web designer, and a bit of the family outcast, having a mild social disorder and not often fitting in with their group. They mainly occupy themselves either online or crafting interactive art sculptures when not in the mood to deal with typical familial complaints.
Two met online, Mutex being vastly interested in Mud Pie's craft and design, even offering some assistance for improving their personal site. The two would become quite chatty with each other, even having special visits, which their relationship would eventually become more romantically involved.
Mud Pie's family has no clue of this relationship, and assume the two are more business friendly.
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
Mud Pie is very into machines and the idea of being placed into one.
Mutex belongs to a7-l45 on bluesky! <3
103 notes · View notes
regexkind · 11 months ago
Text
tfw you really need to go to the bathroom but you're not holding the mutex
81 notes · View notes
eightyonekilograms · 9 months ago
Text
Got to look smart at work today by saying in a review that a mutex should’ve been a reader-writer lock to prevent write starvation. That should be enough job satisfaction to carry me a couple weeks.
32 notes · View notes
itsjunetime · 2 months ago
Text
tier list of rust std modules let's go
Tumblr media
Rationale below the break
S
clone: It’s so important. You gotta be able to clone data around, and you gotta be able to restrict that ability. Crucial
collections: I use this every-fucking-where. Gotta have my HashSet, gotta have by BTreeMap. You know it
future: Love writing futures, love constraining futures, love all of that. And I gotta have that Future trait.
iter: Literally #1 - fucking love my iterations, wish I could write literally everything as an Iterator
option: Option is so fundamental. So many helper methods on it as well, beautiful functionality
ptr: If you’ve ever written complex ffi bindings or collections replacements, you know what I mean. The documentation is phenomenal and only getting better, the provenance projects are making it even even better.
result: Same rationale as option
sync: Arc my beloved. Also channels, mutexes, RwLocks, Atomics, etc, are all so important. Can’t do anything in multi-threaded code without using at least one of them.
vec: We all love Vec. I don’t think I need to explain myself.
A
alloc: Pretty cool and good, would love to see the allocator API stablized and then this would easily be an S tier
array: Manipulating arrays is very nice and good and useful, I just don’t don’t do it enough to put this in S
boxed: Love Box! Really nice and useful. Not something you’ll use in your every-day rust app, though, you only start using it once you’re really getting into the weeds or interacting with futures outside of async/await
cell: Very important to a lot of underlying abstractions in Rust, but just not something most people will really ever use (at least in my experience)
cmp: Useful utilities. Love the way they’re integrated with the langauge operators. V cool.
convert: Also useful! Love my (Try)?(From|Into)
default: Useful sometimes, but I feel like it’s abused occasionally. Also not a fan of seeing Default::default() where someone could’ve used the type name
fs: Gotta interact with a filesystem. Just feel like most rust apps spend most of their time not interacting with a filesystem.
marker: Very important, but most people won’t be interacting with these again.
mem: Love these, very useful, but mostly only useful for specific scenarios.
ops: Hugely important as well, obviously, but most people won’t ever actually manually access this module.
slice: Love manipulating slices - getting chunks, windows
B
borrow: Love Cow, but the whole Borrow vs AsRef thing still confuses me. I understand how they’re different, but I don’t quite understand the historical and tehcnical reasons for it, and feel like there could’ve been a better solution found to avoid this.
arch: Cool and such, but rarely used and a lot of the coolest stuff (portable simd) is still experimental and I rely on it a lot for performance reasons and really want it to stabilize soon.
error: std::error::Error. Woohoo
fmt: Nifty and such. It’s just kinda boring in comparison to all the other cool language features that exist in the standard library.
io: Cool, I guess. I just rarely every use it directly, I guess. And I am also kinda annoyed that AsyncRead and AsyncWrite aren’t things but also I think that the Async variants of traits could be avoided if people wrote more libraries in the sans-io style, so idk
panic: Mmm. I’m glad that the language provides a way for you to clean up during a panic, but I am personally really annoyed that panics are, in the end, recoverable. Irks me.
path: Path and PathBuf woohoo. Also tho such a pity that this module has to be a lot more complex due to windows backwards path separator bullshit. ugh
rc: Rc. Woohoo. I don’t like Rc much personally, I’ve written a lot of code in Rust and I’ve yet to encounter a scenario where I think “This situation could be solved or even helped by an Rc!”. But I understand its uses I guess.
str and String: Useful, yeah, but I’ll always be a bit pissed that they didn’t call them String and StringBuf instead (like they did with Path and PathBuf). Causes way too much confusion to early-on rust users
task: Useful, but I don’t get why they aren’t in future instead. Like, I guess they are used for streams and such, but still.
time: Fine… I guess it’s useful for people to be able to measure elapsed durations for logging and such and easy benchmarking but I just have a natural, deep-seated fear of any computer code that tries to interact with time as a concept so I’m very leery of this.
C
any: Mmmmmm I know it’s useful but I kinda hate that dyn Any is a thing you can do. It should (hopefully) become somewhat less prevalent now that trait upcasting is stabilized, though.
env: Used to be higher, but the whole ‘Linux makes no guarantees about accessing the environment from multiple threads’ thing irks me. I know it’s not Rust’s fault, but I’m still punishing them for it.
ffi: Confuses me that there’s so much duplication between this and os::raw - don’t like it. I know it doesn’t really matter which one you use, but whatever.
hash: Rarely actually interact with it directly. I know that it has to exist to facilitate (Hash|BTree)(Map|Set) but I don’t know what other use it has
net: Nearly all the time that I want to interact with stuff like TcpStream, I would rather use some async-specific net structs, such as are found in tokio.
num: Useful and cool, but I really think that this is seriously missing the traits from the num crate. There’s probably some specific reason why they don’t want to provide this, but the ability to reason around numeric attributes would be so useful.
os: OsStr and OsString suffer from the same sin as str vs String, but also are just inherently confusing due to the complexity that surrounds file paths in different OSes. I know that rust just surfaces all this complexity that hides beneath the surface but that doesn’t keep me from feeling like there was probably some better way to set up these structs
process: std::process::exit. woohoo
thread: Rarely do I spawn a thread manually - generally I want to use tokio or rayon or crossbeam or something like that. Good and useful, just rarely reached to and generally you’d be better off touching something else
D
backtrace: Good for one thing alone, which can be nice for quick and easy debugging, but if you just want a backtrace, a panic!() is easier, and if you can’t do that for whatever reason, you should probably just reach for a full debugger at that point
hint: Just like compiler fuckery. Love it, I do, but rarely do people interact with it, if ever, and really only useful for benchmarks and low-level atomic stuff (which, when I’ve done that, idk if I’ve even seen any sort of performance gains from spin_loop() sooo)
pin: Yes it’s important, but the constant struggle to make it not horrible to use for library developers really irks me. Still no way to (safely) match on pinned enums, no built-in pin projection without macros, etc. Ugh.
prelude: Yeah sure, whatever. You’ll never touch this.
primitive: This does need to exist, but if you’re reaching for this, you’ve fucked up. What are you doing.
F
ascii: I feel like this was a mistake. There are 4 things in it and 2 of them are deprecated. What are we doing.
char: Too many weird things here. Why does to_lowercase return an iterator? Why are these constants not in the primitive type instead? The whole escape stuff also feels arbitrary, and that’s part of the sin of the ascii mod.
f32 and f64: Everything here should be relegated to the primitive types. No need for these. Why are the integer types deprecated while this one isn’t? idk
(I also posted basically this exact same thing on my blog, june.cat, if that sort of thing interests you :))
6 notes · View notes
digitalthinkerhelp · 1 year ago
Text
Mutex Vs Semaphore | Difference Between Semaphore and Mutex
Tumblr media
Hello Friends! Today, here we will explain about key difference between Semaphore and Mutex in OS as well as Mutex Vs Semaphore in tabular comparisons with ease. This is unique post over the Internet. Making ensure that after reading this content; you will definitely fully aware about Mutex Vs Semaphore in Operating System without getting any hindrance.
0 notes
jacob-cs · 2 years ago
Text
RUST 100-112 in english
lifetime
Tumblr media
위에서 my_string은 lifetime specifier가 설정되어있지 않아서 문제
Tumblr media
static으로 lifetime으로 해도 my_string은 함수내에서만 존재하므로 문제발생
Tumblr media Tumblr media
위는 작동하는 코드
Tumblr media
위는 작동하는 코드
Tumblr media
위는 작동하지 않는 코드
Tumblr media
1 각각의 파라미터는 각각의 lifetime을 가지나 보통은 하나로 통일해서 사용하는 경우가 많다
2. 파라미터가 하나고 reference 리턴이 하나 있는 경우. 하나의 lifetime으로 컴파일러가 간주 처리한다
3. 여러 파라미터중 &self , &mut self가 있는 경우 lifetime self가 적용된 
Tumblr media
위 틀린 코드
Tumblr media
위 맞는 코드. 아래와 같이 축약도 가능하다
anonymous lifetime
Tumblr media
위 맞는 코드
Tumblr media
위 맞는 코드
Tumblr media
위 맞는 코드
interior mutability
Tumblr media Tumblr media Tumblr media
위 맞는 코드
RefCell
Tumblr media
위 맞는 코드
Tumblr media
위 mutable reference를 두번 borrow하려고 해서 패닉
그리고 Cell, RefCell은 런타임에서 다이나믹하게 처리된다
Tumblr media Tumblr media
빌린 reference를 통해서는 값을 볼수 있지만 빌려진 원래 변수를 통해서는 값을 확인할수 없는 것에 유의
Tumblr media
above , after drop we can see value through variable which was borrowed
Tumblr media
위위  drop을 이용하는 방법이 번거로운 경우 위 같이 좀더 간단하게 사용할수 있다
Tumblr media Tumblr media
Cell에서 take는 값을 take하고 Cell안은 default 값으로 남기는 것이
Mutex
Tumblr media
Mutex를 통해 interior mutability를 구현할수 있다. Mutex와 thread와 같이 사용해도 안전하다. lock() 하면 다른 곳에서 접근 불가하다
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
위 패닉이 발생할것으로 보이지만 실상은 timeout이 되버린다.
처음 lock하고 다음에서 lock하려고 계속 기다리게 된다
Tumblr media
위 첫번째 lock에서 lock되고 try_lock()에서는 값변경이 이루어지지않는다
Tumblr media
첫번째 lock이후 drop이 되고 try_lock()이 실행되고 값이 변경되고 변수에 저장한게 아니므로 작업후 바로 lock 이 풀린다. 그리고 출력하면 lock된 상태가 아니고 변경된 값은 변경된게 출력된다.
RwLock 
read write lock
Tumblr media
위는 Mutex를 사용한 경우 아래는 RwLock을 사용한 경우 
둘은 매우 비슷하다
Tumblr media Tumblr media
Cow
Tumblr media
vector slice
Tumblr media Tumblr media
0 notes
the-lewd-bot-backup · 8 months ago
Text
i don't even need ropes to tie you up, little bot. i can have you on your knees with a handful of mutexes, spin-locked, cpus pinned and fans whirling
10 notes · View notes
fedfer · 12 days ago
Text
Ok so I'm going insane
I've been developing a simple image viewer in Rust, except it can also view animated images like GIFs!
...I feel like the situation has slightly gotten out of hand, I am now for some reason handling multiple threads and learning about Mutexes and other scary things. I am scared please help I am fucking up
3 notes · View notes
aurock · 1 month ago
Text
Let's Talk Locks (and Chopsticks!): Diving into the Dining Philosophers Problem
Heyyyy,
So, I'm super excited to start diving into some classic computer science concepts here, especially those that pop up in the world of Linux and concurrent programming. And what better place to start than with the fascinating (and sometimes frustrating!) Dining Philosophers Problem (I learned it about two days ago so please be patient :P).
Tumblr media
Think about it: a group of philosophers are sitting around a circular table. In front of each philosopher is a bowl of delicious spaghetti. To eat (somehow) a philosopher needs two chopsticks – one to their left and one to their right. However, there's only one chopstick between each pair of philosophers.
The philosophers have a simple life cycle: they think, they get hungry, they try to pick up their chopsticks, they eat, and then they put the chopsticks down and go back to thinking.
The tricky part arises when multiple philosophers get hungry at the same time. If everyone picks up their left chopstick simultaneously, no one can pick up their right chopstick! They all end up waiting indefinitely, holding one chopstick and starving. This, my friends, is a classic example of a deadlock (and I'm not talking about Valorant's agent ;) ).
Now, why is this relevant to Linux and programming?
Well, the Dining Philosophers Problem is a great analogy for common issues we face when dealing with concurrent processes or threads that need to access shared resources (like those chopsticks!). Chopsticks represent shared resources: Think of these as locks, mutexes, semaphores, or any other mechanism used to control access to critical sections of code (I'm going to talk about those in another posts). Philosophers represent processes or threads: These are the independent units of execution trying to use the shared resources.
The act of picking up chopsticks represents acquiring locks: A process needs to acquire the necessary locks before it can proceed with its task (eating). Deadlock in the problem mirrors deadlock in programs: Just like the philosophers can get stuck waiting for each other's chopsticks, threads can get stuck waiting for locks held by other threads, leading to a program freeze (don't try it at home).
There are several interesting ways to approach solving the Dining Philosophers Problem (and preventing deadlocks in our programs!). Some common strategies include: Introducing a resource hierarchy: Making philosophers pick up chopsticks in a specific order. Allowing a philosopher to pick up both chopsticks only if both are available. Introducing a central coordinator. Limiting the number of philosophers trying to eat at the same time.
What are your initial thoughts on the Dining Philosophers Problem?
Have you encountered similar deadlock situations in your own programming projects? Let me know!
I'm planning on diving deeper into some of the solutions in future posts ;)
6 notes · View notes
seths-heart · 6 months ago
Text
Ok so let me see if I understand this. So the mutex type, meant to make sure that Two threads don't touch the same shared data at once... can't be passed to multiple threads? It needs another type as a wrapper on it?? Why Rust????
2 notes · View notes