« first day (1324 days earlier)      last day (1528 days later) » 

user7659542
8:57 AM
Considering this piece of code:
 
user7659542
mutex_lock(a);
x = x+1;
mutex_unlock(a);
 
user7659542
What guarantee do I have that out of order execution will not lead to this:
 
user7659542
x = x+1;
mutex_lock(a);
mutex_unlock(a);
 
user7659542
?
 
user7659542
assuming I didn't explicitely wrap this code with a memory barrier/fence
 
nwp
8:59 AM
Because the standard says so and compilers use barriers that prevent reordering to implement it.
The necessary memory barriers/fences are already part of mutex_lock/mutex_unlock. Or the implementation is incorrect.
 
user7659542
@nwp Hmm, happen to know which standard? I had a look to the c99 one and didn't see anything
 
user7659542
I looked for pthread_mutex_lock
 
user7659542
Found it!
 
user7659542
9:16 AM
What bothers me is that the POSIX standard states:
 
user7659542
"Applications shall ensure that access to any memory location by more than one thread of control (threads or processes) is restricted such that no thread of control can read or modify a memory location while another thread of control may be modifying it. Such access is restricted using functions that synchronize thread execution and also synchronize memory with respect to other threads. The following functions synchronize memory with respect to other threads: ... pthread_mutex_lock "
 
user7659542
Having memory synchronization does not mean you cannot have out of order execution
 
user7659542
so I guess, based on the documentation, pthread_mutex_lock may not use memory barriers internally
 
nwp
@traducerad C++11 and C11 added threads to the standard. Previously threads were not blessed by the standard and essentially a compiler extension that can do whatever it wants. Though they do aim to be useful extensions that make sense and should have the same semantics as today.
@traducerad Correct.
@traducerad Why not?
 
user7659542
9:29 AM
@nwp because it says that pthread_mutex_lock guarantees memory synchronization. And for me as said just above this doesn't mean you cannot have OOE.
 
user7659542
you now have the guarantee that only one thread accesses memory at a time. Great.
But thread B may be accessing that memory before thread A simply due to OOE
 
nwp
@traducerad That would break the guarantee. If there is a guarantee that only one thread can access the memory at a time then no reordering is allowed that breaks this guarantee.
 
user7659542
true
 
nwp
mutex_lock(a); x = x+1; y = y + 1; mutex_unlock(a);
->
mutex_lock(a); y = y + 1; x = x+1; mutex_unlock(a);
is allowed. Technically
y = y + 1; mutex_lock(a); x = x+1; mutex_unlock(a);
->
mutex_lock(a); x = x+1; y = y + 1; mutex_unlock(a);
is also allowed, but nobody does that.
Actually maybe CPUs do. Who knows.
 
user7659542
An exaggerated(?) example of what may lead to issues:
 
user7659542
9:41 AM
So we said memory synchronization does not protect against OOE
 
user7659542
pthread_mutex_lock(b);
a++;
printf("%d\n", a);
pthread_mutex_lock(b);
 
user7659542
may be reordered to
 
user7659542
pthread_mutex_lock(b);
printf("%d\n", a);
a++;
pthread_mutex_lock(b);
 
nwp
@traducerad No, we said it does protect. There are just sometimes some OOEs possible that are still allowed even in the presence of synchronization.
@traducerad It may not. That isn't allowed even without synchronization primitives.
 
user7659542
@nwp that's not how I understand the POSIX documentation. Because you are not breaking the guarantee that only one thread accesses memory.
 
user7659542
9:44 AM
you are still synchronized among threads
 
nwp
The rule is the "as-if rule". The observable behavior of the code must be "as if" it had been executed as written.
If you change the order of the increment and the print then the observable behavior changes, so you are not allowed to do it.
POSIX doesn't say this because the C or C++ standard already say that.
 
 
1 hour later…
11:13 AM
hey guys, anybody with knowledge about layer architecture?
 
11:24 AM
@SpaceToon sounds really generic, do you have a specific question?
 
 
1 hour later…
12:30 PM
@Peter yes
I want do develop an application with A GUI. The user can search for Bluetooth Low Energy devices and connect to one. Furthermore the data from this device (e.g. development board with a sensor) is sent to the application and the application will convert the data and plot them in real time. The user can select a directory in which the data can be saved on the local computer
Could this be a 3-Layer-Architecutre? Because someone said to me the third layer does not have to be a databse. If in your application data is saved or retrieved you have a 3-Layer architecture. is this correct? And what about MVC for my application
 
striving for an ideal architecture is a fools errand
sure keep gui and code that actual does stuff separate but I don't see a need to split things up further
 
I don't know about anything "being a 3-Layer-Architecture". All the architecture models are just models to help people organize their thoughts and structure their programs. Could you design it as a 3-Layer architecture? sure. Could you use MVC for your program? yeah.
 
That means that I don't have to take a model, but can do it the way I want?
Now I thought that I would create a class BluetoothLE, which contains all functions with which devices can be searched, a connection established and services and characteristics can be selected.
I would then create a second class "DataContainer" that receives the raw data with help of the BluetoothLE class from the sensor and converts it so that it can be plotted.
Then I would create a third class "plotter", which prepares the plots (title, axis labeling, etc.). This class then receives the data from the DataContainer and plots it on the UI.
I think these architectural patterns make sense in complex projects, but my project is quite small, so you're probably right. @ratchetfreak
 
creating more and more boundaries is also often an outgrowth of Conway's law
if you hire a DBA, a backend-dev and a frontend-dev they'll divide the structure in a way that they can work without clashing all the time
 
12:48 PM
Thanks @PeterT And whsat do you think about my class structure. Does this make sense or should I create more classes or maybe interfaces what do you think? Because it is my first practical software projct i am not sure if this can be made more efficient
 
Sounds like an initial plan. I'd say start out with it and if at some time it starts getting in your way, don't be afraid to split things up or merge them
separating the BLE stuff seems like a good idea in any case
 
1:17 PM
Thank you very much
 

« first day (1324 days earlier)      last day (1528 days later) »