Intel® Inspector Help

Cross-thread Stack Access

Occurs when a thread accesses a different thread's stack.

ID

Code Location

Description

1

Allocation site

If present, represents the location and associated call stack where the accessed stack memory was allocated.

2

Stack owned

Represents the location and associated call stack where the thread owning the stack was created.

3

Stack cross access

Represents the location and associated call stack where the stack memory was accessed by a different thread.

CAUTION

It is unsafe if the two threads do not coordinate the access properly. This can happen even if the accesses do not have race conditions. Failure to coordinate safe accesses can potentially result in unexpected application behavior or even an application crash. However, the Intel Inspector does not distinguish between safe accesses and unsafe accesses. It is the user's responsibility to determine if a cross-thread stack access is safe or not.

Example

Preparation

int *p;
CreateThread(..., thread #1, ...); 
CreateThread(..., thread #2, ...);

Thread #1

int q[1024]; // Allocated on Thread #1's stack
p = q;
q[0] = 1;

Thread #2

*p = 2; // Thread #1's stack accessed

If thread #1 and thread #2 are concurrent and there is no other synchronization between them, the Intel Inspector detects a Cross-thread stack access problem if p = q; in thread #1 executes before *p = 2; executes in thread #2.

The example shows the case where thread #1 publishes the address of a local stack variable q to the global pointer p, and later thread #2 accesses the stack of thread #1 by dereferencing the global pointer p, in effect writing to the variable q on thread #1.

Possible Correction Strategies