I was asked about this in an c++ developer position interview, what is the answer to this?
Asked
Active
Viewed 3,426 times
10
-
1I hope you turned it down. I wouldn't want to work for an employer who asks trivia questions in interviews. – corsiKa Mar 17 '11 at 20:49
-
1@glowcoder: Not necessarily trivia. Depends on what they consider a good answer. The might want to check if you know (or even better, can infer) the difference between a portable thread abstraction and what is clearly non-standard (underscore prefix!). – Jon Mar 17 '11 at 21:00
-
I really dont know what is "a portable thread abstraction" and what is "non-standard", could you explain more? – Leon Mar 17 '11 at 21:03
-
@Jon that's exactly it - that too is another piece of trivia. It tells you nothing about how well the person understands the intricate workings of multithreaded technology. Almost any time a question starts "what is the difference between" it's a poorly chosen interview question. – corsiKa Mar 17 '11 at 21:11
-
@Leon: A thread is not only an OS concept, but a programming one as well -- in the sense that you need to manage threads (start them, suspend them etc) from code and this means that you have to refer to them *somehow* and there must be *some* API to do the management. If the C++ runtime for Windows (and only it) provides a function `X` to start a thread, it's non-portable. Conversely, if there is a well-defined API for dealing with threads (such as `pthreads`), this is a layer of abstraction over what the runtime offers. – Jon Mar 17 '11 at 21:18
-
@glowcoder: If someone asked this question and expected to infer the interviewee's knowledge of "intricate workings of multithreaded technology", then we agree you don't want to work there. But I don't feel it's correct to provide summary judgement against the interviewer without any real data. We don't know what they consider a satisfactory answer. – Jon Mar 17 '11 at 21:21
-
@Jon pthreads are far from portable. Portable in the context of C and C++ usually means something within the bounds of the standard: language and library. Portable multi-threading is coming with C++0x. – David Heffernan Mar 17 '11 at 21:34
-
@David: I won't disagree in essence -- but you also have to agree that pthreads are far more portable than `_beginthread`. – Jon Mar 17 '11 at 21:39
-
@Jon Agreed. `_beginthreadex()` is even MSVC specific. `CreateThread()` is a bit less specific. Of course, you can run Win32 threads on Mac and Linux. – David Heffernan Mar 17 '11 at 21:41
1 Answers
10
I would have said:
If I wanted to create a portable cross-platform C++ binary, I'd use pthreads and use the pthread implementation for windows. If I wanted to create a windows-specific C++ binary, I'd use beginthread and avoid the 3rd party dependency on the pthread library.
If they really wanted to know the intricate internal details describing the differences between the two, you should think twice about working there. Unless it was for a reverse engineering job.

Luke
- 3,742
- 4
- 31
- 50
-
6+1 probably the best possible answer to this type of question in an interview. – Chris Dodd Mar 17 '11 at 20:57
-
the p in pthread stands for posix, not portable. who told you that? – Pete Wilson Mar 17 '11 at 21:14
-
@Pete Wilson - I didn't say that the p stood for portable, but do you know what the P in POSIX stands for??? Look it up. :) – Luke Mar 18 '11 at 01:35
-
hey, pass some o' that delicious crow over here, will ya? I read, when I look it up, that "Acronym, Definition. POSIX, Portable Operating System Interface (IEEE Standard 1003.1)" Thanks for the pickup! – Pete Wilson Mar 18 '11 at 10:57