# Concurrency violation detect

**URL:** https://discourse.julialang.org/t/concurrency-violation-detect/67678
**Category:** New to Julia
**Tags:** distributed, sockets
**Created:** [September 4, 2021, 4:50am UTC](https://discourse.julialang.org/t/concurrency-violation-detect/67678 "2021-09-04T04:50:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Beh123](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@Beh123](https://discourse.julialang.org/u/Beh123)
#### Post date: [September 4, 2021, 4:50am UTC](https://discourse.julialang.org/t/concurrency-violation-detect/67678/1 "2021-09-04T04:50:29Z")

</div>

Hi everyone.  
I have 2 threads. First, is reading data from udp. Second, process data. When I use @distributed before loops, I have concurrency violation. This is my code.

```julia

using Distributed , Sockets
using ThreadPools
addprocs(10, lazy=false);
function rec_data(port::Integer, to::Sockets.InetAddr, chan::Channel)
    sock=UDPSocket()
    if bind(sock, Sockets.localhost, port)
        Threads.@spawn begin
            while true
                from, pck = recvfrom(sock)
                msg = serialize(pkg)
                if msg == :exit
                    break
                else
                    put!(chan, msg) # send it to the broker
                end
            end
            close(sock)
        end
    else
        println(stderr, "port $port not available")
    end
end

function broker(chan::Channel)
    Index=0;
while true
        msg = take!(chan)
        Index=index+1;
        if index==10
             Index=0;
            @distributed for I in 1:10 
                do_complicated_processing_and_send(data)
            end
        end
    end
end

queuelength = 8000 # or something long enough
chan = Channel{Array{UInt8,1}}(queuelength)
rectask = ThreadPools.@tspawnat 2 rec_data(port, to, chan)
brokertask = ThreadPools.@tspawnat 1 broker(chan)

```

What is my problem?  
Thanks

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [September 4, 2021, 1:00pm UTC](https://discourse.julialang.org/t/concurrency-violation-detect/67678/2 "2021-09-04T13:00:32Z")

</div>

Can you provide a full MWE (including `do_complicated_processing_and_send`) as well as a full error and stacktrace? Distributed is not currently threadsafe, so you may have to work around this limitation.
