mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Add the thread identifier to various multi-threaded programs and tests.
This commit is contained in:
@@ -149,6 +149,7 @@ worker_thread (void *thread_data_vp)
|
||||
size_t output_len = 0;
|
||||
guestfs_h *g;
|
||||
int err;
|
||||
char id[64];
|
||||
|
||||
/* Take the next domain from the list. */
|
||||
if (thread_data->verbose)
|
||||
@@ -191,6 +192,11 @@ worker_thread (void *thread_data_vp)
|
||||
return &thread_data->r;
|
||||
}
|
||||
|
||||
/* Set the handle identifier so we can tell threads apart. */
|
||||
snprintf (id, sizeof id, "thread_%zu_domain_%zu",
|
||||
thread_data->thread_num, i);
|
||||
guestfs_set_identifier (g, id);
|
||||
|
||||
/* Copy some settings from the options guestfs handle. */
|
||||
guestfs_set_trace (g, thread_data->trace);
|
||||
guestfs_set_verbose (g, thread_data->verbose);
|
||||
|
||||
@@ -1328,6 +1328,9 @@ safe to be called from multiple threads without a mutex.
|
||||
See the graphical program guestfs-browser for one possible
|
||||
architecture for multithreaded programs using libvirt and libguestfs.
|
||||
|
||||
Use L</guestfs_set_identifier> to make it simpler to identify threads
|
||||
in trace output.
|
||||
|
||||
=head2 PATH
|
||||
|
||||
Libguestfs needs a supermin appliance, which it finds by looking along
|
||||
|
||||
@@ -177,6 +177,8 @@ start_thread (void *statevp)
|
||||
pthread_exit (&state->exit_status);
|
||||
}
|
||||
|
||||
guestfs_set_identifier (g, state->mp);
|
||||
|
||||
if (guestfs_add_drive_scratch (g, 512*1024*1024, -1) == -1)
|
||||
goto error;
|
||||
if (guestfs_launch (g) == -1)
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#define NR_THREADS 5
|
||||
|
||||
struct thread_state {
|
||||
size_t thread_num; /* Thread number. */
|
||||
pthread_t thread; /* Thread handle. */
|
||||
int exit_status; /* Thread exit status. */
|
||||
};
|
||||
@@ -89,6 +90,7 @@ main (int argc, char *argv[])
|
||||
sigaction (SIGQUIT, &sa, NULL);
|
||||
|
||||
for (i = 0; i < NR_THREADS; ++i) {
|
||||
threads[i].thread_num = i;
|
||||
/* Start the thread. */
|
||||
r = pthread_create (&threads[i].thread, NULL, start_thread,
|
||||
&threads[i]);
|
||||
@@ -117,6 +119,7 @@ start_thread (void *statevp)
|
||||
struct thread_state *state = statevp;
|
||||
guestfs_h *g;
|
||||
time_t start_t, t;
|
||||
char id[64];
|
||||
|
||||
time (&start_t);
|
||||
|
||||
@@ -133,6 +136,9 @@ start_thread (void *statevp)
|
||||
pthread_exit (&state->exit_status);
|
||||
}
|
||||
|
||||
snprintf (id, sizeof id, "%zu", state->thread_num);
|
||||
guestfs_set_identifier (g, id);
|
||||
|
||||
if (guestfs_add_drive_opts (g, "/dev/null",
|
||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
|
||||
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
|
||||
|
||||
@@ -199,6 +199,7 @@ start_thread (void *thread_data_vp)
|
||||
size_t i;
|
||||
guestfs_h *g;
|
||||
unsigned errors = 0;
|
||||
char id[64];
|
||||
|
||||
for (;;) {
|
||||
/* Take the next process. */
|
||||
@@ -237,6 +238,9 @@ start_thread (void *thread_data_vp)
|
||||
goto error;
|
||||
}
|
||||
|
||||
snprintf (id, sizeof id, "%zu", i);
|
||||
guestfs_set_identifier (g, id);
|
||||
|
||||
guestfs_set_trace (g, trace);
|
||||
guestfs_set_verbose (g, verbose);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user