Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

msvc wrt locking errors...

31 views
Skip to first unread message

Chris M. Thomasson

unread,
Feb 6, 2024, 2:10:35 AMFeb 6
to
This is not giving me a warning, but an assertion. I am still wondering
why Bonita has to suppress all of those warnings wrt this thread ala MSVC:

https://groups.google.com/g/comp.lang.c++/c/pFsb3JI11-k

Here is some bugged code I just created, wrt MSVC version 17.8.5. No
warnings, but an assertion:

https://i.ibb.co/QQFyZQq/image.png

code:
____________________________________
#include <iostream>
#include <functional>
#include <thread>
#include <mutex>


namespace ct
{
struct mutex_test
{
std::mutex m_mutex;

void
works()
{
m_mutex.lock();
m_mutex.unlock();
}


void
foobar()
{
m_mutex.lock();
//m_mutex.unlock(); YIKES!
}
};
}


int
main()
{
std::cout << "ct_threads... ;^)\n" << std::endl;

{
ct::mutex_test test;

test.works();
test.foobar(); // humm... Kabboom!
}

return 0;
}
____________________________________


Btw, I am going to port my new XCHG based code from Relacy race detector
into actual C++ code where we all can play with it. Getting to a point
where I need to use it for a project.

Chris M. Thomasson

unread,
Feb 6, 2024, 3:34:14 AMFeb 6
to
On 2/5/2024 11:10 PM, Chris M. Thomasson wrote:
> This is not giving me a warning, but an assertion. I am still wondering
> why Bonita has to suppress all of those warnings wrt this thread ala MSVC:
>
> https://groups.google.com/g/comp.lang.c++/c/pFsb3JI11-k
[...]

Sometime tomorrow I can work on this. I need to compile the bugged test
code with the warning level bumped up.

Chris M. Thomasson

unread,
Feb 7, 2024, 3:47:52 PMFeb 7
to
On 2/5/2024 11:10 PM, Chris M. Thomasson wrote:
> This is not giving me a warning, but an assertion. I am still wondering
> why Bonita has to suppress all of those warnings wrt this thread ala MSVC:
>
> https://groups.google.com/g/comp.lang.c++/c/pFsb3JI11-k
[...]

Okay, made some progress. Here is a little example of where the warnings
pop up. "Sketchy" use of std::unique_lock, well, imvvho that is:
___________________________________________
#include <iostream>
#include <functional>
#include <thread>
#include <mutex>
#include <cassert>


namespace ct
{
struct mutex_test
{
std::mutex m_mutex;

void
bar(std::unique_lock<std::mutex>& lock)
{
assert(lock);
lock.unlock();
}

void
foo()
{
std::unique_lock<std::mutex> lock(m_mutex);

// lock will be unlocked after this call!
bar(lock);

lock.lock(); // Yup...
}
};
}


int
main()
{
std::cout << "ct_threads... ;^)\n" << std::endl;

{
ct::mutex_test test;

test.foo();
}

return 0;
}
___________________________________________


Interesting wrt MSVC.
0 new messages