After there I want to run ZwUnloadDriver. Function DriverUnload must terminate thread… function PsTerminateSystemThread terminationg only current thread. function ZwTerminateThread is in ntdll, but not in ntoskrnl.
I would create an event and waited on this event (probably besides few other objects) in the thread routine instead of the KeDelayExecutionThread. Once I need to unload driver I would signal that event so the thread routine left waiting and called PsTerminateSystemThread. At the same time DriverUnload can wait for the thread to exit by waiting on the thread object.
Alternatively (less modifications in your code but not that nice) you can create some global variable and check its state in your Func: