Skip to content

Commit 38adedd

Browse files
committed
Make temporaries in the glue script thread safe
This emits all temporaries as 'static thread_local <type> temp;' instead of 'static <type> temp;' and prevents race conditions when you use the resulting library in a multithreaded environment. When compiling without -pthread, the thread_local attribute is ignored and the generated code is as it was before.
1 parent 10cb9d4 commit 38adedd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/webidl_binder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ def make_call_args(i):
629629
if non_pointer:
630630
return_prefix += '&'
631631
if copy:
632-
pre += ' static %s temp;\n' % type_to_c(return_type, non_pointing=True)
632+
# Avoid sharing this static temp var between threads, which could race.
633+
pre += ' static thread_local %s temp;\n' % type_to_c(return_type, non_pointing=True)
633634
return_prefix += '(temp = '
634635
return_postfix += ', &temp)'
635636

0 commit comments

Comments
 (0)