I would like some help regarding multithreading...
i want to know what exactly happens when i start a new thread... i.e how it affects the variables etc. in the program...
one query i have is what happens if i start 2 threads starting with the same function.. will their running be separate from each other or will the changing of the local variables by one affect the other...
and is their anyway to overcome this problem in the case one affects the other...

Recommended Answers

All 2 Replies

separate threads use different stacks (the part of the memory that stores the local variables) but share the same heap(the part of the memory that stores the objects allocated by 'malloc', or 'new', and global variables).

That means that any changes made on variables allocated on the heap are visible for the other threads, But the local variables are not affected (so no problem if you use the same function for both threads)

thanx a lot dude..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.