# \#channel

**URL:** https://discourse.julialang.org/tag/channel/420.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Threads with Channels sometimes lead to weird code excecution](https://discourse.julialang.org/t/threads-with-channels-sometimes-lead-to-weird-code-excecution/130975)

<div class="topic-metadata">

**Author:** [@ncxst](https://discourse.julialang.org/u/ncxst)\
**Replies:** 11\
**Last updated:** [July 24, 2025, 12:23pm UTC](https://discourse.julialang.org/t/threads-with-channels-sometimes-lead-to-weird-code-excecution/130975 "2025-07-24T12:23:14Z")

</div>

Background story I had the problem, that I wanted to generate a certain object from random seeds, which only with a very low probability gives me the result I want. Too speed the calculation up I wanted to parallelize th…

---

## [Is \`put!\` of a \`RemoteChannel\` thread-safe](https://discourse.julialang.org/t/is-put-of-a-remotechannel-thread-safe/120866)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 0\
**Last updated:** [October 3, 2024, 6:18pm UTC](https://discourse.julialang.org/t/is-put-of-a-remotechannel-thread-safe/120866 "2024-10-03T18:18:36Z")

</div>

Hello, I have the following RemoteChannel channel = RemoteChannel(() -\> Channel{Bool}(), 1) Is the put!(channel, true) action thread-safe?

---

## [Core dumped when defining a Channel as constant](https://discourse.julialang.org/t/core-dumped-when-defining-a-channel-as-constant/119551)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 6\
**Last updated:** [September 18, 2024, 2:04pm UTC](https://discourse.julialang.org/t/core-dumped-when-defining-a-channel-as-constant/119551 "2024-09-18T14:04:58Z")

</div>

module M const C = Channel(ch -\> put!(ch, nothing), ctype=Nothing) end Precompiling this module leads to core dumped… \[16831\] signal (6.-6): Aborted in expression starting at REPL\[1\]:1 unknown function (ip: 0xffffb1270…

---

## [@take macro?](https://discourse.julialang.org/t/take-macro/114282)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 2\
**Last updated:** [May 15, 2024, 1:51pm UTC](https://discourse.julialang.org/t/take-macro/114282 "2024-05-15T13:51:19Z")

</div>

I’m using a Channel to keep a few instances of a struct that I need to use inside a thread (following the instructions in Thread-Safe Storage · OhMyThreads.jl): using OhMyThreads nthings = 4 const things = Channel{…

---

## [How to preallocate for a parallel monte carlo simulation?](https://discourse.julialang.org/t/how-to-preallocate-for-a-parallel-monte-carlo-simulation/107104)

<div class="topic-metadata">

**Author:** [@Taneli\_Tolppanen](https://discourse.julialang.org/u/Taneli_Tolppanen)\
**Replies:** 5\
**Last updated:** [December 8, 2023, 8:08am UTC](https://discourse.julialang.org/t/how-to-preallocate-for-a-parallel-monte-carlo-simulation/107104 "2023-12-08T08:08:22Z")

</div>

I am trying to run a series of monte carlo simulations. My simulation gives as an output a matrix. I would like to preallocate this matrix for each of the simulations, and also preallocate some work vectors since I am ru…

---

## [\[ANN\] PriorityChannels.jl](https://discourse.julialang.org/t/ann-prioritychannels-jl/19234)

<div class="topic-metadata">

**Author:** [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Replies:** 5\
**Last updated:** [September 17, 2023, 6:49pm UTC](https://discourse.julialang.org/t/ann-prioritychannels-jl/19234 "2023-09-17T18:49:04Z")

</div>

I’ve created a small package PriorityChannels.jl that implements a PriorityChannel that mimics Base.Channel , but where each element is associated with a priority. take! always returns the highest priority element. In…

---

## [Any small example of a queue like system, where a function is automatically executed when a new item pops in the queue?](https://discourse.julialang.org/t/any-small-example-of-a-queue-like-system-where-a-function-is-automatically-executed-when-a-new-item-pops-in-the-queue/86616)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 12\
**Last updated:** [September 2, 2022, 8:31pm UTC](https://discourse.julialang.org/t/any-small-example-of-a-queue-like-system-where-a-function-is-automatically-executed-when-a-new-item-pops-in-the-queue/86616 "2022-09-02T20:31:38Z")

</div>

Hello! I have some Julia code which detects when new files are made in a folder. The name of these files are then passed to a vector. Whenever a new item enters the vector, I wish to have a function detect this and run …

---

## [Put!(remotechannel, x) causes no error but an infinite run time](https://discourse.julialang.org/t/put-remotechannel-x-causes-no-error-but-an-infinite-run-time/79770)

<div class="topic-metadata">

**Author:** [@Himbeersternchen](https://discourse.julialang.org/u/Himbeersternchen)\
**Replies:** 3\
**Last updated:** [April 21, 2022, 10:48am UTC](https://discourse.julialang.org/t/put-remotechannel-x-causes-no-error-but-an-infinite-run-time/79770 "2022-04-21T10:48:11Z")

</div>

Hi Everyone, i m trying to use RemoteChannel in Julia: julia -p 2 x = RemoteChannel(()-\>Channel{Array{Float64,2}}(1)) a = \[1 2 3 4; 5 6 7 8\] put!(x,a) ran perfect. But the maximal length of channel x is 1. So i expe…

---

## [How to wait for a thread to complete](https://discourse.julialang.org/t/how-to-wait-for-a-thread-to-complete/78546)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 3\
**Last updated:** [March 27, 2022, 7:56pm UTC](https://discourse.julialang.org/t/how-to-wait-for-a-thread-to-complete/78546 "2022-03-27T19:56:10Z")

</div>

Hi all, I have a situation where I receive a message via ZMQ and would like to perform post processing of the reply on a separate thread and then send a reply from the main thread once the post processing is complete. I…

---

## [Why do take! and put! for channels allocate memory?](https://discourse.julialang.org/t/why-do-take-and-put-for-channels-allocate-memory/76513)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 1\
**Last updated:** [February 18, 2022, 6:00pm UTC](https://discourse.julialang.org/t/why-do-take-and-put-for-channels-allocate-memory/76513 "2022-02-18T18:00:20Z")

</div>

I ran a bunch of floats through some channels across threads to test it out and discovered that memory was being allocated during the process which seems odd. Increasing the count in the for loop increases the allocation…

---

## [Channel monitoring/statistics](https://discourse.julialang.org/t/channel-monitoring-statistics/53744)

<div class="topic-metadata">

**Author:** [@pmilovanov](https://discourse.julialang.org/u/pmilovanov)\
**Replies:** 3\
**Last updated:** [February 13, 2022, 6:53pm UTC](https://discourse.julialang.org/t/channel-monitoring-statistics/53744 "2022-02-13T18:53:05Z")

</div>

Before I reinvent the wheel, is there any conventional solution to track statistics on the state of channels during execution? E.g what’s the distribution of channel length over time (not size but items in channel) or di…

---

## [Channel take if available](https://discourse.julialang.org/t/channel-take-if-available/73252)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 1\
**Last updated:** [December 17, 2021, 1:55pm UTC](https://discourse.julialang.org/t/channel-take-if-available/73252 "2021-12-17T13:55:54Z")

</div>

Hi all :slight\_smile: Is there a way to take an element from a Channel if and only if there are elements available. This should be non blocking. I could do something like: julia\> c = Channel(10) Channel{Any}(10) (empt…

---

## [Use of Channels (or similar) constructs in parallel processing](https://discourse.julialang.org/t/use-of-channels-or-similar-constructs-in-parallel-processing/18497)

<div class="topic-metadata">

**Author:** [@hesham](https://discourse.julialang.org/u/hesham)\
**Replies:** 4\
**Last updated:** [December 11, 2021, 8:26am UTC](https://discourse.julialang.org/t/use-of-channels-or-similar-constructs-in-parallel-processing/18497 "2021-12-11T08:26:23Z")

</div>

Hi, I have used Julia Channels in real-time processing of data in a pipeline fashion. Each Channel passes data to the next processing step. A simplified example is the code below, one channel for generating random numbe…

---

## [Request for comments on approach to multithreaded work](https://discourse.julialang.org/t/request-for-comments-on-approach-to-multithreaded-work/72728)

<div class="topic-metadata">

**Author:** [@miguelbiron](https://discourse.julialang.org/u/miguelbiron)\
**Replies:** 2\
**Last updated:** [December 8, 2021, 11:00pm UTC](https://discourse.julialang.org/t/request-for-comments-on-approach-to-multithreaded-work/72728 "2021-12-08T23:00:35Z")

</div>

Hi, I’m developing a multithreaded version of a piece of software and already have a working solution. I just want to check if there is a simpler way of doing it. Basically, the problem can be reduced to this: suppose …

---

## [See usage of Channel (i.e. how many items are enqueued)](https://discourse.julialang.org/t/see-usage-of-channel-i-e-how-many-items-are-enqueued/69284)

<div class="topic-metadata">

**Author:** [@torrance](https://discourse.julialang.org/u/torrance)\
**Replies:** 2\
**Last updated:** [October 6, 2021, 11:09am UTC](https://discourse.julialang.org/t/see-usage-of-channel-i-e-how-many-items-are-enqueued/69284 "2021-10-06T11:09:37Z")

</div>

I am using buffered Channels as a stream between different parts of my program, and I’d like to regularly find out how much of a buffered channel is actually used. For example, if the channel is regularly empty, I know …

---

## [Best way for a task to read from two channels](https://discourse.julialang.org/t/best-way-for-a-task-to-read-from-two-channels/68704)

<div class="topic-metadata">

**Author:** [@adriano.vilela](https://discourse.julialang.org/u/adriano.vilela)\
**Replies:** 25\
**Last updated:** [September 27, 2021, 12:48am UTC](https://discourse.julialang.org/t/best-way-for-a-task-to-read-from-two-channels/68704 "2021-09-27T00:48:30Z")

</div>

Hi, I’m working on a problem that involves tasks communicating through channels. I have a task that needs to read from two channels and I’m trying to figure out the best way of doing that. The task needs to read an in…

---

## [Channel with sliding window buffer?](https://discourse.julialang.org/t/channel-with-sliding-window-buffer/68647)

<div class="topic-metadata">

**Author:** [@vshesh](https://discourse.julialang.org/u/vshesh)\
**Replies:** 0\
**Last updated:** [September 23, 2021, 8:16pm UTC](https://discourse.julialang.org/t/channel-with-sliding-window-buffer/68647 "2021-09-23T20:16:42Z")

</div>

Are there any versions of julia channels that do not block when they are full? I’m looking for a channel that will do a sliding window (so drop the front of the queue when adding something to the back if it’s full). Doe…

---

## [How do I know if an unbuffered (0 sized) channel ready to put! (not blocking)?](https://discourse.julialang.org/t/how-do-i-know-if-an-unbuffered-0-sized-channel-ready-to-put-not-blocking/65228)

<div class="topic-metadata">

**Author:** [@zwtechnb](https://discourse.julialang.org/u/zwtechnb)\
**Replies:** 0\
**Last updated:** [July 24, 2021, 10:43am UTC](https://discourse.julialang.org/t/how-do-i-know-if-an-unbuffered-0-sized-channel-ready-to-put-not-blocking/65228 "2021-07-24T10:43:48Z")

</div>

For a buffered channel(n) with n\>0, I can check it full or not with comparing the Channel field: sz\_max with the undocumented function Base.n\_avail(channel). For channel(0), when a take! on it, a put! can be operated on…

---

## [Does specifying the element type of a Channel impact performance?](https://discourse.julialang.org/t/does-specifying-the-element-type-of-a-channel-impact-performance/57653)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 2\
**Last updated:** [March 21, 2021, 1:19pm UTC](https://discourse.julialang.org/t/does-specifying-the-element-type-of-a-channel-impact-performance/57653 "2021-03-21T13:19:04Z")

</div>

julia\> a = ones(2,2); julia\> ct = Channel{Matrix{Float64}}(1) Channel{Array{Float64,2}}(sz\_max:1,sz\_curr:0) julia\> @btime (put!($ct, $a); take!($ct);); 283.612 ns (0 allocations: 0 bytes) julia\> c = Channel{Any}(1);…

---

## [Progressbar for multiple workers -- connecting workers to RemoteChannel](https://discourse.julialang.org/t/progressbar-for-multiple-workers-connecting-workers-to-remotechannel/56683)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 6\
**Last updated:** [March 8, 2021, 9:56pm UTC](https://discourse.julialang.org/t/progressbar-for-multiple-workers-connecting-workers-to-remotechannel/56683 "2021-03-08T21:56:38Z")

</div>

I am trying to expand the example given on the ProgressMeter.jl documentation to get a progress bar for a few slow processes that run in parallel. Since there are only few processes, but each of them take a long time I w…

---

## [Util for debugging channels/threads performance: should I publish a package?](https://discourse.julialang.org/t/util-for-debugging-channels-threads-performance-should-i-publish-a-package/55093)

<div class="topic-metadata">

**Author:** [@pmilovanov](https://discourse.julialang.org/u/pmilovanov)\
**Replies:** 2\
**Last updated:** [February 13, 2021, 5:37am UTC](https://discourse.julialang.org/t/util-for-debugging-channels-threads-performance-should-i-publish-a-package/55093 "2021-02-13T05:37:13Z")

</div>

I wrote some code for myself to better understand what’s going on with threads and channels in my app. It implements TrackingChannel, a wrapper around a channel that measures how long take!, put!, fetch ops took on that …

---

## [Best practice for channels that use HDF5 (seems like race is still an issue with lock)](https://discourse.julialang.org/t/best-practice-for-channels-that-use-hdf5-seems-like-race-is-still-an-issue-with-lock/44652)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 0\
**Last updated:** [August 10, 2020, 1:07am UTC](https://discourse.julialang.org/t/best-practice-for-channels-that-use-hdf5-seems-like-race-is-still-an-issue-with-lock/44652 "2020-08-10T01:07:19Z")

</div>

I’m about to submit some jobs that use following “emergency backup” scheme (see MWE testBackup.jl below). I learned the hard way after loosing some data on a job that was submitted to our cluster, due to a failing check…

---

## [Channel is closed error when trying to put! objects in LibCURL write callback](https://discourse.julialang.org/t/channel-is-closed-error-when-trying-to-put-objects-in-libcurl-write-callback/40705)

<div class="topic-metadata">

**Author:** [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Replies:** 1\
**Last updated:** [June 4, 2020, 1:20pm UTC](https://discourse.julialang.org/t/channel-is-closed-error-when-trying-to-put-objects-in-libcurl-write-callback/40705 "2020-06-04T13:20:23Z")

</div>

Solved by wrapping curl\_easy\_perform in @async Julia version: 1.0.5 LibCURL: \[b27032c2\] LibCURL v0.5.2 julia\> unsafe\_string(LibCURL.curl\_version()) "libcurl/7.64.1 mbedTLS/2.6.1 zlib/1.2.11" When I use a write callba…

---

## [Why is it \`close(::Channel)\` instead of \`close!(::Channel)\`?](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261)

<div class="topic-metadata">

**Author:** [@jonas-schulze](https://discourse.julialang.org/u/jonas-schulze)\
**Replies:** 4\
**Last updated:** [May 16, 2019, 4:27am UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261 "2019-05-16T04:27:35Z")

</div>

Out of curiosity, why does closing a channel not have a ! in its name?
