// JP opened flex table

Click to See Complete Forum and Search --> : If _beginthreadex fails, can I call it again for the same thread?


ameliaj8
October 4th, 2007, 10:18 PM
Is there any issue with calling _beginthreadex more than once for the same thread until it succeeds?

Arjay
October 4th, 2007, 10:24 PM
It shouldn't fail. Why is it failing (see what GetLastError() returns)?

I've only seen it fail during development, but although I check the return value, I yet to see it fail in production.

ameliaj8
October 5th, 2007, 12:38 AM
At the moment it is occasionally returning ENOMEM. And yes I have the /MD option set.

I'm just wondering if I can sleep for a while and then try _beginthreadex again on the same thread or if I need to delete the thread and create a new one.

Arjay
October 5th, 2007, 01:37 AM
ENOMEM? What OS are you running on?

ameliaj8
October 5th, 2007, 02:20 AM
Windows XP.

I'm sure I am trying to start too many threads at once and that is why it is having this error (running out of stack space) but that is not the point. I just want to know if it is ok to wait and then try starting again or if _beginthreadex sets some state variables or something that mean I shouldn't call it twice for the same thread.

JVene
October 5th, 2007, 04:00 PM
It's ok, but unless the condition that's causing the error changes, it will define an infinite loop (with some delay in the loop, I'd assume).

However, the design issue that you're indicating is underneath this question is probably at the heart of your solution. Waiting and retrying is probably just a 'bandaid' to the real problem.

If you're just experimenting, then push on to the limits and explore.

If you're designing 'real' code, then you've approached a limit that can probably be solved by a change of design.

//JP added flex table