From 99c0f64b34a488bf167657fca0e6c5c0adbbd1bf Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Thu, 2 Jun 2016 12:22:41 -0700 Subject: [PATCH] expr_parser: fix concurrent use issues Change-Id: Ic9ef5d42f4348ada5c418a36118660e79a1a689b Signed-off-by: Andrew Boie --- scripts/expr_parser.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/expr_parser.py b/scripts/expr_parser.py index a9bd4d73fc8..91aaa555b7b 100644 --- a/scripts/expr_parser.py +++ b/scripts/expr_parser.py @@ -17,6 +17,7 @@ import sys import os import copy +import threading try: import ply.lex as lex @@ -204,14 +205,21 @@ def ast_expr(ast, env): elif ast[0] == "exists": return True if ast_sym(ast[1], env) else False +mutex = threading.Lock() def parse(expr_text, env): """Given a text representation of an expression in our language, use the provided environment to determine whether the expression is true or false""" - ast = parser.parse(expr_text) - return ast_expr(ast, env) + # Like it's C counterpart, state machine is not thread-safe + mutex.acquire() + try: + ast = parser.parse(expr_text) + finally: + mutex.release() + + return ast_expr(ast, env) # Just some test code if __name__ == "__main__":