[m-users.] Uncomplete documentation of thread.channel and thread.closeable_channel
Volker Wysk
post at volker-wysk.de
Sat Apr 11 16:41:21 AEST 2026
Am Freitag, dem 10.04.2026 um 15:00 +1000 schrieb Peter Wang:
> On Thu, 09 Apr 2026 14:24:01 +0200 Volker Wysk <post at volker-wysk.de>
> wrote:
> > Hi!
> >
> > Reading the API docs of thread.channel gives the impression that a
> > channel
> > can't be destroyed. What about the ressources associated with the
> > channel?
> > Wouldn't it lead to ressource leak if a program repeatedly creates
> > channels,
> > that finally aren't used any longer?
>
> The API doesn't require channels to be explicitly destroyed.
>
> In terms of the implementation, a channel consists of a couple of mvars,
> which are implemented with semaphores. On C backends, semaphores are
> implemented with mutexes and condition variables; we register a
> GC finaliser to destroy those when the semaphore is collected.[1]
> On the Java and C# backends, semaphores don't need explicit cleanup
> either.
>
> Peter
>
> [1] On Linux, I belive pthread_mutex_destroy and pthread_cond_destroy
> effectively do nothing.
Okay, thanks. I need this for a parallelisation library, which I'm releasing
soon.
Best wishes,
Volker
More information about the users
mailing list