-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1000 from kloudkl/boost-thread
Replace pthread with boost::thread
- Loading branch information
Showing
9 changed files
with
83 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "caffe/internal_thread.hpp" | ||
|
||
namespace caffe { | ||
|
||
InternalThread::~InternalThread() { | ||
WaitForInternalThreadToExit(); | ||
if (thread_ != NULL) { | ||
delete thread_; | ||
} | ||
} | ||
|
||
bool InternalThread::StartInternalThread() { | ||
try { | ||
thread_ = new boost::thread(&InternalThread::InternalThreadEntry, this); | ||
} catch (...) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** Will not return until the internal thread has exited. */ | ||
bool InternalThread::WaitForInternalThreadToExit() { | ||
if (is_started()) { | ||
try { | ||
thread_->join(); | ||
} catch (...) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace caffe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "glog/logging.h" | ||
#include "gtest/gtest.h" | ||
|
||
#include "caffe/internal_thread.hpp" | ||
|
||
#include "caffe/test/test_caffe_main.hpp" | ||
|
||
namespace caffe { | ||
|
||
|
||
class InternalThreadTest : public ::testing::Test {}; | ||
|
||
TEST_F(InternalThreadTest, TestStartAndExit) { | ||
InternalThread thread; | ||
EXPECT_FALSE(thread.is_started()); | ||
EXPECT_TRUE(thread.StartInternalThread()); | ||
EXPECT_TRUE(thread.is_started()); | ||
EXPECT_TRUE(thread.WaitForInternalThreadToExit()); | ||
EXPECT_FALSE(thread.is_started()); | ||
} | ||
|
||
} // namespace caffe | ||
|