Probably safer would be to protect all access to tree with a helper function getTree() which did

    CriticalBlock b(crit);
    checkDirtyReload();
    return LINK(tree);

and then call.

    Owned<IPropertyTree> t = getTree();
    toXML(t, s);

- It would hold the critical section for a shorter duration.
- Other functions like getPackageMap() aren't currently thread safe.
- other functions like findAllQueriesUsingFile() would correctly check for dirty.