Opened 10 years ago
Last modified 10 years ago
#7160 new Bugs
BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG and DATE_TIME_NO_DEFAULT_CONSTRUCTOR
Reported by: | Owned by: | az_sw_dude | |
---|---|---|---|
Milestone: | To Be Determined | Component: | date_time |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | thread, asio, ptime, posix_time | Cc: |
Description
I think I found a couple issues that are somewhat related to one another:
Issue 1 - Defining BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG and using the ptime default constructor along with a thread causes runtime crash
Steps to reproduce:
- Define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG (to use nanosecond resolution in a posix_time) in the pre-processor definitions (VS2008).
- Create a boost::posix_time::ptime using the default constructor.
- Create a boost::thread and call join.
Example:
#include <iostream> #include <boost/thread.hpp> class ThreadClass { public: ThreadClass() { } void operator()() { return; } }; int main() { boost::posix_time::ptime currentTimeUTC; ThreadClass tc; boost::thread t(tc); t.join(); //causes a runtime access violation here std::cout << "done" << std::endl; system("pause"); return 0; }
Issue 2 - defining DATE_TIME_NO_DEFAULT_CONSTRUCTOR causes compile-time error "no appropriate default constructor available"
In Issue 1 above, if you do not use a default constructor for a ptime, it seems to fix the issue. So I figured that was fine and I could prevent a user of my library from using that default constructor by defining DATE_TIME_NO_DEFAULT_CONSTRUCTOR. However, this now breaks at compile time:
Steps to reproduce:
- Use the same code as above, just for ease of use.
- Define the pre-processor definition: DATE_TIME_NO_DEFAULT_CONSTRUCTOR.
- Compile the program.
- The following error is produced: error C2512: 'boost::posix_time::ptime' : no appropriate default constructor available e:\libraries\boost\boost_1_47\boost\thread\win32\thread_data.hpp 145
The issue, I believe, is that I am using a boost thread, which uses a ptime default constructor in its explicit timeout(sentinal_type) constructor when it doesn't set the abs_time member variable.
I am using Boost 1.47, however looking at the latest boost code (1.51), I don't see any fixes for these issues that stand out (I am not able to try the latest versions of Boost, so I apologize if they are fixed, but I would think that they are not)
Change History (9)
follow-up: 2 comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 3 comment:2 by , 10 years ago
Replying to viboes:
I will try to reproduce the example as soon as I have access to a windows machine.
For the second issue, as DATE_TIME_NO_DEFAULT_CONSTRUCTOR is not documented so that I can not take care of it. In addition the ptime interface is deprecated now.
Is it noted anywhere that the ptime interface is deprecated? What version of Boost did this occur in?
comment:3 by , 10 years ago
Replying to rwstoneback@…:
Replying to viboes:
I will try to reproduce the example as soon as I have access to a windows machine.
For the second issue, as DATE_TIME_NO_DEFAULT_CONSTRUCTOR is not documented so that I can not take care of it. In addition the ptime interface is deprecated now.
Is it noted anywhere that the ptime interface is deprecated? What version of Boost did this occur in?
1.50. See http://www.boost.org/doc/libs/1_50_0/doc/html/thread/time.html#thread.time.deprecated.
Note BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0 in http://www.boost.org/doc/libs/1_50_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread. And http://www.boost.org/doc/libs/1_50_0/doc/html/thread/build.html#thread.build.configuration.deprecated.
1.51 will be a little more explicit.
follow-up: 5 comment:4 by , 10 years ago
Test regressions in http://www.boost.org/development/tests/trunk/developer/thread.html show that the test_7160 is passing on windows. Please could you check the test?
follow-up: 6 comment:5 by , 10 years ago
Replying to viboes:
Test regressions in http://www.boost.org/development/tests/trunk/developer/thread.html show that the test_7160 is passing on windows. Please could you check the test?
Just realized (after running your regression test) that this only happens in Debug mode...not in Release.
comment:6 by , 10 years ago
Issue 1 happens any time a ptime default constructor is used...which I'm also now realizing includes creating a deadline_timer. The following creates the same run-time error (in Debug):
#define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG #include <iostream> #include <boost/thread.hpp> #include <boost/asio.hpp> class ThreadClass { public: ThreadClass(){} void operator()(){return;} }; int main() { boost::asio::io_service ioService; boost::asio::deadline_timer x(ioService); ThreadClass tc; boost::thread t(tc); t.join(); //causes a runtime access violation here std::cout << "done" << std::endl; system("pause"); return 0; }
Since I am writing a library for people to use, I cannot simply say that it's OK that it doesn't break in Release.
comment:8 by , 10 years ago
Component: | thread → date_time |
---|---|
Status: | assigned → new |
Moved to DateTime as it seems Boost.Thread has nothing to do here.
comment:9 by , 10 years ago
Owner: | changed from | to
---|
I will try to reproduce the example as soon as I have access to a windows machine.
For the second issue, as DATE_TIME_NO_DEFAULT_CONSTRUCTOR is not documented so that I can not take care of it. In addition the ptime interface is deprecated now.