Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlocks in cipher ctr mt #7

Merged
merged 4 commits into from
Sep 8, 2016

Conversation

chutz
Copy link

@chutz chutz commented Sep 7, 2016

No description provided.

Patrick McLean added 4 commits September 7, 2016 11:40
…ES-CTR cipher

The threads spend a lot of time in pthread_cond_wait waiting for the
state of a queue to change, but sometimes a thread will change the state
of a queue without notifying other threads. This makes sure other
threads will always get notified to avoid deadlocks.

This uses pthread_cond_broadcast rather than pthread_cond_signal since
pthread_cond_signal only notifies one thread, which could end up being
the parent thread, which will just loop back to the cond, and nothing
will continue.
There is no gurantee that pthread_create will have filled in the thread
id field when the thread starts, so there was a race condition.
Sometimes the first thread would see c->tid[0] as 0, and not initialize
the first queue, and the entire thing would deadlock. This uses a rwlock
to make sure that the tid is filled in before trying to access it.
Currently it's possible that the other threads will transition the first
queue to another state than KQDRAINING before the starting thread gets
woken up, and if the queue never goes back to KQDRAINING then the init
thread will never continue.
…y are cancelled

It seems that on OSX a pthread_cancel does not necessarily wake up a
thread that is in pthread_cond_wait. This results in the process hanging
indefinetly when the main thread does a pthread_join on a thread that is
sleeping. This adds an explicit call to pthread_cond_broadcast to every
queue's condition so all the threads get woken up after they are
cancelled.
@rapier1 rapier1 merged commit 78b28a5 into rapier1:master Sep 8, 2016
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.

None yet

2 participants