Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:59:06+00:00 2026-05-26T10:59:06+00:00

I am constructing several objects from a Class and using a particular function from

  • 0

I am constructing several objects from a Class and using a particular function from these classes to start Threads. Now the Class containing the member function from where these objects are constructed, has a static private Mutex member. I am passing this static member to the constructors and inside each constructor, the passed Mutex(presumably by reference) is assigned to another local member.

If I then use each of these local Mutex member to ensure Thread safety, will I be able to achieve this? I am counting on the fact, no matter how many different instances of the object containing the Thread function exists, since they are all referring to the same Mutex object, Thread safety is ensure if properly used.

Please find below code snippet to represent the Idea:

Class ThreadClass
{
 private Mutex myCopyOfMutex;
public ThreadClass(Mutex _globalMutex)
{
 myCopyOfMutex = _globalMutex;
}
public ThreadFunction()
{

// Wait until it is safe to enter.
myCopyOfMutex.WaitOne();
// critical code

// Release the Mutex.
 myCopyOfMutex.ReleaseMutex();

}
}

Class MotherClass
{
  private static Mutex mut = new Mutex();

  ThreadClass one = new ThreadClass(mut); // first instance
  Threadclass two = new ThreadClass(mut); // second instance

// Assign the Thread function to run on separate Thread

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:59:07+00:00Added an answer on May 26, 2026 at 10:59 am

    Yes, it will work. No, it’s not passed by reference.

    There is an important difference between passing a reference and passing by reference.

    When you pass a reference type to a method, it’s normally passed as a reference:

    SomeMethod(mutex);
    

    To pass a parameter by reference, you use the ref keyword:

    SomeMethod(ref mutex);
    

    The parameter in the method signature also has to be declared using the ref keyword:

    public void SomeMethod(ref Mutex mutex) {
    

    Passing a variable by reference means that you pass a reference to the variable, not a copy of the reference that is contained in the variable. The method can then change the variable itself, not only the object that the reference points to.

    In most cases, and also in this case, you should pass parameters in the regular way. Passing by reference is only done when you need it for a specific reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have several objects within a class, each of which needs constructing with
I am constructing a search function in a class to be used by several
I have several string each containing a JSON representation of an array of objects.
An ethical question here. I'm planning on using several manager classes in my new
I am constructing a simple calculator using a form that requires selections from a
Given: Constructing an ADO Connection object from one thread and giving it to another
I am constructing a search page with a textbox and a button for now,
I'm constructing a method to take in an ArrayList(presumably full of objects) and then
I am constructing a large HTML document from fragments supplied by users that have
I am currently constructing a Carputer front end and one function that it needs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.