| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
General - Thread Safe
Could someone give me some pointers as to why this function is not thread safe
Code:
LPTSTR NextToken(LPTSTR p)
{
LPTSTR p1, p2;
static LPTSTR CurrTok;
if (p)
CurrTok = p;
if (CurrTok==NULL || *CurrTok==0)
return NULL;
// Run until delimeter
for (p2 = p1 = CurrTok; *p1 && *p1 != ','; p1++);
if (*p1==0)
CurrTok = NULL;
else
{
*p1 = 0;
CurrTok = p1+1;
}
return p2;
}
thanks |
|
#2
|
||||
|
||||
|
static LPTSTR CurrTok;
If two threads call this function they will share (and probably corrupt in some way) this variable.
__________________
There is no such thing as C/C++, you either program C or C++ |
|
#3
|
|||
|
|||
|
For this to be thread safe you need to make the variables into vector... then have some sort of shared index...
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > General - Thread Safe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|