[asio] An error occured in asio::win_mutex.hpp

Hi ALL,
I have encountered this error, and would like to program a win32 FTP client with asio lib.
In asio examples I reffenrenced at the 'Services(logger program)'.
Could you help me ?
I appriciate any suggestion.
Thank all,
Yasuhiko Yoshimura (Japan)
An accsess violence occured at the below ===>> point.
win_mutex.hpp:line 125:
------------------------------------------------------------------------
Then variable values are:
&crit_section_ 0xcdcdcdcd
this 0xcdcdcdcd (boost::noncopyable_::noncopyable)
// Locking must be performed in a separate function to lock() since the
// compiler does not support the use of structured exceptions and C++
// exceptions in the same function.
int do_lock()
{
__try
{
===>> ::EnterCriticalSection(&crit_section_);
}
__except(GetExceptionCode() == STATUS_INVALID_HANDLE
|| GetExceptionCode() == STATUS_NO_MEMORY
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
if (GetExceptionCode() == STATUS_NO_MEMORY)
return ERROR_OUTOFMEMORY;
return ERROR_INVALID_HANDLE;
}
return 0;
}
------------------------------------------------------------------------
Here are my codes below.
And error point was ===>>
------------------------------------------------------------------------
using boost::asio::ip::tcp;
class ftp_client_dtp
: public boost::enable_shared_from_this

<...>
ftp_client_dtp(boost::asio::io_service& io_service) : work_io_service_(), work_resolver_(new boost::asio::ip::tcp::resolver(work_io_service_)), work_socket_(new boost::asio::ip::tcp::socket(work_io_service_)) ===>> { } <...> boost::scoped_ptrboost::asio::ip::tcp::resolver work_resolver_; boost::scoped_ptrboost::asio::ip::tcp::socket work_socket_;
boost::asio::io_service work_io_service_; <...>
Please, pay attention that member objects are initialized in the order of their definition. I.e., when you initialize work_resolver_ and work_socket_ you pass them uninitialized work_io_service_ as a parameter.

Hi Igor R,
Thank you very much for your reply.
Now I have got a resolution that moving the initialization of 2 variable
objects
(work_resolver_ , work_socket_) that you mentioned into start() function
from
the constructor.
Thank you,
Yasuhiko Yoshimura
--------------------------------------------------
From: "Igor R"
<...>
ftp_client_dtp(boost::asio::io_service& io_service) : work_io_service_(), work_resolver_(new boost::asio::ip::tcp::resolver(work_io_service_)), work_socket_(new boost::asio::ip::tcp::socket(work_io_service_)) ===>> { } <...> boost::scoped_ptrboost::asio::ip::tcp::resolver work_resolver_; boost::scoped_ptrboost::asio::ip::tcp::socket work_socket_;
boost::asio::io_service work_io_service_; <...>
Please, pay attention that member objects are initialized in the order of their definition. I.e., when you initialize work_resolver_ and work_socket_ you pass them uninitialized work_io_service_ as a parameter. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Now I have got a resolution that moving the initialization of 2 variable objects (work_resolver_ , work_socket_) that you mentioned into start() function from the constructor.
Well, you could just change the order of their definition, so that io_service is always defined *first*..
participants (2)
-
Igor R
-
Yasuhiko Yoshimura (informax.co.jp)