The /GT compiler switch may cause an access violation when a fiber is switched between two threads (262515)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q262515 SYMPTOMS During the switching of threads, an access violation may
occur, with the following message at the top of the call stack:
KERNEL32! IsBadReadPtr@8 + 82 bytes In
general, this problem can occur whenever a fiber is switched between two
threads; for instance:
- when switching between preemptive mode and nonpreemptive
mode in User Mode Schedulers (UMS)
- when accessing a variable that is stored in thread-local
storage (TLS) before and after a switch.
CAUSE A fiber is a lightweight object that consists of a stack
and a register context, and which can be scheduled on various threads. A fiber
can run on any thread. Because a fiber may be swapped out and then restarted on
a different thread, it must not be cached or optimized as a common
subexpression across a function call.
The /GT compiler switch
prevents such optimizations. The /GT option supports fiber safety for data that
is allocated by using static thread-local storage; in other words, data that is
allocated with the __declspec( thread ) keyword.
The /GT compiler
switch leaves the TLSArray references as constant. When accessing a TLS
variable before and after a switch, the address is computed incorrectly. The
pointer to the TLS variable is stored in the esi register, the offset is stored
in the eax register, and the address is calculated by adding these two values.
After a thread switch, eax is recalculated but esi is not. The address is still
evaluated by adding esi and eax, and when the fiber switch changes the value in
esi, an access violation occurs. RESOLUTION Obtain the latest service pack for Visual Studio 6.0.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
This bug was corrected in the next service pack for Visual
Studio 6.0.
For additional information about Visual Studio service packs, click
the following article numbers to view the articles in the Microsoft Knowledge
Base: 194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed To download the latest Visual Studio service pack, visit the
following Microsoft Web site:
Modification Type: | Minor | Last Reviewed: | 12/12/2005 |
---|
Keywords: | kbBug kbCompiler kbfix kbVS600sp4fix kbVS600sp5fix KB262515 kbAudDeveloper |
---|
|