Question: Am new to C++ 11 and using threading. I came across a scenario where it's not possible to copy mutex & condition variable objects. The code is like this....

```
class producer {

   public: 
      producer(mutex m, condition_variable cv) 
      {
           mut = m;    // ERROR
           cvar = cv;   // ERROR
       }

    private:
         mutex mut;
         condition_variable cvar;
}

```

When trying to copy the variables in constructor it's giving the error. Seems like copy constructor is set to delete for mutex and cv.

Is there a way to overcome that? I want a producer & consumer class and then pass the mutex & cv from the **main** function.

so basically the call from main function should look like....

```
int main ()
{
    mutex m;
    condition_variable cv;
    //Initialize mutex & cv
    producer prod(m, cv);
}

```

Answer: 
No this is not possible. Features were added in C++ to enable this feature (non copying).

If you think about the implementation are you changing somekind of kernel object? Will that be the same. Probably not. This is by design.
You'll want to store references or pointers to the `mutex` and `condition_variable`.

```
class producer {
public: 
  producer(mutex & m, condition_variable & cv) 
    : _mut{m}
    , _cvar{cv}
  {
  }

private:
     mutex & mut;
     condition_variable & cvar;
};

```

You could use `std::shared_ptr`s, since that lets your instances have strong ownership of the `mutex` and `condition_variable`, but this was faster to type.