Repository navigation
Clean up thread-local memory - #3771
Conversation
|
I closed #3530 since it turned out that calling InitAPI/ShutdownAPI from different threads is not a good idea. |
Thanks for the comment. We might decide to implement this fix even if it's not blocking anyone as it seems like a good idea. |
There is now a third case where this condition is causing problems: awslabs/aws-c-io#478 |
Are you suggesting that it is not a good idea to implement this fix? This change is technically unrelated to potential errors when calling InitAPI/ShutdownAPI from different threads. |
bd67326 to
35a346b
Compare
Resolved issues:
resolves #3525
Description of changes:
Adds a pthread key so that we can clean up the allocated thread-local memory without having to call s2n_cleanup in every thread.
Also I re-wrote the init test to make it more clean and add more cases.
Call-outs:
Was floating the idea of having one key to cleanup all thread-local storage, but I don't like this design. It means that the destructor function would be called multiple times potentially, so that cleanup function must be idempotent. This isn't that big of a deal, but it feels kind of dangerous. I'd rather create a key for each type of data that is thread-local.
Testing:
Adds a test that shows that you can call s2n_init in a different thread without calling s2n_cleanup.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.