$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] Q: N00b spinlock
From: Moritz Moeller (boost_at_[hidden])
Date: 2010-01-20 22:00:35
I'm new to multi-threaded programming. So I apologize for aksing what is
possibly a silly question.
Will below code give me the behaviour of what is commonly called a
"spinlock"?
boost::unique_lock< boost::shared_mutex >
guard( mutex, boost::try_to_lock );
if ( !guard.owns_lock() ) {
while ( !guard.try_lock() ) {
boost::thread::yield();
}
}
// access data
Cheers,
Moritz