Spin structures and boundary conditions for worldsheet fermions The definition I'm aware of a spin structure is the following one:

Definition: Let $(M,g)$ be a semi-Riemannian manifold with signature $(p,q)$. Let ${\cal F}M$ be the principal ${\rm SO}(p,q)$-bundle of orthonormal frames and let $\rho : {\rm Spin}(p,q)\to {\rm SO}(p,q)$ be the covering map. A spin structure is a principal ${\rm Spin}(p,q)$-bundle ${\cal S}M$ over $M$ together with a principal bundle map $\Phi:{\cal S}M\to {\cal F}M$ such that $$\Phi(E\cdot g)=\Phi(E)\cdot \rho(g),\quad \forall E\in{\cal S}M,g\in {\rm Spin}(p,q).$$

On the other hand, studying string theory in the book by Blumenhagen, Lüst and Theisen, the authors say that a Riemann surface $\Sigma_g$ of genus $g$ has $2^{2g}$ inequivalent spin structures. They ellaborate by talking about boundary conditions (page 224):

We know from Chap. 6 that there are two non-contractible loops associated with each of the $g$ holes. All other non-contractible loops can be generated by deforming and joining elements of this basis. When we have spinors defined over $\Sigma_g$ we can assign them either periodic or anti-periodic boundary conditions around each of the $2g$ loops. Each of these $2^{2g}$ possible assignments is called a spin structure on $\Sigma_g$.

I can't see the relation between these two ideas. I mean, why the assignment of boundary conditions around each of the $2g$ loops will give rise to a spin structure in the sense of the definition above? Why these two things are the same?
 A: Let's consider the torus glued from two cylinders $C_1$ and $C_2$ with trivial spin bundles over them. We know there are four different spin bundles over the torus, how do we get them from choosing a transition function $t_{12} : U_1\cap U_2 \to \mathrm{Spin}$ on the two (thickened) circles where the cylinders overlap? Let's split this into two "partial" transition functions $t_1,t_2 : S^1 \to \mathrm{Spin}$. The choice for the trivial bundle on the torus is clearly $t_1 = t_2 = 1$. A second bundle arises from choosing $t_1 = 1; t_2 = -1$:
Bundles constructed from patches via gluing are isomorphic if there are functions $f_i : C_i \to G$ on the glued parts such that $t_{12} f_2 = f_1 t_{12}$ on the overlap. Since the $C_i$ are connected but 1 and -1 lie in different connected parts of $\mathrm{Spin}(1,1)$, there are no smooth functions such that $f_1 = f_2$ on one circle and $f_1 = -f_2$ on the other, therefore the bundles for $t_1 = t_2 = 1$ and $t_1 = 1; t_2 = -1$ are non-isomorphic.
Now if we look at the spinor field $\psi$ (really a section of some associated bundle to the spin bundle) in the patches $C_i$, then we have two fields $\psi_i$ with $\psi_1 = t_{12} \psi_2$. Clearly, in the trivial case, this is just $\psi_1 = \psi_2$ and so we can pretend we have a spinor field with periodic conditions. In the case where the $t_i$ have different signs, we get that our $\psi_i$ agree on one of the overlap circles but have $\psi_1 = -\psi_2$ on the other - so we have an "antiperiodic boundary condition" going around the fundamental loop orthogonal to the overlapping circles.
If we choose the two $C_i$ in "the other direction", i.e. if we glue the torus together longitudinally instead of latitudinally, we get a another non-trivial bundle. Combining both of these gluing methods (yes, this is handwavy but you should be able to make it precise considering the actual minimal four charts on the torus) gives us four different bundles: Trivially glued along both fundamental loops, non-trivially glued along either one of them and non-trivially glued along both of them, and they corresponding to the "boundary conditions" for spinors as described above.
(That this exhausts all possible bundles, i.e. that there are $2^{2g}$ possible bundles is proven by connecting spin bundles to the algebraic geometry of Riemann surfaces, see Atiyah's "Riemann Surfaces and Spin Structures".)
This reasoning extends to all Riemann surfaces by viewing them as the $g$-fold connected sum of the torus with itself.
