1. A computer-implemented method of acquiring ownership of a shared resource in a multi-threaded computing environment, comprising: for each set of multiple sets of N successive attempts by a first thread acquire ownership of the shared resource: for each of a predetermined number of the N attempts of the set, executing a spin procedure during which the first thread repeatedly determines whether the shared resource is owned by another thread, the spin procedure terminating upon the earlier of (i) successfully obtaining ownership of the shared resource, or (ii) reaching a predetermined execution time limit; and for a remainder of the N attempts of the set, determining whether the shared resource is owned by the another thread, and if so then executing a blocking procedure which temporarily suspends execution of the first thread; periodically adjusting the value of N based on the extent to which at least one recent execution of the spin procedure has terminated successfully; and measuring the duration of a context switching operation within the computing environment, and wherein the predetermined execution time limit is made substantially equal to the measured duration of the context switching operation.