# A problem about multi-threading and IO

**URL:** <https://discourse.julialang.org/t/a-problem-about-multi-threading-and-io/96492>\
**Category:** General Usage\
**Tags:** question, multithreading, io\
**Created:** [March 23, 2023, 5:59am UTC](https://discourse.julialang.org/t/a-problem-about-multi-threading-and-io/96492 "2023-03-23T05:59:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fenyutanchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fenyutanchan/32/24081_2.png) [@fenyutanchan](https://discourse.julialang.org/u/fenyutanchan)\
**Post date:** [March 23, 2023, 5:59am UTC](https://discourse.julialang.org/t/a-problem-about-multi-threading-and-io/96492/1 "2023-03-23T05:59:10Z")

</div>

I’m trying write a code as

```plaintext
make_random_string(n::Int)::String = (prod ∘ map)(Char, rand(65:90, n))

function outer_string(n::Int)::Tuple{String, String}
    orig_str = make_random_string(n)
    result_io = IOBuffer()

    run(pipeline(`echo $orig_str`; stdout=result_io))
    result_str = (String ∘ take!)(result_io)

    return orig_str, result_str[begin:end-1]
end

function main()
    n_list = rand(10:100, 100)
    pushfirst!(n_list, 10^6)

    Threads.@threads for n ∈ n_list
    # for n ∈ n_list
        orig_str, rslt_str = outer_string(n)
        if orig_str != rslt_str
            @show n, orig_str, rslt_str
        end
    end
end

main()

```

Then, run `julia -t 8 main.jl`, it shows that

```plaintext
(n, orig_str, rslt_str) = (47, "WQRHRDILRKIVDDKOYNQWBUBBZJCCCMIGJPOEFASLMRPGQTN", "")
(n, orig_str, rslt_str) = (80, "AMFSFDGKTTNNGNHYXSOKYKVTIAPIMSIJYALREWIIKOFPFIQXPIGHOFDYJFIHGKLDLGHFOHQMHVGGWTFU", "")
(n, orig_str, rslt_str) = (29, "OOHSVEQJSPSVTWIVHWKJASCRANMSK", "")
(n, orig_str, rslt_str) = (49, "DVQXHVZDKCGCOAJGCDMZDISLMGBISLTJGLCNUUWTXSHHCQKYH", "")
(n, orig_str, rslt_str) = (59, "OSPSJJESVNZQVMHPCQHKOUNBTRIMTPUSNFNDCBPTGOVETBCKIRHGVLDFPFP", "")
(n, orig_str, rslt_str) = (45, "JHCWOYROYBOYYDDUOXZGXAKNFVFPZDCQMRBPNXMUAFKND", "")
(n, orig_str, rslt_str) = (23, "EAUVYYGFTJHHZLLQREEIZDZ", "")

```

Actually, `julia main.jl` returns no logs.  
It seems that there are some broken running.  
Why and how to correct the codes?
