Skip to content

Instantly share code, notes, and snippets.

@sadi304
Created April 14, 2019 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadi304/d6ef1be20a983ff374b0ef9624ab2b20 to your computer and use it in GitHub Desktop.
Save sadi304/d6ef1be20a983ff374b0ef9624ab2b20 to your computer and use it in GitHub Desktop.
Check whether a schedule is conflict serializable or not
# schedule
schedule = "r1(x) r1(y) w2(x) w1(x) r2(y)".split(' ')
final_schedule = {}
cycles = {}
i_index = 0
for i in schedule:
i_index += 1
i_operation_type, i_transaction, i_operator = i[0], i[1], i[3]
j_index = 0
for j in schedule:
j_index += 1
j_operation_type, j_transaction, j_operator = j[0], j[1], j[3]
if((i_transaction != j_transaction) and (i_operator == j_operator) and (i_operation_type+''+j_operation_type != 'rr') and j_index > i_index):
if(i_transaction + '' + j_transaction not in final_schedule.values()):
final_schedule[i + '-->' + j] = i_transaction + '' + j_transaction
# print(final_schedule)
for k,v in final_schedule.items():
for k1,v1 in final_schedule.items():
if(v == v1[::-1]):
cycles[k] = v
print("Schedule: ")
for k,v in final_schedule.items():
print('T'+v[0]+' --> '+'T'+v[1])
if(len(cycles)):
print("Cycles found: ")
for k,v in cycles.items():
print('T'+v[0]+' --> '+'T'+v[1], end=" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment