@@ -129,6 +129,7 @@ static void *socket_thread(void *arg)
129129int container_runner_dispatch (struct ocre_container * container , int socket )
130130{
131131 struct runner * runner = NULL ;
132+ pthread_attr_t attr ;
132133
133134 runner = malloc (sizeof (struct runner ));
134135 if (!runner ) {
@@ -147,18 +148,37 @@ int container_runner_dispatch(struct ocre_container *container, int socket)
147148 goto error_runner ;
148149 }
149150
151+ rc = pthread_attr_init (& attr );
152+ if (rc ) {
153+ fprintf (stderr , "Failed to initialize thread attributes: rc=%d" , rc );
154+ goto error_mutex ;
155+ }
156+
157+ rc = pthread_attr_setdetachstate (& attr , PTHREAD_CREATE_DETACHED );
158+ if (rc ) {
159+ fprintf (stderr , "Failed to initialize thread attributes: rc=%d" , rc );
160+ goto error_attr ;
161+ }
162+
163+ /* The socket thread is joinable */
150164 rc = pthread_create (& runner -> socket_thread , NULL , socket_thread , runner );
151165 if (rc ) {
152166 fprintf (stderr , "Failed to create socket thread: rc=%d" , rc );
153167 goto error_mutex ;
154168 }
155169
156- rc = pthread_create (& runner -> run_thread , NULL , run_thread , runner );
170+ /* The run_thread is detached */
171+ rc = pthread_create (& runner -> run_thread , & attr , run_thread , runner );
157172 if (rc ) {
158173 fprintf (stderr , "Failed to create runner thread: rc=%d" , rc );
159174 goto error_thread ;
160175 }
161176
177+ rc = pthread_attr_destroy (& attr );
178+ if (rc ) {
179+ fprintf (stderr , "Failed to destroy thread attributes: rc=%d" , rc );
180+ }
181+
162182 return 0 ;
163183
164184error_thread :
@@ -176,6 +196,12 @@ int container_runner_dispatch(struct ocre_container *container, int socket)
176196
177197 pthread_join (runner -> socket_thread , NULL );
178198
199+ error_attr :
200+ rc = pthread_attr_destroy (& attr );
201+ if (rc ) {
202+ fprintf (stderr , "Failed to destroy thread attributes: rc=%d" , rc );
203+ }
204+
179205error_mutex :
180206 pthread_mutex_destroy (& runner -> mutex );
181207
0 commit comments