Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost mutex error when using SimpleActionClient with std::unique_ptr #143

Open
rcywongaa opened this issue Jun 25, 2019 · 0 comments
Open

Comments

@rcywongaa
Copy link

Tested with ROS Melodic
The minimal example that reproduces the issue (modified from this example) is as follows

#include <memory>
#include <gtest/gtest.h>
#include <actionlib/TestAction.h>
#include <actionlib/client/simple_action_client.h>

using namespace actionlib;

std::unique_ptr<SimpleActionClient<TestAction>> client;

TEST(SimpleClient, easy_wait_test)
{

  bool started = client->waitForServer(ros::Duration(10.0));
  ASSERT_TRUE(started);

  TestGoal goal;
  SimpleClientGoalState state(SimpleClientGoalState::LOST);

  goal.goal = 1;
  state = client->sendGoalAndWait(goal, ros::Duration(10,0), ros::Duration(10,0));
  EXPECT_TRUE( state == SimpleClientGoalState::SUCCEEDED)
    << "Expected [SUCCEEDED], but goal state is [" << client->getState().toString() << "]";

  goal.goal = 4;
  state = client->sendGoalAndWait(goal, ros::Duration(2,0), ros::Duration(1,0));
  EXPECT_TRUE( state == SimpleClientGoalState::PREEMPTED)
    << "Expected [PREEMPTED], but goal state is [" << client->getState().toString() << "]";
}

void spinThread()
{
  ros::NodeHandle nh;
  ros::spin();
}

int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);

  ros::init(argc, argv, "simple_client_test");

  client = std::unique_ptr<SimpleActionClient<TestAction>>(new SimpleActionClient<TestAction>("/my_action", true));

  boost::thread spin_thread(&spinThread);

  int result = RUN_ALL_TESTS();

  ros::shutdown();

  spin_thread.join();

  return result;
}

The error message (regardless of whether or not the tests succeed):

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
  what():  boost: mutex lock failed in pthread_mutex_lock: Invalid argument

link to answers.ros question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant