You are on the right track.
1) For the first array (read-only) you do not need to use a mutex lock for it. Since threads just read without changing data, in no way can a thread ruin the data for another thread
2) I am a little confused by this question. If you know that stream 1 will only write an element to cell 1 of the array, and stream 2 will only write to cell 2 of the array, then you do not need a mutex lock. However, I am not sure how you achieve this property. If my above statement is not suitable for your situation, you will definitely need a mutex lock.
3) Given the definition of an atom:
Atomic types are types that encapsulate a value, access to which is not guaranteed to lead to data failures and can be used to synchronize memory access between different threads.
Key note: a mutex lock is an atomic value that only one assembly instruction is required to lock / unlock the lock. If 2 assembly instructions were required to lock / unlock, the lock would not be flow safe. For example, if thread 1 tried to capture a lock and was switched to thread 2, thread 2 would capture a lock.
Using atomic data types will reduce your overhead, but not significantly.
4) I'm not sure how you can assure that your variables are aligned. Since threads can switch at any time in your program (your OS determines when a thread switches)
Hope this helps
Richard Mpanga Jun 10 '15 at 2:31 on 2015-06-10 14:31
source share