So I have a program separated into 4 parts. I the first 3 parts I create 3 different shared dynamic libraries which I then use in the fourth part with dynamic loading.
In the 4th part I have program structure that roughly looks like this
.hpp
...
typedef Snake *(*SNAKE)(int, int);
typedef void (*DELETESNAKE)(Snake *);
...
SNAKE _snake;
std::map<int, void *> _handlers;
std::map<int, Snake *> _snakes;
std::map<int, std::string> _libs;
...
.cpp
...
_handlers[1] = dlopen("lib/libSnakeSFML.so", RTLD_LAZY | RTLD_LOCAL);
if (!_handlers[1])
throw NibblerExceptionE("dl_error : " + std::string(dlerror()));
_snake = reinterpret_cast<SNAKE>(dlsym(_handlers[1], "createSnake"));
if (!_snake)
throw NibblerExceptionE("Some snake Error");
_snakes[1] = _snake(_w, _h);
_snakes[1]->init();
_handlers[2] = dlopen("lib/libSnakeSDL.so", RTLD_LAZY | RTLD_LOCAL);
if (!_handlers[2])
throw NibblerExceptionE("dl_error : " + std::string(dlerror()));
_snake = reinterpret_cast<SNAKE>(dlsym(_handlers[2], "createSnake"));
if (!_snake)
throw NibblerExceptionE("Some snake Error");
_snakes[2] = _snake(_w, _h);
_snakes[2]->init();
_handlers[3] = dlopen("lib/libSnakeFLTK.so", RTLD_LAZY | RTLD_LOCAL);
if (!_handlers[3])
throw NibblerExceptionE("dl_error : " + std::string(dlerror()));
_snake = reinterpret_cast<SNAKE>(dlsym(_handlers[3], "createSnake"));
if (!_snake)
throw NibblerExceptionE("Some snake Error");
_snakes[3] = _snake(_w, _h);
_snakes[3]->init();
...
now when I try to call any of the _snakes[...]
methods on the fly, the last handle, which in this case is FLTK
, seems to be used. From some research I did, It seems like you can only have one handle in a thread. I'm not sure it I'm saying that correctly, but if I am. How do I work around this?