---
title: "What is CMutex? How can we use it?"  
description: "What is CMutex? How can we use it?"  
author: "Anonymous User"  
published: 2012-08-17  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/1505/what-is-cmutex-how-can-we-use-it  
category: "visual c++"  
tags: ["visual c++", "c++", "c#", "mindstick", "interview question", "mutex", "cmutex"]  
reading_time: 2 minutes  

---

# What is CMutex? How can we use it?

**CMutex** is a **synchronization class** which uses synchronization object named as mutex. It allows multiple program thread can share the same resource by taking turns. At the starting of the program it creates a mutex at beginning and then a system gives a unique ID or name for it. After that, any thread which needs the resource can use the mutex to lock the resource.

For example; access of a file. To use CMutex, construct its object when it is needed to be accessed. Give the name of mutex and to the application will own it. You can access mutex when constructor returns again to the start. When you have done, accessing the controlled resource then call **CSyncObject::Unlock**.

## Answers

### Answer by Anonymous User

**CMutex** is a **synchronization class** which uses synchronization object named as mutex. It allows multiple program thread can share the same resource by taking turns. At the starting of the program it creates a mutex at beginning and then a system gives a unique ID or name for it. After that, any thread which needs the resource can use the mutex to lock the resource.

For example; access of a file. To use CMutex, construct its object when it is needed to be accessed. Give the name of mutex and to the application will own it. You can access mutex when constructor returns again to the start. When you have done, accessing the controlled resource then call **CSyncObject::Unlock**.


---

Original Source: https://www.mindstick.com/interview/1505/what-is-cmutex-how-can-we-use-it

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
