Skip to main content

What is the purpose of a mutex or semaphore in multi-threading?

Expert C#
Quick Answer Mutex allows only one thread (or process) at a time to access a resource รขโ‚ฌโ€ useful for cross-process locking. Semaphore limits concurrent access to N threads at once รขโ‚ฌโ€ useful for rate-limiting or connection pools. Both block waiting threads; overusing them causes contention and performance issues.

Answer

Mutex allows exclusive access to a resource; Semaphore limits concurrent access.

Both prevent race conditions but may cause contention when misused.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice