In my process of learning Nim, I'm currently studying Nim's approaches to concurrent programming. I have seen a few comments about the limitations of a thread-local garbage collection (for instance here and there), but I still don't fully see all implications of this.
I'm wondering if there are some kind of well-established "design patterns" in Nim how to deal with these limitations? Maybe it is possible to consider a typical example that requires inter-thread sharing/interaction and to show possible idiomatic solutions to such a problem?
My own attempts to come up with good solutions to this were not really successful so far and have lead to this more specific question about TChannel
.
Most common use of thread local is when you have some object that is not thread-safe, but you want to avoid synchronizing access to that object using synchronized keyword/block. Instead, give each thread its own instance of the object to work with.
The ThreadLocal class is used to create thread local variables which can only be read and written by the same thread. For example, if two threads are accessing code having reference to same threadLocal variable then each thread will not see any modification to threadLocal variable done by other thread.
Java ThreadLocal class provides thread-local variables. It enables you to create variables that can only be read and write by the same thread.
It's safe because getMap returns the map for the given (i.e. current) thread.
A really broad answer is: This seems to go against the design principles of Nim. Nim completely avoids any inter-thread sharing/interaction problems by removing that as a capability. The no "stop the world" design principle. The built in asynchronous message passing should be adequate to.
What limitations are mentioned in the referenced articles seem to be limitations in design or approach to the problems.
Also in the time passed since you posted this question I see that there has been an answer to the linked TChannel question. Has this resolved your issue?
@bluenote10 Is it possible you can better define the type of problem you are facing? The way it seems now this question is really broad. Also sorry I don't have the rep to reply directly to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With