Re: DBUS - how to handle muliple bus-message in parallel

Lawrence D'Oliveiro <ldo-kC51rjc0cqs1dNLGKZg6taU/[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Organization Geek Central
Message-ID <[email protected]>
On Thu, 23 Aug 2018 14:10:51 +1200, I wrote:

> Enclosed is a reasonably fully-worked example ...

Hmm, threads can leave zombies too, just like processes. Need to call
pthread_join to clean these up. Patch enclosed.

--- a/slow_dbus_server.c
+++ b/slow_dbus_server.c
@@ -102,6 +102,7 @@ struct workqueue_entry
     DBusMessage * request;
     int valtype;
     unsigned long limit, result;
+    pthread_t worker; /* for join call */
   };
 static struct workqueue_entry
   /* completed work entries */
@@ -356,6 +357,14 @@ static void handle_event(void)
                     break;
                   } /*if*/
                 finished = finished->next;
+                  {
+                    const int err = pthread_join(entry->worker, NULL);
+                    if (err != 0)
+                      {
+                        fprintf(stderr, "error %d jointing thread %d: %s\n", err, strerror(err), entry->worker);
+                        die();
+                      } /*if*/
+                  }
                 DBusMessage * const reply = dbus_message_new_method_return(entry->request);
                 if (reply == NULL)
                   {
@@ -612,17 +621,16 @@ static DBusHandlerResult handle_message
                     context->request = dbus_message_ref(message);
                     context->valtype = signature[0];
                     context->limit = limit;
-                    pthread_t child;
                     const int err = pthread_create
                       (
-                        /*thread =*/ &child,
+                        /*thread =*/ &context->worker,
                         /*attr =*/ NULL,
                         /*start_routine =*/ compute_primes,
                         /*arg =*/ context
                       );
                     if (err == 0)
                       {
-                        fprintf(stderr, "child thread %d created.\n", child);
+                        fprintf(stderr, "child thread %d created.\n", context->worker);
                       }
                     else
                       {
_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.