The basic system is pretty simple: just make sure the points you're tracking on the cloth don't move further than a certain distance away from each other. Doing it on the GPU is a bit tricky because you have to know which constraints you can check in parallel.