Questions tagged [scoped-lock]
29 questions
1
vote
1 answer
Will boost::recursive_mutex::scoped_locks destructor reference an unlocked mutex?
After calling unlock() on a boost::recursive_mutex::scoped_lock, will the lock object reference the mutex somehow in its destructor?
The lock still retains a reference to the mutex after the call to unlock (ie. mutex() returns the same pointer).…

Viktor
- 3,295
- 2
- 25
- 26
1
vote
2 answers
Unexplained behavior boost::scoped_lock
I am wrote on C++ multithread TCP server, for synchronization using boost:scoped_lock
After connecting to server client freezes.
in gdb i saw more threads in pthread_kill after call boost::mutex::lock
(gdb) info thread
277 Thread 808779c00 (LWP…

Nikola
- 61
- 5
1
vote
1 answer
C++ boost thread and mutex
I just started on boost. I would like to ask if my code uses mutex well.
To test it I wrote code which counts sum of numbers 1 to n. Silly way to count it but I used n threads... just to try mutex...
#include
#include…

ST3
- 8,826
- 3
- 68
- 92
1
vote
1 answer
Check optional mutex before scoped locking
I have a constructor that optionally allows the user to pass a ponter to a Boost mutex. If no mutex is supplied, the member pointer pMyMutex is set to NULL. This gives the user the option of applying some thread safety if they wish. However, I…

learnvst
- 15,455
- 16
- 74
- 121
0
votes
1 answer
scoped_lock inside lock_guard, is it redundant?
I'm new in multi-thread programming.
I'm now doing a serial port communication project, and search related codes for reference.
I found a code that someone used scoped_lock inside lock_guard as below:
void B(){
boost::mutex::scoped_lock…

RyanChen.YLC
- 57
- 7
0
votes
0 answers
C++ std::scoped_lock allows nesting
#include
#include
using namespace std;
class TestClass {
public : // members
std::mutex m_mutex;
int m_var;
public : //functions
TestClass()
:m_var(0) {};
void fooIncVar()
…

hemanths
- 61
- 5
0
votes
1 answer
Why c++11 std::lock and std::scoped_lock need at least 2 parameters?
Just found that these 2 utils needs at least 2 parameters, e.g. 2 mutex to lock.
Needs to be like this(from cppreference.com):
void assign_lunch_partner(Employee &e1, Employee &e2)
{
static std::mutex io_mutex;
{
…

Troskyvs
- 7,537
- 7
- 47
- 115
0
votes
0 answers
Can compiled reorder operations when std::scoped_lock is used inside new scope
Is it possible that compiler can reorder operations before and after the lock, when locking is done in new scope?
For example:
std::cout << "started from ...
std::cout << "exited from ...
locking
or:
locking
std::cout << "started from ...
std::cout…

pidgun
- 113
- 6
0
votes
0 answers
Running a packaged_task after extracting it from a queue in mutual exclusion using a scoped_lock
I need to execute an extracted task from a queue after locking two mutex using a scoped_lock, the problem is to swap a task from a queue to another one and then execute it. So far this is my starting point
std::packaged_task task;
…

Antonio Santoro
- 827
- 1
- 11
- 29
0
votes
1 answer
boost::scoped_lock not working (for me)
I am extending a code base,Have a look at the following code snippet taken out of a class. I made it as simple as possible not to confuse you:
std::queue< boost::shared_ptr > _container;
boost::mutex _mutex;
//...
void foo(Item *item)
{
…

rahman
- 4,820
- 16
- 52
- 86
0
votes
0 answers
when will a std::lock_guard got locked?
I have the following codes. I wonder that whether the scoped lock got locked at the beginning of function "do_something"? Thanks very much!
class Test {
public:
void do_something () {
std::cout << "anything printable" << std::endl;
…

wakensky
- 43
- 1
- 2
0
votes
1 answer
creating scoped_lock for 200 ms max
I am trying to create a timed scoped lock on mutex. I thought following api from boost could help but I am having hard time finding some sample code as reference to use it.
scoped_lock(mutex_type & m, const boost::posix_time::ptime & abs_time);
I…

RLT
- 4,219
- 4
- 37
- 91
0
votes
1 answer
Memory leak caused by a wrong usage of scoped_lock?
I have a memory leak, and I guess it's caused by a wrong usage of scoped_lock (Boost). I however don't manage to find the exact problem, and I do believe that the way the code has been written is not completely right neither.
The code is in this…

TigrouMeow
- 3,669
- 3
- 27
- 31
0
votes
1 answer
boost unable to move a scoped_lock with gcc
The following compiles under VS2010 (Express) but not gcc (4.6.2 here).
Lockable.h:
#include
#include
template
class LockedProxy : boost::noncopyable
{
public:
…

Gabriel
- 2,841
- 4
- 33
- 43