Fork me on GitHub
#clojure
<
2024-03-10
>
roklenarcic12:03:04

So I have some code looks at a hashmap for a key and there can be a promise , if there is, it is derefed but otherwise one is created, inserted into hashmap and some calculation proceeds that delivers on that promise. This calculation can call this code again, of course, and that’s fine if the key is different, but if the key is the same I have a deadlock. Promise is created, inserted, then calculation starts and promise is fetched and derefed, which blocks the thread and promise is never delivered. So the question here is: what’s the best, most performant way to stop this scenario? I don’t care how complicated it is, I need performance. My first idea is straightforward, it is to use ThreadLocal and keep a set of promises created by this thread there and check it before derefing a promise. But it’s pretty slow, so if someone has any tricks, any tricks at all, I’d love to hear them. If I have to write Java code and add java compilation, that’s no problem.

p-himik12:03:32

It feels that, while the direct issue is deadlocks, the root cause is a suboptimal approach to computation altogether. Have you seen the libraries that let you build a computation graph in advance and then execute it?

roklenarcic13:03:18

The actual computation is implemented by library user, I have to be ready for anything

p-himik13:03:58

That makes it sound even more vague. :) "How do I ensure that my program never hangs and performs the best it can, while being able to process absolutely anything?"

phill16:03:46

Could you use clojure.core.async - the map would hold promise-channels - and computations would read them in a way that would park, not block: <!, not <!!? (But, do have a look at Plumatic Plumbing for an elegant example of what you could do if you required the tasks to be declared in such a way that you could detect which depended on which others.)

seancorfield17:03:24

A request to the OP - please don't delete questions that others have taken the time to answer.

roklenarcic18:03:17

Sorry, I’ve deleted it specifically because I didn’t want more people to waste their time reading and potentially answering it. Realized it was a mistake to ask this in the first place.

seancorfield19:03:37

@U66G3SGP5 A note in the response thread saying that would be better than deleting it (and losing the context of the responses).

2
teodorlu06:03:23

Sorry, I’ve deleted it specifically because I didn’t want more people to waste their time reading and potentially answering it. Realized it was a mistake to ask this in the first place.> I never consider it a waste to read or answer questions here. I think it's great that people ask questions, and interesting to read questions and answers. That's a great way to learn for me :) I believe it's people's own responsibility to judge whether they should answer a question when reading the question. (and personally, I'm very curious about what the original question actually was ...)

Marc Berndtgen12:03:59

Maybe I'm doing a rookie mistake here, but I'm on macOS 14 with an OpenJDK 21 and when I go through the eelchat tutorial and try to sign up, the signup link isn't printed on my console:

TO: [{:email [email protected]}]
SUBJECT: Sign up for My Application

nil

p-himik12:03:36

There's #C013Y4VG20J and if I were in your shoes I'd just try debugging it to see where the problem is. Maybe it ends up being worthy of a proper issue report.

Marc Berndtgen12:03:16

Oh sorry, I think I misclicked in the channel list and posted here by accident