hendrikdv wrote on Monday, June 22, 2015:
I’ve got a lot of trouble getting my application to run on Windows. The threads go haywire or deadlock, and the result is different depending whether or not I look at them in Sysinternals Process Explorer. Very bizarre.
Anyway, while debugging I did find what I think is a potential bug.
In prvProcessSimulatedInterrupts(), there is a piece of code to switch threads:
/* Suspend the old thread. */
pxThreadState = ( xThreadState *) *( ( size_t * ) pvOldCurrentTCB );
SuspendThread( pxThreadState->pvThread );
/* Obtain the state of the task now selected to enter the
Running state. */
pxThreadState = ( xThreadState * ) ( *( size_t *) pxCurrentTCB );
ResumeThread( pxThreadState->pvThread );
I think inbetween these two there needs to be a call to GetThreadContext, as described on the given URL.
CONTEXT context;
BOOL success;
/* Suspend the old thread. */
pxThreadState = ( xThreadState *) *( ( size_t * ) pvOldCurrentTCB );
SuspendThread( pxThreadState->pvThread );
// Ensure the thread is really suspended by calling an operation on it
// that only returns once once it is suspended.
// See http://blogs.msdn.com/b/oldnewthing/archive/2015/02/05/10591215.aspx
context.ContextFlags = CONTEXT_INTEGER; // Just ask some dummy register data
success = GetThreadContext( pxThreadState->pvThread, &context );
configASSERT( success );
/* Obtain the state of the task now selected to enter the
Running state. */
pxThreadState = ( xThreadState * ) ( *( size_t *) pxCurrentTCB );
ResumeThread( pxThreadState->pvThread );