Improve multi-threading support

In previous versions YR_RULES objects can't be used by more than MAX_THREADS during the whole lifetime of the object. Now this limit applies to the number of threads *simultaneosly* using the object.