You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2015/07/30 00:45:12 UTC
mesos git commit: Used std::thread instead of pthread for Long Lived
Executor.
Repository: mesos
Updated Branches:
refs/heads/master 2c38f201f -> 8727301d3
Used std::thread instead of pthread for Long Lived Executor.
Review: https://reviews.apache.org/r/36822
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8727301d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8727301d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8727301d
Branch: refs/heads/master
Commit: 8727301d3c00a8f93b32a36737d5244307ea3834
Parents: 2c38f20
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jul 29 15:45:03 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 29 15:45:03 2015 -0700
----------------------------------------------------------------------
src/examples/long_lived_executor.cpp | 35 ++++++++-----------------------
1 file changed, 9 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/8727301d/src/examples/long_lived_executor.cpp
----------------------------------------------------------------------
diff --git a/src/examples/long_lived_executor.cpp b/src/examples/long_lived_executor.cpp
index d9b7fa1..c6ea6b5 100644
--- a/src/examples/long_lived_executor.cpp
+++ b/src/examples/long_lived_executor.cpp
@@ -16,11 +16,11 @@
* limitations under the License.
*/
-#include <pthread.h>
#include <stdlib.h> // For random.
#include <cstdlib>
#include <iostream>
+#include <thread>
#include <mesos/executor.hpp>
@@ -47,15 +47,6 @@ void run(ExecutorDriver* driver, const TaskInfo& task)
}
-void* start(void* arg)
-{
- lambda::function<void(void)>* thunk = (lambda::function<void(void)>*) arg;
- (*thunk)();
- delete thunk;
- return NULL;
-}
-
-
class LongLivedExecutor : public Executor
{
public:
@@ -81,25 +72,17 @@ public:
{
cout << "Starting task " << task.task_id().value() << endl;
- lambda::function<void(void)>* thunk =
- new lambda::function<void(void)>(lambda::bind(&run, driver, task));
-
- pthread_t pthread;
- if (pthread_create(&pthread, NULL, &start, thunk) != 0) {
- TaskStatus status;
- status.mutable_task_id()->MergeFrom(task.task_id());
- status.set_state(TASK_FAILED);
+ std::thread* thread = new std::thread([=]() {
+ run(driver, task);
+ });
- driver->sendStatusUpdate(status);
- } else {
- pthread_detach(pthread);
+ thread->detach();
- TaskStatus status;
- status.mutable_task_id()->MergeFrom(task.task_id());
- status.set_state(TASK_RUNNING);
+ TaskStatus status;
+ status.mutable_task_id()->MergeFrom(task.task_id());
+ status.set_state(TASK_RUNNING);
- driver->sendStatusUpdate(status);
- }
+ driver->sendStatusUpdate(status);
}
virtual void killTask(ExecutorDriver* driver, const TaskID& taskId) {}