Unable to watch more than 64 directories on Windows #70
Description
I am using pathwatcher in my own component and love it. I was using it the other day in a bigger project and all of the sudden I wasn't getting any notifications anymore.
After debugging pathwatcher it turns out to be a limitation in the Windows API that pathwatcher uses:
DWORD r = WaitForMultipleObjects(copied_events.size(),
copied_events.data(),
FALSE,
INFINITE);
in function PlatformThread() in pathwatcher_win.cc
Luckily there is a workaround to this problem given in the documentation on MSDN
https://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
To wait on more than MAXIMUM_WAIT_OBJECTS handles, use one of the following methods:
- Create a thread to wait on MAXIMUM_WAIT_OBJECTS handles, then wait on that thread plus the other handles. Use this technique to break the handles into groups of MAXIMUM_WAIT_OBJECTS.
- Call RegisterWaitForSingleObject to wait on each handle. A wait thread from the thread pool waits on MAXIMUM_WAIT_OBJECTS registered objects and assigns a worker thread after the object is signaled or the time-out interval expires.
Can this be fixed please ?
Btw, with your 65th directory the PlatformThread() function ends up in a continuous loop that uses 100% CPU as the function doesn't wait anymore but returns immediately. At a minimum the code should check the size and not pass in more than 64 objects.