summaryrefslogtreecommitdiff
path: root/code/snippets/cow.rb
blob: f7d85d418a4f12527f76bf4859630ac37e4ce14d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
arr = [1,2,3]

fork do
  # At this point the child process has been initialized.
  # Because of CoW the arr variable hasn't been copied yet.
  arr << 4
  # The above line of code modifies the array, so a copy of
  # the array will need to be made for this process before
  # it can modify it. The array in the parent process remains
  # unchanged.
end