Skip to main content
gamedev.net
🔒 Locked

MultiThreading - unsure

Started by mageziyx 3 replies 650+ views
Original Post
mageziyx
mageziyx
void Object::Function() { for(int count=0; count<100; count++) { cout << count; } } When several threads calls the above function, will each thread have its own copy of count or will they be referring to the same count? Does each thread own a separate stack?
djsteffey
djsteffey
each thread will have their own count
as long as count is definded in the function like you have it
now if count was declared global then of course all the threads would be using the same count and you would get some messed up stuff going on, or maybe not messed up if that is what you were looking to do

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
Gabriel Fleseriu
Gabriel Fleseriu
Yes, "count" will be different. But "cout" won''t, so you''ll probably get an output salad.

Forever trusting who we are
And nothing else matters
- Metallica
Forever trusting who we areAnd nothing else matters - Metallica
Solo
Solo
Yes, each thread get''s it''s own stack.
// Ryan
Stoffel
Stoffel
heheheh, output salad. I''ll have to use that in a code review sometime.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.