An elementary geometric interpretation of Carathéodory's Theorem (see Example REF ) and the geodesic structure of a \(\operatorname{CAT}(0)\)  space leads us to define a set operation that we call threading. This notion helps us derive sufficient conditions for when the closure of the convex hull of a compact set is compact.
Essentially threading of a set \(S\subseteq X\)  is the union of all geodesic segments with endpoints in \(S\) . It is well behaved under the intersections and unions of sets and satisfies certain monotonicity properties. Moreover this operation preserves compactness. This has an important implication for our main problem. If the underlying space is of finite type then for every compact set its convex hull is compact. In relation to this topic Kopečka and Reich have made the following important observation that it suffices to consider the problem for finite sets only [1]} i.e. for any finite set \(\lbrace x_1,\cdots ,x_n\rbrace \subseteq X\) , if \(\operatorname{cl}\operatorname{co}\lbrace x_1,\cdots ,x_n\rbrace \)  is compact then for each compact set \(S\subseteq X\)  the closure of its convex hull \(\operatorname{cl}\operatorname{co}S\)  is compact. To verify this condition it is enough then to show that every finite set has a finite threading degree. Moreover using our theory of threading we are able to show that at least in the case of flat complete \(\operatorname{CAT}(0)\)  spaces the closure of the convex hull of any compact set is compact. This in turn solves the problem for a certain class of \(\operatorname{CAT}(0)\)  spaces. As a practical application of our theory we consider the computation of the Fréchet mean from a given finite set of points. We prove that in a \(\operatorname{CAT}(0)\)  space of finite type the Fréchet mean of a finite set \(S\)  lies in the convex hull \(\operatorname{co}S\)  and it is constructible from \(S\)  in at most a finite number of steps. The Fréchet mean is relevant in computational biology, in particular for computing the average phylogenetic tree from a given finite collection of phylogenetic trees see e.g. the seminal work of [2]}[Billera et al.] and more recently [3]}[Owen et al.].
