Closed Ofenhed closed 3 years ago
@Ofenhed thanks a lot for the investigation and fix.
Could you amend the "BEWARE" comment for pure
? Maybe something along the lines of
Also note that the function might be called multiple times, given that
unsafeDupablePerformIO
is used to call the provided C code.
Actually, re-reading the comment for unsafeDupablePerformIO
, I think an ever longer caveat is warranted, something like
Also note that the function might be called multiple times, given that
unsafeDupablePerformIO
is used to call the provided C code. Please refer to the documentation forunsafeDupabelPerformIO
for more details.unsafeDupablePerformIO
is used to ensure good performance using the threaded runtime.
Oh and last request -- please link the issue above the code usage of unsafeDupablePerformIO
, so that we remember why it's there :).
I mostly used your text. What do you think about it now?
Changing from unsafePerformIO to unsafeDupablePerformIO removes the thread safety of pure functions calls, which means that expensive CPU core memory synchronization is not performed. This means that pure functions may be called more than once if called at the same time from multiple threads. This change is safe as long as the documentation is followed, since the documentation asserts that called functions are not allowed to have side effects.
This fixes overhead reported in #115.