Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bobjtowers

Pages: [1]
1
General Discussion about just::thread / Re: mutex as class member
« on: December 14, 2010, 04:55:11 AM »
It does help, thanks for replying :)

This issue of the non-copy mutex really interests me.
I can't help wondering why it is non-copyable.
Is this issue to do with whether the mutex would be a deep vs shallow copy of the mutex ?
What danger or mischief is prevented by making a mutex non-copyable ?

Java has a unique intrinsic lock built into every object of every class.
To the best of knowledge, there are no special hazards associated with this scenario.
(but of-course, i don't know, what i don't know)

Rob.

2
General Discussion about just::thread / mutex as class member
« on: December 13, 2010, 08:09:17 AM »
hi there,

consider this simple class (shown below)

It's just a callable functor class, implementing the func. call operator.
I find that when i declare a mutex inside this class, the compiler curses me...
.. uttering words like:

/usr/include/justthread/mutex: In copy constructor ‘functor::functor(const functor&)’:
threadId.cxx:19:   instantiated from ‘__jss::__0x::__invoker<_ResultType, _Callable, _Args>::__invoker(_Callable&, const __jss::__0x::__args_tuple<_OtherArgs ...>&) [with _OtherArgs = , _ResultType = void, _Callable = functor&, _Args = ]’

When i make the mutex global (line 17).. the code compiles and runs as expected.
I also tried wrapping the mutex in a unique_lock.  But ... no joy.

Is it not possible to define a mutex as a class member ?
Any suggestions.. warmly welcomed :)

Rob.


 17 // mutex m;
 18
 19 class functor {
 20     mutex m;
 21     // unique_lock<mutex> m;
 22 public:
 23     void operator()() {
 24         int loopCtr = 0;
 25         while (++loopCtr < 20){
 26             getThreadId(loopCtr);
 27         }
 28     }
 29     functor(){}
 30 private:
 31     void getThreadId(const int ctr){
 32         m.lock();
 33         try {
 34             thread::id thisThread = this_thread::get_id();
 35             cout << ctr << " - thisThread=" << thisThread << endl;
 36             m.unlock();
 37         } catch (...) {
 38             m.unlock();
 39         }
 40     }
 41 };

Pages: [1]