Skip to content

prevent undefined behavior with LTC_PTHREAD#337

Merged
sjaeckel merged 1 commit intodevelopfrom
fix/prng_pthread
Dec 10, 2017
Merged

prevent undefined behavior with LTC_PTHREAD#337
sjaeckel merged 1 commit intodevelopfrom
fix/prng_pthread

Conversation

@sjaeckel
Copy link
Copy Markdown
Member

@sjaeckel sjaeckel commented Dec 7, 2017

While reading through through man pthread_mutex_init I stumbled over this:
"Attempting to initialize an already initialized mutex results in undefined behavior."

This patch should prevent this undefined behavior.

@sjaeckel sjaeckel requested a review from karel-m December 7, 2017 13:54
as of `man pthread_mutex_init`:

"Attempting to initialize an already initialized mutex
results in undefined behavior."
@sjaeckel sjaeckel merged commit 45db2a9 into develop Dec 10, 2017
@sjaeckel sjaeckel deleted the fix/prng_pthread branch December 10, 2017 11:35
@rofl0r
Copy link
Copy Markdown

rofl0r commented Dec 10, 2017

now that i think about it, it seems curious that you need mutexes at all. you pass a struct containing the entire context to each of the prng function, so this seems quite thread-safe to me.

@sjaeckel
Copy link
Copy Markdown
Member Author

... so this seems quite thread-safe to me

really? even in case you're sharing one prng state in multiple threads?

@rofl0r
Copy link
Copy Markdown

rofl0r commented Dec 17, 2017

if you share state among threads you must of course protect it with locks if you modify it, but this is the first time i see the library doing the locking "for you". it is generally considered to be the responsibility of the library user to prevent concurrent updates.

@sjaeckel
Copy link
Copy Markdown
Member Author

but this is the first time i see the library doing the locking "for you"

well that's already in there for a long time, there are also some static mutexes for e.g. the cipher/hash/prng registry or in the ecc code for the tables... just look it up...

I also think that it's up to the library-user to take care of that, but as it's not enabled by default he already does that by compiling ltc with pthread-support ;)

sjaeckel added a commit that referenced this pull request Jan 14, 2018
prevent undefined behavior with LTC_PTHREAD
(cherry picked from commit 45db2a9)
@sjaeckel sjaeckel added this to the next milestone Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants