concurrency - boost::unique_lock/upgrade_to_unique_lock && boost::shared_lock can exist at the same time ? it worries me -
i did experiments boost::upgrade_to_unique_lock/unique_lock && boost::shared_lock, scenario is:
1 write thread, has boost::unique_lock existing boost::shared_mutex, in thread, write global aclass
3 read thread, each 1 has boost::shared_lock same boost:;shrared_mutex, have loop read global aclass
i observed threads holding locks( 1 unique, 3 shared ) @ same time, , running data access loops.
my concern aclass not thread-safe, if can read/write @ same time in different threads, read crash. it's not aclass, use primitive types, reading them surely not crash, data dirty, isn't ?
boost::shared_lock<boost::shared_mutex>(gmutex); this not "unnamed lock." creates temporary shared_lock object locks gmutex, temporary shared_lock object destroyed, unlocking gmutex. need name object, making variable, example:
boost::shared_lock<boost::shared_mutex> my_awesome_lock(gmutex); my_awesome_lock destroyed @ end of block in declared, behavior want.
Comments
Post a Comment