|
|
extern
declaration for the global variable in the other files.#include
works before diving into that example code. #include "file"
or #include <file>
both do the same thing, they look for the file named 'file' anywhere in the list of folders that your compiler has been configured to include. When the file 'file' is found the text of 'file' is put in the same place that #include "file"
was. So, in other words, it replaces the #include
with the contents of the file. Knowing this should help you see where the declarations are coming from in the example code.
extern
and everything, thing is, source file receive get target force 125 times in a second, and file 'send' gets it online once, on start, original state, it doesn't change. I tryed with main source and everyhing, still nothing. I need to communicate iner-process. All source files are part of 1 executable. I would really appriciate it if you could give me a hand. I'm really inexperienced in C++.extern volatile int myVar;
. This tells the optimizer that the variable can change, even if a section of code indicates that it won't. That prevents the optimizer from optimizing away accesses to the variable.Within a thread of execution, accesses (reads and writes) to all volatile objects are guaranteed to not be reordered relative to each other, but this order is not guaranteed to be observed by another thread, since volatile access does not establish inter-thread synchronization. In addition, volatile accesses are not atomic (concurrent read and write is a data race) and do not order memory (non-volatile memory accesses may be freely reordered around the volatile access). ... Standard volatile semantics are not applicable to multithreaded programming, although they are sufficient for http://en.cppreference.com/w/cpp/atomic/memory_order |
Atomic objects are the only C++ objects free of data races; that is, if one thread writes to an atomic while another thread reads from it, the behavior is well-defined. http://en.cppreference.com/w/cpp/atomic |