pthread_mutex_lock(&mutex_)failed with error 22

3,563 views
Skip to first unread message

Fu Jiantao

unread,
Apr 16, 2014, 12:57:47 AM4/16/14
to googl...@googlegroups.com, googl...@googlegroups.com
Hi,

I'm using gtest in iOS simluator env, and when using gmock, i
encounter such error,

[ FATAL ] /Users/jeromy/work/cisco/mari/adaptation_resilience/build/ios_sim/ThirdParty/src/gmock/gtest/include/gtest/internal/gtest-port.h:1340::
pthread_mutex_lock(&mutex_)failed with error 22

Seems it's relating to the use of gmock, other gtest code has no problem.

TEST(CBandwidthEvalInterfaceTest, AttachDetachMonitor)

{

NetworkMonitorMock monitor;

CBandwidthEvaluator bwEval(false);


EXPECT_CALL(monitor, RegisterSink(_)).Times(1).WillOnce(Return(true));

bool ret = bwEval.AttachNetworkMonitor(&monitor);

ASSERT_EQ(ret,true);
}

Any solutions?

Thanks

Jeromy

Fu Jiantao

unread,
Apr 16, 2014, 2:05:17 AM4/16/14
to googl...@googlegroups.com

Aaron McDaniel

unread,
May 5, 2014, 7:22:39 PM5/5/14
to googl...@googlegroups.com
I'm getting this same error, but on our iOS devices. Our tests passed on iOS before we updated to the latest GMock and GTest.

It happens whenever it tries to lock the mutex in the following line inside the MutexBase class defined in gtest-port.h:

GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));

The member variable mutex_ is not null.

Aaron McDaniel

unread,
May 7, 2014, 2:38:08 PM5/7/14
to googl...@googlegroups.com
Found the solution. In the test app that is linking with gmock, use the following preprocessor flag:

GTEST_HAS_PTHREAD=0

Fu Jiantao

unread,
May 8, 2014, 2:15:32 AM5/8/14
to Aaron McDaniel, googl...@googlegroups.com
Thanks Aaron, but what if in need thread in unit test, i think pthread
should be supported on both ios and android.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Google C++ Mocking Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to googlemock+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/googlemock/123f6337-3e1e-44fb-a263-daced307e4e8%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Aaron McDaniel

unread,
May 8, 2014, 2:51:20 AM5/8/14
to Fu Jiantao, googl...@googlegroups.com
It uses boost threading I believe. The above flag is needed for android builds as well. I believe the os prevents certain actions due to security concerns so this would not be possible to work around.
Reply all
Reply to author
Forward
0 new messages