summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-11-17 01:51:15 -0500
committerTavian Barnes <tavianator@gmail.com>2010-11-17 01:51:15 -0500
commit294d815e27f3fe79df463b5504ca9099667574d8 (patch)
treee965ad598bd644a24808b9ed08ac9293693ea140
parentadb2f0d80f6146baa188770aeb678a8426892ccc (diff)
downloaddimension-294d815e27f3fe79df463b5504ca9099667574d8.tar.xz
Fix race when one worker thread errors out.
-rw-r--r--libdimension/raytrace.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index df3d973..74f4557 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -122,14 +122,23 @@ dmnsn_raytrace_scene_thread(void *ptr)
}
}
+ /* Join the rest of the threads after detecting an error, so we don't
+ free anything out from under them */
+ bool join_failed = false;
+ bool error_seen = false;
for (int i = 0; i < nthreads; ++i) {
void *ptr = NULL;
- if (pthread_join(threads[i], &ptr)) {
+ if (pthread_join(threads[i], &ptr) != 0)
+ join_failed = true;
+ if (!ptr)
+ error_seen = true;
+ }
+ if (join_failed) {
dmnsn_error(DMNSN_SEVERITY_MEDIUM,
"Couldn't join worker thread in raytrace engine.");
- }
- if (!ptr)
- dmnsn_error(DMNSN_SEVERITY_HIGH, "Error occurred in worker thread.");
+ }
+ if (error_seen) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Error occurred in worker thread.");
}
dmnsn_complete_timer(payload->scene->render_timer);