in reply to Re^2: Why is my counter not updating in a threaded application?
in thread Why is my counter not updating in a threaded application?

I thought child processes have access to the global variables.

The child process is a copy of the parent process, made at the point of fork(). So any variables (not just globals) will have the same value at the start of the child process as they did in the parent process at that time. But changes made in the child affect only the copy, not the original in the parent.

The same is true for threads, except that in that case there is a special mechanism called sharing that lets you nominate specific variables to be shared across threads, such that a change made in one thread is visible in the other threads (see threads::shared). This is costly, however - access to such variables must be protected by locking - so should be used sparingly if you hope to retain any speed benefit from making an application multi-threaded.

There are other more explicit mechanisms for sharing data between threads or processes - think for example of pipes, shared memory, or databases. Collectively such mechanisms are known as "IPC" (inter-process communication) - there are lots of modules in the IPC:: namespace that may give you ideas.