If you don't need it, never lock something within a loop (this holds for images as for banks - similar as it already has been in old blitz with buffers), as it will always become far slower if you lock - unlock within the loop.
But the "best way" depends on the actual use you need it for.
But the "best way" depends on the actual use you need it for.