#include #include #include #include #include #include DBusConnection *connection; typedef struct { int i; } ThreadData; void *fun(void *p) { DBusError error; ThreadData *d = (ThreadData *)p; int cnt = 1; while (1) { dbus_error_init (&error); DBusMessageIter iter; DBusMessage* message = dbus_message_new_method_call (NULL, "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); //dbus_message_ref (message); dbus_message_set_auto_start (message, TRUE); dbus_message_set_destination (message, "org.freedesktop.DBus"); dbus_message_iter_init_append (message, &iter); DBusMessage *reply = dbus_connection_send_with_reply_and_block (connection, message, 10, &error); if (dbus_error_is_set (&error)) fprintf(stderr, "%d %s %s\n",d->i, error.name, error.message); else dbus_message_unref(reply); dbus_message_unref(message); if (cnt++%10 == 0) fprintf(stderr, "%c",'A' + (char )d->i); } return 0; } ThreadData d[100]; int main(int argc, char **argv) { DBusError error; srand(time(0)); dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_SESSION, &error); int i; for (i = 0; i < 10; i++) { pthread_t thr; d[i].i = i; void *p = &d[i]; pthread_create(&thr, NULL, fun, p); } for (;;) sleep(1000); dbus_connection_unref(connection); return 0; }