Opened 12 years ago

Closed 11 years ago

#5150 closed Feature Requests (duplicate)

boost::thread does not print or return the error value when creating a thread fails.

Reported by: jukka.jylanki@… Owned by: Anthony Williams
Milestone: Component: thread
Version: Boost 1.45.0 Severity: Not Applicable
Keywords: Cc:

Description

I'm running on Win7 64bit Professional, and building 32-bit code on MSVC2008.

For some reason, I'm getting boost::thread_resource_error from void thread::start_thread() in http://svn.boost.org/svn/boost/trunk/libs/thread/src/win32/thread.cpp , but I'm unable to debug this issue, since the boost sources don't check for the error value of when this call fails.

http://msdn.microsoft.com/en-us/library/kdzttdcb(v=vs.80).aspx specifies that _beginthreadex returns 0 on an error, in which case errno and _doserrno are set.

Expected: The value of errno is caught in the code and passed in the exception so that the client can debug the reason of the failure.

(The following background for some context, although it's such a voodoo situation I can not report that as a bug directly, better start with the above first)

My code that uses boost threads worked ok previously, and curiously it was that incorporating the use of QScriptEngineDebugger from Qt 4.6 into my application started exhibiting this problem. If I remove the use of QScriptEngineDebugger, the thread is created fine. I am using less than 100MB of memory, and my application is running about 15 threads, so it shouldn't be a system resource consumption issue.

Change History (4)

comment:1 by viboes, 11 years ago

Please, could you clarify what is exactly wrong with the library?

comment:2 by anonymous, 11 years ago

The problem is that the boost sources don't check for the error value when it creates a new thread in thread.cpp and report it back in any way, which makes it impossible to debug the reason why a thread creation might fail.

The thread::start_thread() calls _beginthreadex (which calls CreateThread if BOOST_HAS_THREADEX isn't defined). CreateThread has the following documentation on MSDN: "If the function fails, the return value is NULL. To get extended error information, call GetLastError." _beginthreadex has the following documentation on MSDN: "_beginthreadex returns 0 on an error, in which case errno and _doserrno are set.".

It would be more helpful if the the exception "boost::throw_exception(thread_resource_error());" would carry the reason for the failure, instead of only reporting back "I failed for an unknown reason.".

I tried to manually read GetLastError when this occurred, but it returned 0, which indicates that the error field was cleared by an operation in between.

comment:3 by viboes, 11 years ago

Severity: ProblemNot Applicable
Type: BugsFeature Requests

I don't see any bug in Boost.Thread. I think your concern will be best managed as a feature request.

comment:4 by viboes, 11 years ago

Milestone: To Be Determined
Resolution: duplicate
Status: newclosed

I have think a little bit more about this issue and I think that following the standard C++11 would respond to your request. I have added a more explicit feature request

#6230 Follows the exception reporting mechanism as defined in the c++11

So I will close this feature as duplicated.

Note: See TracTickets for help on using tickets.