Opened 9 years ago
Closed 8 years ago
#9880 closed Bugs (fixed)
[windows] boost::condition_variable.timed_wait() exception if system time < 1970
| Reported by: | anonymous | Owned by: | viboes |
|---|---|---|---|
| Milestone: | Boost 1.57.0 | Component: | thread |
| Version: | Boost 1.55.0 | Severity: | Problem |
| Keywords: | Cc: |
Description (last modified by )
Os: any windows. Set system time < 01.01.1970, for example 01.01.1950.
Any call to boost::condition_variable.timed_wait() with relative(!) time throw exception because boost try get system time in posix format.
How to fix: boost\thread\win32\thread_data.hpp, line 179 (boost 1.55.0). In constructor
timeout(uintmax_t milliseconds_):
start(win32::GetTickCount64()),
milliseconds(milliseconds_),
relative(true),
abs_time(boost::get_system_time())
{}
we set "relative(true)" and there for not need to set variable "abs_time". Must be:
timeout(uintmax_t milliseconds_):
start(win32::GetTickCount64()),
milliseconds(milliseconds_),
relative(true)
{}
Change History (13)
comment:1 by , 9 years ago
| Component: | None → date_time |
|---|---|
| Owner: | set to |
comment:2 by , 9 years ago
| Component: | date_time → thread |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:3 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:4 by , 9 years ago
comment:6 by , 9 years ago
I am the developer of anti-virus, respectively, our product should work with any conditions that malicious software may do. We found that the boost has architectural problem with the fact that he is trying to get the system time in posix format when specifying relative time. We found some workarounds solutions, but a problem with the condition variable could not solve. Example executed on windows 8.1, visual studio 2012, boost_1_55_0. Thanks!
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include "windows.h"
#include "boost/thread.hpp"
#define IF_ERR_RET(x) if(!(x)) {printf("Error: %d in %s(%d)\n", GetLastError(), __FILE__, __LINE__); return FALSE;}
#define TRY try {
#define CATCH } catch(std::exception& exc) {printf("Exception %s in %s(%d)\n", exc.what(), __FILE__, __LINE__);}
bool setYear(int year)
{
SYSTEMTIME tm;
GetLocalTime(&tm);
tm.wYear = year;
IF_ERR_RET(SetLocalTime(&tm));
return TRUE;
}
void Func(void)
{
Sleep(10000);
}
int _tmain(int argc, _TCHAR* argv[])
{
IF_ERR_RET(setYear(1950));
TRY;
boost::condition_variable cv;
boost::mutex mtx;
boost::mutex::scoped_lock lck(mtx);
cv.timed_wait(lck, boost::posix_time::milliseconds(1000)); // exception
CATCH;
TRY;
boost::thread thr(&Func);
thr.timed_join(boost::posix_time::milliseconds(1000)); // exception
CATCH;
TRY;
boost::thread thr(&Func);
thr.try_join_for(boost::chrono::milliseconds(1000)); // exception
CATCH;
TRY;
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000)); // exception
CATCH;
TRY;
boost::posix_time::second_clock::local_time(); // exception
CATCH;
IF_ERR_RET(setYear(2014));
return 0;
}
comment:7 by , 9 years ago
Ok, I understand your concern. I will take a look. Could you answer to the questions: Have you found a regression? If yes, on which version it was working?
comment:8 by , 9 years ago
I was not looking for a regression, but I think that this error has always been. boost_1_51_0, boost_1_55_0 - the problem persists.
comment:9 by , 9 years ago
I have no access to a windows machine. So before updating the code I want to be sure it fixes the issue.
Please, could you point me where abs_time is used if relative is true?
Thanks in advance, Vicente
comment:10 by , 9 years ago
| Summary: | boost::condition_variable.timed_wait() exception if system time < 1970 → [windows] boost::condition_variable.timed_wait() exception if system time < 1970 |
|---|
comment:13 by , 8 years ago
| Milestone: | To Be Determined → Boost 1.57.0 |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |

This code has been there since the beginning.
Have you found a regression? If yes, on which version it was working?
Could you provide an example, please?