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: Ricky Stoneback <rwstoneback@…> 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:

  1. Define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG (to use nanosecond resolution in a posix_time) in the pre-processor definitions (VS2008).
  2. Create a boost::posix_time::ptime using the default constructor.
  3. 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:

  1. Use the same code as above, just for ease of use.
  2. Define the pre-processor definition: DATE_TIME_NO_DEFAULT_CONSTRUCTOR.
  3. Compile the program.
  4. 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)

comment:1 by viboes, 10 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

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.

in reply to:  1 ; comment:2 by rwstoneback@…, 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?

in reply to:  2 comment:3 by viboes, 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.

comment:4 by viboes, 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?

in reply to:  4 ; comment:5 by Ricky Stoneback <rwstoneback@…>, 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.

in reply to:  5 comment:6 by Ricky Stoneback <rwstoneback@…>, 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:7 by viboes, 10 years ago

Does the error occur in Boost.DateTime?

comment:8 by viboes, 10 years ago

Component: threaddate_time
Status: assignednew

Moved to DateTime as it seems Boost.Thread has nothing to do here.

comment:9 by viboes, 10 years ago

Owner: changed from viboes to az_sw_dude
Note: See TracTickets for help on using tickets.