edited by
16,784 views

7 Answers

Best answer
57 votes
57 votes

A thread shares with other threads a process’s (to which it belongs to) :

  • Code section
  • Data section (static + heap)
  • Address Space
  • Permissions
  • Other resources (e.g. files)

Therefore, (D) is the answer. 

edited by
20 votes
20 votes

Ans is D.

Threads of a process share everything ( code , data , files , heap ) except stack and registers 

14 votes
14 votes

Global variables are stored on Heap and Heap is shared so both of them are shared.

Not able to find any "proper" references. Read this is in some book, forgot which one.

Here is a link for its reference:

http://cs.stackexchange.com/questions/48345/what-threads-share-in-general/48415

In practice global variables can be kept in the stack of Main function so that it can be accessed by all functions. Correction: Global variables cannot be inside a function, as that will limit its visibility.

The following argument is for when we need large memory, which is not asked in the question:

If its is kept in the main, the memory required for it will be taken from stack (whose size is fixed) and if the memory required is too much then this is will results into the famous error "Stack Overflow". However if it is outside any functions, then it is allocated from the heap or the data section of the code whose size can be configured as per the space required by the global variables.

Example:

This gives Stack overflow error:

int main(){
	int arr[10000000];
	cout<<"This is working"<<endl;
	return 0;
}

This does not:

int arr[10000000];
int main(){
	cout<<"This is working"<<endl;
	return 0;
}

Thanks for the question. It taught me something which I took for granted. Hope this helps.

edited by
9 votes
9 votes
i think both heap and global variables.Global variables are shared by threads.Data on heap is available throughout the program execution.
Answer:

Related questions

24 votes
24 votes
3 answers
3
30 votes
30 votes
5 answers
4
Madhav asked Feb 14, 2017
11,732 views
Which of the following is/are shared by all the threads in a process?Program counterStackAddress spaceRegisters(I) and (II) only(III) only(IV) only(III) and (IV) only