Commit 5cef3fbd authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

fixed bug happening when finalize is called before destructor of engine

parent cebb346a
......@@ -4,7 +4,7 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
return 0;
}
......@@ -5,7 +5,7 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
return 0;
......
......@@ -4,9 +4,13 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure hello = myEngine.define("hello").ignore_response();
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server = myEngine.lookup(argv[1]);
hello.on(server)();
return 0;
......
......@@ -9,7 +9,8 @@ void hello(const tl::request& req) {
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
myEngine.define("hello", hello).ignore_response();
return 0;
......
......@@ -4,10 +4,13 @@
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure sum = myEngine.define("sum");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server = myEngine.lookup(argv[1]);
int ret = sum.on(server)(42,63);
std::cout << "Server answered " << ret << std::endl;
......
......@@ -10,7 +10,8 @@ void sum(const tl::request& req, int x, int y) {
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
myEngine.define("sum", sum);
return 0;
......
......@@ -4,10 +4,13 @@
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure sum = myEngine.define("sum");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server = myEngine.lookup(argv[1]);
int ret = sum.on(server)(42,63);
std::cout << "Server answered " << ret << std::endl;
......
......@@ -5,7 +5,8 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
std::function<void(const tl::request&, int, int)> sum =
[](const tl::request& req, int x, int y) {
......
......@@ -4,10 +4,13 @@
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure sum = myEngine.define("sum");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server = myEngine.lookup(argv[1]);
int ret = sum.on(server)(42,63);
std::cout << "Server answered " << ret << std::endl;
......
......@@ -5,7 +5,8 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
std::function<void(const tl::request&, int, int)> sum =
[&myEngine](const tl::request& req, int x, int y) {
......
......@@ -5,10 +5,13 @@
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure hello = myEngine.define("hello").ignore_response();
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server = myEngine.lookup(argv[1]);
std::string name = "Matthieu";
hello.on(server)(name);
......
......@@ -11,7 +11,8 @@ void hello(const tl::request& req, const std::string& name) {
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
myEngine.define("hello", hello).ignore_response();
return 0;
......
......@@ -5,10 +5,13 @@
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure dot_product = myEngine.define("dot_product");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server = myEngine.lookup(argv[1]);
point p(1,2,3);
point q(5,2,4);
double ret = dot_product.on(server)(p,q);
......
......@@ -6,7 +6,8 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
std::function<void(const tl::request&, const point&, const point&)> dot_product =
[&myEngine](const tl::request& req, const point& p, const point& q) {
......
......@@ -4,10 +4,13 @@
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", MARGO_CLIENT_MODE);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
exit(0);
}
tl::engine myEngine("tcp", MARGO_CLIENT_MODE);
tl::remote_procedure remote_do_rdma = myEngine.define("do_rdma").ignore_response();
tl::endpoint server_endpoint = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
tl::endpoint server_endpoint = myEngine.lookup(argv[1]);
std::string buffer = "Matthieu";
std::vector<std::pair<void*,std::size_t>> segments(1);
......
......@@ -6,7 +6,8 @@ namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << (std::string)myEngine.self() << std::endl;
std::function<void(const tl::request&, tl::bulk&)> f =
[&myEngine](const tl::request& req, tl::bulk& b) {
......
......@@ -10,6 +10,7 @@
#include <string>
#include <functional>
#include <unordered_map>
#include <atomic>
#include <margo.h>
#include <thallium/tuple_util.hpp>
#include <thallium/function_cast.hpp>
......@@ -50,6 +51,7 @@ private:
std::unordered_map<hg_id_t, rpc_t> m_rpcs;
bool m_is_server;
bool m_owns_mid;
std::atomic<bool> m_finalize_called;
/**
* @brief Encapsulation of some data needed by RPC callbacks
......@@ -126,6 +128,11 @@ private:
return HG_SUCCESS;
}
static void on_finalize(void* arg) {
engine* e = static_cast<engine*>(arg);
e->m_finalize_called = true;
}
public:
/**
......@@ -142,12 +149,14 @@ public:
std::int32_t rpc_thread_count = 0) {
m_is_server = (mode == THALLIUM_SERVER_MODE);
m_finalize_called = false;
m_mid = margo_init(addr.c_str(), mode,
use_progress_thread ? 1 : 0,
rpc_thread_count);
// XXX throw an exception if m_mid not initialized
m_owns_mid = true;
margo_push_finalize_callback(m_mid,
&engine::on_finalize, static_cast<void*>(this));
}
engine(margo_instance_id mid, int mode) {
......@@ -183,7 +192,8 @@ public:
~engine() throw(margo_exception) {
if(m_owns_mid) {
if(m_is_server) {
margo_wait_for_finalize(m_mid);
if(!m_finalize_called)
margo_wait_for_finalize(m_mid);
} else {
margo_finalize(m_mid);
}
......
......@@ -5,14 +5,18 @@
# list of source files
set(thallium-src bulk.cpp
callable_remote_procedure.cpp
endpoint.cpp
engine.cpp
margo_exception.cpp
pool.cpp
proc_buffer.cpp
remote_procedure.cpp
request.cpp
remote_bulk.cpp
callable_remote_procedure.cpp
margo_exception.cpp
proc_buffer.cpp)
scheduler.cpp
task.cpp
thread.cpp)
# load package helper for generating cmake CONFIG packages
include (CMakePackageConfigHelpers)
......
......@@ -8,13 +8,13 @@
namespace tl = thallium;
int client() {
int client(const char* addr) {
tl::engine margo("bmi+tcp", MARGO_CLIENT_MODE);
tl::engine margo("tcp", MARGO_CLIENT_MODE);
auto remote_hello = margo.define("hello").ignore_response();
auto remote_sum = margo.define("sum");
auto remote_stop = margo.define("stop").ignore_response();
std::string server_addr = "bmi+tcp://127.0.0.1:1234";
std::string server_addr = addr;
sleep(1);
auto server_endpoint = margo.lookup(server_addr);
......@@ -32,6 +32,10 @@ int client() {
}
int main(int argc, char** argv) {
client();
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <addr>" << std::endl;
exit(0);
}
client(argv[1]);
return 0;
}
......@@ -14,8 +14,9 @@ void hello(const tl::request& req, const std::string& name) {
int server() {
tl::engine margo("bmi+tcp://127.0.0.1:1234", MARGO_SERVER_MODE);
margo.define("hello", hello).ignore_response();
tl::engine margo("tcp", MARGO_SERVER_MODE);
margo.define("hello", hello).ignore_response();
std::function<void(const tl::request&, int, int)> f =
[](const tl::request& req, int x, int y) {
......@@ -31,7 +32,7 @@ int server() {
};
margo.define("stop", g);
std::string addr = margo.self();
std::string addr = margo.self();
std::cout << "Server running at address " << addr << std::endl;
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment