Boost logo

Boost Users :

From: Sakharuk, Vlad \(GMI Development\) (Vlad_Sakharuk_at_[hidden])
Date: 2008-03-25 13:23:07


I think u are crashing not because of mutex.
The problem is here:
iter.next (...) != 0 ;

should be iter.next != ... end()

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Yasmina Berber
Sent: Tuesday, March 11, 2008 8:05 AM
To: boost-users_at_[hidden]
Subject: [Boost-users] [Mutex] behaviour??

Hi, everybody
I have a problem to understand mutex behaviour in a server client
program . basically there are two threads that execute different code in
two different classes but manipulate the same resource: fisrt Class is
Subscriber with these members :
 
public:
ACE_Unbounded_Set<client_reference> m_set;
 typedef boost::recursive_mutex Mutex;
 typedef boost::recursive_mutex::scoped_lock Lock;
 Mutex mutex_set;

and methods:
Subscribe (client_reference) : inserts (add) a reference client to the
set { ... Lock theScope( mutex_set); m_set.insert (client_reference)
  ...
}
Unsubscribe(client_reference) : removes a reference client from the set
{ ... Lock theScope( mutex_set); m_set.remove (client_reference) }

the second class is Manager that has a shared pointer to Subscriber
(SubscriberPtr) and does a specific opeartion on each client_reference
inside a for loop in the method
Manage()
{
boost::recursive_mutex::scoped_lock
scoped_lock(subscriberPtr->mutex_set)
  for (Subscriber::Set_Iterator iter (subscriberPtr->m_set); iter.next
(...) != 0 ; iter.advance ())
    {
       specific opeartion on each client reference
    }
}
What happens is that a client can be removed (call to Unsubscribe()) by
the first thread during the second one is executing manage() : the set
is not well protected and this causes of course seg fault.

I probably do something wrong,
If you need more details please let me know.
Regards.

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
--------------------------------------------------------

This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
--------------------------------------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net