# Help implementing parallelism with readbytes!

**URL:** <https://discourse.julialang.org/t/help-implementing-parallelism-with-readbytes/92672>\
**Category:** Performance\
**Tags:** question, binaryio, multithreading\
**Created:** [January 8, 2023, 1:46pm UTC](https://discourse.julialang.org/t/help-implementing-parallelism-with-readbytes/92672 "2023-01-08T13:46:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [January 8, 2023, 3:18pm UTC](https://discourse.julialang.org/t/help-implementing-parallelism-with-readbytes/92672/2 "2023-01-08T15:18:52Z")

</div>

I would create a single channel first, and then have two functions, one which continuous writes to the channel (reading the bytes) and another which processes.

```julia
c=Channel{ByteDataType}(1) #replace with the actual type
function read_data!(c, f
    open(f, 'r') do file
        while !eof(file)
             data=readbytes!(file) # read a chunk
             put!(c, data)
        end
    end
end
function process_data!(c)
    while isopen(c)
        data=take!(c)
        # process the data
    end
end
processing_task = Threads.@spawn process_data!(c)
read_data!(c, "filename.dat") # can read on main thread
wait(processing_task)

```

Sorry for the " pseudocodeness", I am on my phone and can’t run anything now. I hope it is clear nonetheless.

---

_[View the full topic](https://discourse.julialang.org/t/help-implementing-parallelism-with-readbytes/92672)._
