简体   繁体   English

在Linux上进行C ++编程与Windows在Linux VM上进行C ++编程

[英]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? 与在Windows上使用Linux VM学习相比,在Linux上学习C ++编程有什么区别吗?

My initial guess is that there is no difference - the VM simply acts as if it were a normal Linux OS? 我最初的猜测是没有区别-VM只是像正常的Linux操作系统一样工作?

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. 我这样做是为了在Linux上的C ++编程中变得特别,包括Linux内核,Linux的工作方式,IPC,套接字,共享内存,管道等。

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. 当编写多线程程序或对共享数据进行IPC时,VM遇到的最大问题可能会出现。 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. 不幸的是,由于大多数VM的工作方式,您最终可能掩盖了时序问题,这些问题可能导致本机运行Linux内核的“真实”计算机崩溃,或者至少导致不良行为。 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. 由于VM的速度,您可能会观察到以下行为:每个写入过程都能够将其整个有效负载原子写入管道中,即使该有效负载大于PIPE_MAX的保证原子性...如果为该类型的程序进行编程行为,在实际机器上,由于PIPE_MAX任何PIPE_MAX都与写入该管道的其他进程交错在一起,您可能会大吃一惊。

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. 因此,最后,在VM上执行多线程编程或共享数据IPC时,您能够观察到过程数据损坏或因潜在的数据争用而崩溃的事实并不能确保您的程序实际上是数据争用免费,否则它不会在交错操作时间会更快得多的物理机器上崩溃。 The speed of the VM could simply be masking those issue for you. VM的速度可能只是为您掩盖了这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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