I am trying to read the man of gcc but I have not figured out what sort of problem I might have with data alignment for ints, doubles, structs and arrays.
Let's summarize in a few questions:
(1) I guess for a relatively recent 32bit Intel x86 , data alignment must be 32 bit for all ints, doubles, struct fileds, array elements or any other data. Because otherwise pthread_mutex_locking for multithreading data protection would be not sufficient to protect shared data? Is this a default option of the compiler? How would be this option changed?
(2) For a 64 bit more recent Intel do I have to require 32 or 64 bit alignment of all data? What is the default?
(3)
What if an array is shared but each single element is not shared
or a struct is shared but each single element is not shared. Example:
Thread 1 uses struct.field1 and a[0] while Thread2 uses struct.field2 and a[1]
What if my code does not use mutexes to protect these data cause they are not effectively shared? Is there some probability that the compiler does not align field1 and field2 or a[0] and a[1] so that I have errors?!
Please help me understand!
Thank you
oops.. part of the answer was probably given in the previous threads
http://cboard.cprogramming.com/showthread.php?t=105136
and http://cboard.cprogramming.com/showthread.php?t=104627
I will review it but I guess still part of my doubts will be left!!