Boost C++ Libraries: Ticket #7160: BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG and DATE_TIME_NO_DEFAULT_CONSTRUCTOR https://svn.boost.org/trac10/ticket/7160 <p> I think I found a couple issues that are somewhat related to one another: </p> <p> <strong>Issue 1 - Defining BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG and using the ptime default constructor along with a thread causes runtime crash</strong> </p> <p> Steps to reproduce: </p> <ol><li>Define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG (to use nanosecond resolution in a posix_time) in the pre-processor definitions (VS2008). </li><li>Create a boost::posix_time::ptime using the default constructor. </li><li>Create a boost::thread and call join. </li></ol><p> Example: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/thread.hpp&gt; 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 &lt;&lt; "done" &lt;&lt; std::endl; system("pause"); return 0; } </pre><p> <strong>Issue 2 - defining DATE_TIME_NO_DEFAULT_CONSTRUCTOR causes compile-time error "no appropriate default constructor available"</strong> </p> <p> 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: </p> <p> Steps to reproduce: </p> <ol><li>Use the same code as above, just for ease of use. </li><li>Define the pre-processor definition: DATE_TIME_NO_DEFAULT_CONSTRUCTOR. </li><li>Compile the program. </li><li>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 </li></ol><p> The issue, I believe, is that I am using a boost thread, which uses a ptime default constructor in its <em>explicit timeout(sentinal_type)</em> constructor when it doesn't set the <em>abs_time</em> member variable. </p> <p> 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) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7160 Trac 1.4.3 viboes Sun, 12 Aug 2012 19:19:17 GMT owner, status changed https://svn.boost.org/trac10/ticket/7160#comment:1 https://svn.boost.org/trac10/ticket/7160#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I will try to reproduce the example as soon as I have access to a windows machine. </p> <p> 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. </p> Ticket rwstoneback@… Sun, 12 Aug 2012 19:52:13 GMT <link>https://svn.boost.org/trac10/ticket/7160#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7160#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7160#comment:1" title="Comment 1">viboes</a>: </p> <blockquote class="citation"> <p> I will try to reproduce the example as soon as I have access to a windows machine. </p> <p> 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. </p> </blockquote> <p> <br /> Is it noted anywhere that the ptime interface is deprecated? What version of Boost did this occur in? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 15 Aug 2012 20:15:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7160#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7160#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7160#comment:2" title="Comment 2">rwstoneback@…</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7160#comment:1" title="Comment 1">viboes</a>: </p> <blockquote class="citation"> <p> I will try to reproduce the example as soon as I have access to a windows machine. </p> <p> 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. </p> </blockquote> <p> <br /> Is it noted anywhere that the ptime interface is deprecated? What version of Boost did this occur in? </p> </blockquote> <p> 1.50. See <a href="http://www.boost.org/doc/libs/1_50_0/doc/html/thread/time.html#thread.time.deprecated">http://www.boost.org/doc/libs/1_50_0/doc/html/thread/time.html#thread.time.deprecated</a>. </p> <p> Note BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0 in <a href="http://www.boost.org/doc/libs/1_50_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread">http://www.boost.org/doc/libs/1_50_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread</a>. And <a href="http://www.boost.org/doc/libs/1_50_0/doc/html/thread/build.html#thread.build.configuration.deprecated">http://www.boost.org/doc/libs/1_50_0/doc/html/thread/build.html#thread.build.configuration.deprecated</a>. </p> <p> 1.51 will be a little more explicit. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 15 Aug 2012 20:17:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7160#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7160#comment:4</guid> <description> <p> Test regressions in <a href="http://www.boost.org/development/tests/trunk/developer/thread.html">http://www.boost.org/development/tests/trunk/developer/thread.html</a> show that the test_7160 is passing on windows. Please could you check the test? </p> </description> <category>Ticket</category> </item> <item> <author>Ricky Stoneback <rwstoneback@…></author> <pubDate>Wed, 15 Aug 2012 20:29:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7160#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7160#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7160#comment:4" title="Comment 4">viboes</a>: </p> <blockquote class="citation"> <p> Test regressions in <a href="http://www.boost.org/development/tests/trunk/developer/thread.html">http://www.boost.org/development/tests/trunk/developer/thread.html</a> show that the test_7160 is passing on windows. Please could you check the test? </p> </blockquote> <p> Just realized (after running your regression test) that this only happens in Debug mode...not in Release. </p> </description> <category>Ticket</category> </item> <item> <author>Ricky Stoneback <rwstoneback@…></author> <pubDate>Wed, 15 Aug 2012 21:19:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7160#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7160#comment:6</guid> <description> <p> 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): </p> <pre class="wiki">#define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG #include &lt;iostream&gt; #include &lt;boost/thread.hpp&gt; #include &lt;boost/asio.hpp&gt; 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 &lt;&lt; "done" &lt;&lt; std::endl; system("pause"); return 0; } </pre><p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 18 Aug 2012 14:48:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7160#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7160#comment:7</guid> <description> <p> Does the error occur in Boost.<a class="missing wiki">DateTime</a>? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 19 Aug 2012 15:32:15 GMT</pubDate> <title>status, component changed https://svn.boost.org/trac10/ticket/7160#comment:8 https://svn.boost.org/trac10/ticket/7160#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> <li><strong>component</strong> <span class="trac-field-old">thread</span> → <span class="trac-field-new">date_time</span> </li> </ul> <p> Moved to <a class="missing wiki">DateTime</a> as it seems Boost.Thread has nothing to do here. </p> Ticket viboes Sat, 17 Nov 2012 16:00:00 GMT owner changed https://svn.boost.org/trac10/ticket/7160#comment:9 https://svn.boost.org/trac10/ticket/7160#comment:9 <ul> <li><strong>owner</strong> changed from <span class="trac-author">viboes</span> to <span class="trac-author">az_sw_dude</span> </li> </ul> Ticket