简体   繁体   中英

Programming C++ on Linux vs Programming C++ on Linux VM in Windows

Is there any difference between learning to program C++ on Linux as opposed to learning via using a Linux VM, on Windows?

My initial guess is that there is no difference - the VM simply acts as if it were a normal Linux OS?

I am doing this to become particular with C++ programming on Linux, including the Linux kernel, how Linux works, IPC, sockets, shared memory, pipes etc.

Probably the biggest issue you will run into with a VM will come when you are writing multi-threaded programs, or doing IPC on shared data. Unfortunately because of the way most VM's work, you can end up masking timing issues that would cause crashes on a "real" machine natively running the Linux kernel, or at least un-desirable behavior. For instance, a data-race that may appear benign on a VM because it doesn't crash during run-time could cause, because of the inherently faster timing on a physical machine, a true data-race that may be very hard to debug. Another example of timing-related issues that could occur might be where you have multiple processes writing to a pipe with a single reader. Because of the speed of a VM, you might observe behavior where every writing process is able to atomically write their entire payload into a pipe, even if that payload is larger than the guaranteed atomicity of PIPE_MAX ... if you programmed for that type of behavior, on a real-machine you could end up with a big surprise as anything over PIPE_MAX gets interleaved with other processes writing to the pipe.

So in the end, the fact that you are able to observe a lack of process data corruption or crashes from potential data-races while doing multi-threaded programming or shared data IPC on a VM does not assure that your program is actually data-race free, or that it will not crash on a physical machine where the timing of interleaved operations will be much faster. The speed of the VM could simply be masking those issue for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM