question about objects by reference and threadsafety



 DEVELOP > c-Plus-Plus > question about objects by reference and threadsafety

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "john smith"
Date: 20 Jan 2005 09:29:51 PM
Object: question about objects by reference and threadsafety
If I create an object and pass it by reference to two other functions, and
the other two function have separate threads
must I worry about threadsafety? The two functions could modify the myCar
object in main at the same time couldn't they?
I have trouble understading if this is a problem or not. both functions
reference the myCar object in main and could potentially create a critical
section
path correct?
Thanks.
For example
int main()
{
Car myCar;
fixCar( myCar ); // fixCar() is a process running on its
own thread
fixCarAgain( myCar ); // fixCarAgain() is a process running on its
own thread
return 0;
}
void fixCar( Car& myCar ) // separate thread
{
// if I modify myCar should I do mutual exclusion semaphore here?
}
void fixCarAgain( Car& myCar ) // separate thread
{
// if I modify myCar should I do mutual exclusion semaphore here?
}
.

User: "shez"

Title: Re: question about objects by reference and threadsafety 20 Jan 2005 09:34:16 PM
john smith wrote:

int main()
{

Car myCar;

fixCar( myCar ); // fixCar() is a process running

on its

own thread

fixCarAgain( myCar ); // fixCarAgain() is a process running

on its

own thread

return 0;

}

void fixCar( Car& myCar ) // separate thread
{
// if I modify myCar should I do mutual exclusion semaphore here?

}

void fixCarAgain( Car& myCar ) // separate thread
{
// if I modify myCar should I do mutual exclusion semaphore here?

}

Yes, you will need a mutex if you modify myCar.
-shez-
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER