'This test exercises the refct in multithreaded code'

def test_refct_mt(self):

    def pyfunc(n, inp):
        out = np.empty(inp.size)
        for i in range(out.size):
            out[i] = (inp[i] + 1)
        for i in range(n):
            (out, inp) = (inp, out)
        return out
    cfunc = nrtjit(pyfunc)
    size = 10
    input = np.arange(size, dtype=np.float)
    expected_refct = sys.getrefcount(input)
    swapct = random.randrange(1000)
    expected = pyfunc(swapct, input)
    np.testing.assert_equal(expected, cfunc(swapct, input))
    del expected
    self.assertEqual(expected_refct, sys.getrefcount(input))
    workers = []
    outputs = []
    swapcts = []
    def wrapped(n, input, out):
        out[:] = cfunc(n, input)
    for i in range(100):
        out = np.empty(size)
        swapct = random.randrange(1000)
        thread = threading.Thread(target=wrapped, args=(swapct, input, out), name='worker{0}'.format(i))
        workers.append(thread)
        outputs.append(out)
        swapcts.append(swapct)
    for thread in workers:
        thread.start()
    for thread in workers:
        thread.join()
    for (swapct, out) in zip(swapcts, outputs):
        np.testing.assert_equal(pyfunc(swapct, input), out)
    del outputs, workers
    self.assertEqual(expected_refct, sys.getrefcount(input))
