Opened 5 years ago

Last modified 5 years ago

#13364 new Bugs

xxx please delete - it was my fault xxx

Reported by: anonymous Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.66.0 Severity: Showstopper
Keywords: boost::asio::steady_timer boost::dll Cc:

Description

The steady_timer is working fine when it is started in the executeable. By starting the steady_timer in the dll, the timer expires immediately. I think this is a bug, isn't it?

Change History (2)

comment:1 by anonymous, 5 years ago

I'm working with Visual Studio 2017 V15.5.2. Sorry, can't add attachments. So i list the source here:

api.h:


#include <boost/asio.hpp>

class my_api { public:

virtual void startTimer(boost::asio::io_service& ioservice) = 0;

virtual ~my_api() {}

};

dll.cpp


#include <iostream> #include <boost/dll.hpp> #include "api.h"

class my_plugin : public my_api { public:

void startTimer(boost::asio::io_service& ioservice) {

std::cout << "start timer (15 sec)\n"; boost::asio::steady_timer timer{ ioservice, std::chrono::seconds{ 15 } }; timer.async_wait([](const boost::system::error_code &ec) { std::cout << "15 sec\n"; });

};

~my_plugin() {};

};

static boost::shared_ptr<my_api> createPlugin() {

return boost::shared_ptr<my_api>(new my_plugin());

}

BOOST_DLL_ALIAS(

createPlugin, create_plugin

)

AsioProblem.cpp:


#include "stdafx.h"

#include <boost/dll/import.hpp> #include <boost/function.hpp> #include <boost/asio.hpp> #include <iostream> #include "../DLL/api.h"

namespace dll = boost::dll;

int main() {

boost::asio::io_service ioservice;

/* load dll */ boost::filesystem::path shared_library_path("..
Debug"); shared_library_path /= "DLL";

boost::function<boost::shared_ptr<my_api>()> creator = boost::dll::import_alias<boost::shared_ptr<my_api>()>(

shared_library_path, "create_plugin", boost::dll::load_mode::append_decorations );

boost::shared_ptr<my_api> plugin = creator();

/* set timer 10 sec */ std::cout << "start timer (10 sec)\n"; boost::asio::steady_timer timer{ ioservice, std::chrono::seconds{ 10 } }; timer.async_wait([](const boost::system::error_code &ec) { std::cout << "10 sec\n"; });

/* create my_plugin in dll with timer 15 sec */ plugin->startTimer(ioservice);

ioservice.run();

return 0;

}

comment:2 by anonymous, 5 years ago

Summary: steady_timer doesn't work in dllxxx please delete - it was my fault xxx
Note: See TracTickets for help on using tickets.