rping: create persistent server threads in DETACHED state
PATCH 1/1 rping: create persistent server threads in DETACHED state
Since the persistent server threads aren't joined, they must be created in the DETACHED state or resources will not be cleaned up when they exit. This results in pthread_create() failures after thousands of rping instances are run against a persistent server.
Also check the return from all calls to pthread_create() so we don't ignore a thread creation failure.
---
examples/rping.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 42 insertions(+), 5 deletions(-)
examples/rping.c +42 -5
@@ -793,7 +793,11 @@ static void *rping_persistent_server_thread(void *arg) goto err2; } -pthread_create (&cb->cqthread,NULL , cq_thread, cb); + ret =pthread_create (&cb->cqthread,NULL , cq_thread, cb); +if (ret) { +perror ("pthread_create" ); + goto err2; + } ret =rping_accept (cb);if (ret) {
@@ -825,11 +829,27 @@ static int rping_run_persistent_server(struct rping_cb *listening_cb) {int ret;struct rping_cb *cb; +pthread_attr_t attr; ret =rping_bind_server (listening_cb);if (ret)return ret; +/* +* Set persistent server threads to DEATCHED state so +* they release all their resources when they exit. +*/ + ret =pthread_attr_init (&attr); +if (ret) { +perror ("pthread_attr_init" ); +return ret; + } + ret =pthread_attr_setdetachstate (&attr,PTHREAD_CREATE_DETACHED ); +if (ret) { +perror ("pthread_attr_setdetachstate" ); +return ret; + } +while (1 ) {sem_wait (&listening_cb->sem);if (listening_cb->state !=CONNECT_REQUEST ) {
@@ -841,7 +861,12 @@ static int rping_run_persistent_server(struct rping_cb *listening_cb) cb =clone_cb (listening_cb);if (!cb)return -1 ; -pthread_create (&cb->persistent_server_thread,NULL , rping_persistent_server_thread, cb); + + ret =pthread_create (&cb->persistent_server_thread, &attr, rping_persistent_server_thread, cb); +if (ret) { +perror ("pthread_create" ); +return ret; + } }return 0 ; }
@@ -880,7 +905,11 @@ static int rping_run_server(struct rping_cb *cb) goto err2; } -pthread_create (&cb->cqthread,NULL , cq_thread, cb); + ret =pthread_create (&cb->cqthread,NULL , cq_thread, cb); +if (ret) { +perror ("pthread_create" ); + goto err2; + } ret =rping_accept (cb);if (ret) {
@@ -1055,7 +1084,11 @@ static int rping_run_client(struct rping_cb *cb) goto err2; } -pthread_create (&cb->cqthread,NULL , cq_thread, cb); + ret =pthread_create (&cb->cqthread,NULL , cq_thread, cb); +if (ret) { +perror ("pthread_create" ); + goto err2; + } ret =rping_connect_client (cb);if (ret) {
@@ -1222,7 +1255,11 @@ int main(int argc, char *argv[]) }DEBUG_LOG ("created cm_id %p\n" , cb->cm_id); -pthread_create (&cb->cmthread,NULL , cm_thread, cb); + ret =pthread_create (&cb->cmthread,NULL , cm_thread, cb); +if (ret) { +perror ("pthread_create" ); + goto out2; + }if (cb->server) {if (persistent_server)
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20150112165740.17112.18209.stgit-T4OLL4TyM9aNDNWfRnPdfg@public.gmane.org
Hey Sean,
Does this patch look ok?
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 54BE75FA.1000307-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org
PiBEb2VzIHRoaXMgcGF0Y2ggbG9vayBvaz8NCg0KSXQgbG9va3Mgb2theSBhdCBhIGdsYW5jZS4g IFNvcnJ5LCBJIGhhdmVuJ3QgbG9zdCB0aGlzLCBidXQganVzdCBoYXZlbid0IGhhZCB0aW1lIHRv IGFwcGx5IGl0Lg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
VGhhbmtzIC0gYXBwbGllZA0KDQo=
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html