Monday, June 3, 2013

Interview Series: "Describe the difference between a Thread and a Process?"

I came across a post on Scott Hanselman's website titled 'What Great .NET Developers Ought To Know (More .NET Interview Questions)' and the list of questions really caught my interest. So, I've decided to try and answer all of the questions. I'll probably have to look up a bunch, and some of the questions aren't really applicable to my field of work, but still - I'm expecting to learn quite a bit.

"Describe the difference between a Thread and a Process?"

A process is an instance of an application, which can run n-threads (depending on the OS). A thread being 'smallest sequence of programmed instructions that can be managed independently by an operating system scheduler'. For more detailed information, use the links below or use Google.

In terms of .NET namespaces, the processes are inside System.Diagnostics whereas the threading stuff is under System.Threading. I never really got why process is inside the diagnostics namespace, so If you know - place a comment.

A lot has changed in the .NET framework related to threading quite recently. In .NET 4 - the 'task' keyword was introduced and in 4.5 the 'async' and 'await' keywords were added to that. This is of course because processors are getting more and more cores. A nice video for getting up to speed with task/async/await is this one on YouTube:

One of the interesting points made in the video is that async does not mean multi-threaded. That was in eye-opener to me. What he also points out that if you have 8 cores and don't use multiple-threads, you're only using an eigth of the processor capacity at most.


No comments:

Post a Comment