Mutexes
면접 대비시간 제한2초메모리 제한512 MB
함수 호출과 뮤텍스 acquire, release, access 명령으로 이루어진 프로그램을 실행 순서대로 시뮬레이션하면서 가장 먼저 발생하는 corruption, deadlock, error를 찾는다.
문제
Anna loves coding multithreaded backend services. In such a service, multiple threads may sometimes need to read and write the same data structures in memory. To ensure all threads have a consistent view of a single datastructure, one can use so-called mutexes to protect access to it.
A mutex is an object that threads can acquire and release. When a mutex is acquired, the mutex cannot be acquired again until it is released -- even by the same thread! If a thread attempts to acquire a mutex it has already acquired, the thread will deadlock, waiting for itself to release the mutex.
Anna has written a program that consists of a number of functions. Each function consists of a list of commands that execute sequentially when the function is called. The commands are each one of:
- acquire the mutex named
- release the mutex named
- access a data structure protected by the mutex
- call another function
Anna is not sure if she implemented her mutexes correctly, and she wants your help to verify that three properties hold. Assuming a function main is called at the beginning of the program, you should check that:
- whenever a data structure protected by a mutex is to be accessed, the mutex is currently acquired,
- whenever a mutex is to be acquired, the program has not already acquired it (in order to avoid a deadlock),
- whenever a mutex is to be released, the program is currently holding it.
입력
The first line of the input contains an integer , the number of functions. This is followed by a description of all the functions.
The description of a function starts with an integer and a string , meaning that there is a function named with commands. This is followed by lines, each containing a command. The commands will be of the form:
acquire X-- the mutex named is acquiredrelease X-- the mutex named is releasedaccess X-- a data structure that must be protected by the mutex is accessedcall F-- the function called is called
All functions and mutexes have names between characters in length containing only characters a-z. No two functions will have the same name, and there will always be a function called main.
It is guaranteed that there is no infinite recursion: a function will never call itself, either directly or through a chain of other functions.
출력
If the program is free from errors, output a-ok.
Otherwise, output the first error that occurs during execution. Specifically:
- if a data structure is accessed without the correct mutex being acquired, output
corruption, - if a deadlock occurs, output
deadlock, - if a mutex is released without being acquired, output
error.
제한
Let denote the total number of instructions among all functions.