Interview Question for Software Engineer / Developers


Country: India




Comment hidden because of low score. Click to expand.
2
of 2 vote

Shared:
- code
- data
- heap memory and memory address
- memory management information (base/relocation & limit registers, page tables
- process state (new, ready, running, waiting, halted, etc)
- I/O status information (opened file descriptors, etc)
- signals
- environment variables

Not shared:
- registers
- stack
- thread specific data

- jzhu May 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

@tejaswibm: It is just the stack that is not shared between threads. Heap, data and code are share between the threads.

- nithish.m January 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Internally, it's possible for different threads to allocate on different heaps to avoid the need for synchronization. In that situation, thread-specific heaps may be copied over to a shared heap periodically. These details are highly language, compiler, and runtime-specific, though.


The answer above should be more than sufficient for your typical interviewer.

- eugene.yarovoi January 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Also there's 'thread specific storage' which is either a compiler extension or, now, in C++11, baked into the language I believe, which is not shared. But, what eugene says goes for this too.

- JeffD January 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

In some languages, like Java, you can extend the Thread class and put whatever instance variables you want in the extending class. When you then instantiate this class, you'll create threads that each have their own copies of these instance variables. This kind of thing is useful when you need each thread to have some kind of functionality that involves keeping track of internal state, but the desired functionality logically has no dependency between threads. An example would be a random number generator. Using a per-thread random number generator will remove any kind of lock contention that might otherwise have existed.

- eugene.yarovoi May 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In short ,
thread share all resources of process except local storage like - register , stack .

- Breakinterview April 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

do threads share program counters?

- Rohhit Naik January 03, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, threads don't share program counters. How could they? A program counter represents which instruction you're currently executing, which is related to what line of code you're currently executing. Since the whole point of threads is that they allow you to execute different parts of the program at the same time, each thread must have its own program counter.

- eugene.yarovoi January 03, 2015 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I think threads have their different registers.

- Psycho May 04, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More