aboutsummaryrefslogtreecommitdiff
path: root/examples/idle.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/idle.c')
-rw-r--r--examples/idle.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/examples/idle.c b/examples/idle.c
index 30e106db..87a03924 100644
--- a/examples/idle.c
+++ b/examples/idle.c
@@ -152,14 +152,20 @@ int main(int argc, char *argv[]) {
.display = display,
};
- if (simulate_activity_timeout != 0 && simulate_activity_timeout < close_timeout) {
+ bool create_t1 = (simulate_activity_timeout != 0) &&
+ (simulate_activity_timeout < close_timeout);
+
+ if (create_t1) {
if (pthread_create(&t1, NULL, &simulate_activity, (void *)&arg) != 0) {
return -1;
}
}
- if (close_timeout != 0) {
+
+ bool create_t2 = (close_timeout != 0);
+
+ if (create_t2) {
if (pthread_create(&t2, NULL, &close_program, (void *)&arg) != 0) {
- if (simulate_activity_timeout != 0) {
+ if (create_t1) {
pthread_cancel(t1);
}
return -1;
@@ -170,18 +176,19 @@ int main(int argc, char *argv[]) {
fprintf(stdout, "waiting\n");
if (pthread_create(&t3, NULL, &main_loop, (void *)display) != 0) {
- if (simulate_activity_timeout != 0) {
+ if (create_t1) {
pthread_cancel(t1);
}
- if (close_timeout != 0 ) {
+ if (create_t2) {
pthread_cancel(t2);
}
+ return -1;
}
- if (simulate_activity_timeout != 0) {
+ if (create_t1) {
pthread_join(t1, NULL);
}
- if (close_timeout != 0) {
+ if (create_t2) {
pthread_join(t2, NULL);
}
pthread_cancel(t3);