Retrieve a value within a do block

Is my “feasible” method above correct? I’m a bit unclear now, since do is a hard local block.

julia> function f(af)
           a = 3
           println("inside function: a = $a")
       end
f (generic function with 1 method)

julia> a = 0;

julia> for i = 1:1
           a = 2
           f() do
               a = 7
           end
           println("inside for: a = $a")
       end
inside function: a = 3
inside for: a = 2

julia> a
2

Given this fact, how can my following analogous code be made correct?

julia> Threads.nthreads()
4

julia> using JuMP

julia> my_lock = Threads.ReentrantLock();

julia> model = Model();

julia> JuMP.@variable(model, x[1:3]);

julia> for k = 1:1
           Threads.@threads for i = 1:3
               # The following line is indispensable. If it's absent, ERROR is seen
               cut = "the initial cut inside for i = $i"
               con = @build_constraint(x[i] <= i)
               Threads.lock(my_lock) do
                   cut = JuMP.add_constraint(model, con)
               end
               println("at the end of i = $i, cut = $cut")
           end
       end
at the end of i = 1, cut = x[1] <= 1
at the end of i = 3, cut = x[3] <= 3
at the end of i = 2, cut = x[2] <= 2

julia> print(model)
Feasibility
Subject to
 x[3] <= 3
 x[1] <= 1
 x[2] <= 2