benchmark silo added
[c11concurrency-benchmarks.git] / silo / thread.cc
diff --git a/silo/thread.cc b/silo/thread.cc
new file mode 100644 (file)
index 0000000..d9f5bd7
--- /dev/null
@@ -0,0 +1,31 @@
+#include "macros.h"
+#include "thread.h"
+
+using namespace std;
+
+ndb_thread::~ndb_thread()
+{
+}
+
+void
+ndb_thread::start()
+{
+  thd_ = std::move(thread(&ndb_thread::run, this));
+  if (daemon_)
+    thd_.detach();
+}
+
+void
+ndb_thread::join()
+{
+  ALWAYS_ASSERT(!daemon_);
+  thd_.join();
+}
+
+// can be overloaded by subclasses
+void
+ndb_thread::run()
+{
+  ALWAYS_ASSERT(body_);
+  body_();
+}