Strange minifilter behaviour

Hello everyone.
I am developing a minifilter driver that has to detect ransomware based on modified files. I made a small program to test this, it walks through files and modify them randomly. The program is single threaded, but here comes the best part. When it reaches 5 modified files, the minifilter begin to analyse them and won’t return until the analysis is complete. This means I should not receive any IRP_MJ_CREATE from this process, but they still come.
Is there a way to avoid cases like this?

Global lock.

But how it is possible to get more IRP_MJ_CRATE requests from the same process with one thread if I’m not returning from the callback?

Malware won’t be conforming to your tests.

APCs can cause what you describe.
Presuming it is the same thread actually. RTL can make its own threads and
access files from them.

I suggest posting a stack trace for the thread that analyses the
modifications, and of the 6th IRP_MJ_CREATE.

Catching malware will be the goal, but first I want to make sure this case is work as I intend. It seems IRP_MJ_CREATE works correctly, in fact. The problem might in the fact that the files are not modified as I expected. For example, after modifing 5 files, I should be able to give a verdict. But the files might be not be modified so I can analyse them as I should. And it seems this is the case actually, the files are not modified when opening the 6th file.