Hi everyone,

I'm working on a graphical program, and using pthread to speed up the calculations.

The program works beautifully, but valgrind and fsanitize warn me of 2 potential problems:

1. There are still reachables when my program exits. They seem to be coming from pthread. I'd like to figure out whether I can do anything about them - maybe they're inherent to pthread, maybe I made a mistake. https://i.imgur.com/nExA5PN.png

2. There are data race warnings when using helgrind or fsanitize=thread. What I can't figure out is that only the school computers have this problem. At home, neither of these tools warn of any problems. I tried testing extensively and I couldn't have any data race warning. I don't have any log of the errors sadly but I will tomorrow.

Some more details about the 2 problems:

1. I know still reachables, especially such as these (4 blocks, 1654 bytes, always, no matter window size, amount of renders, number of threads), should not really be a problem. This is a school project and my school is very strict on these, so I'm doing my best to comply. If I can't fix this, I'd like to at least understand exactly where the still reachables come from - what does pthread do that creates these?

2. When I implemented multi-threading, I read about mutex of course, and I implemented a mutex lock on the only variable that the threads could simultaneously write to. All the rest is read-only.

When troubleshooting with a friend, he pointed out that several threads accessing the same memory space concurrently could create problems, and that I should try to make copies of all common memory for each thread. Is that true?

I found a way to completely prevent any data race warnings by adding a mutex lock around a single line (fractol_draw.c, line 104), which completely defeats the purpose of multithreading. And the thing is, these instructions never write anything to common memory, only read. The only non mutex'd write is compartmentalized so that each thread cannot touch the others.

Not to mention I have no problems at home. My CPU is way better, but no matter how much I stress it by blowing up window size and SSAA strength, there are no data race warnings.

The code is there GitHub - m0d1nst4ll3r/42_fract-ol: 42 - common core - ring #2 (it's really just a personal repo, and it's my first big project, please forgive the messiness - I'll do better next time)

Thank you all for your help! I'm going crazy.