I need to detect a deadlock by adding some code to the process's main function or inside his handler (HandleEvent()) using only: NewThread, Semaphore, GetMessage, Write2memory, ReadFromMemory.

...