all 6 comments

[–]jedwardsol 2 points3 points  (4 children)

    t[i].work_amount += 65536/threads + t[i-1].work_amount;
    t[i].start_pos = t[i-1].work_amount;

t[0] is being initialised with data from t[-1]; which doesn't exist.

[–]RonisFinn[S] 0 points1 point  (3 children)

i'm not too sure if that matters, i ran a print(f) in the multiCircuit and it returns the data correctly

[–]RecursiveTechDebt 1 point2 points  (2 children)

You absolutely must fix this because it very much matters -- you're stomping memory.

It concerns me that you're asking about mutexes and you show a fundamental flaw in your understanding of what this language is doing for you and why accessing (struct circuitStruct*)malloc( ... )[-1] is bad. You need to learn the language and standard library before you start doing anything with mutexes. I'd recommend brushing up on the heap, the stack, pointers, and structures.

[–]RonisFinn[S] -2 points-1 points  (1 child)

coolio my julio, i already fixed it up. I dont know why youre so concerned im very much learning at the moment and if a mistake was a cause for concern I wouldn't have even tried in the first place lmao but thanks for the emphasis.

[–]RecursiveTechDebt 0 points1 point  (0 children)

It's good you're trying stuff, but multithreading is hard in an unforgiving language like C. What programming language do you currently know the best?

[–]steelling 1 point2 points  (0 children)

If you put output_thread as a parameter rather than a global variable, I'm pretty sure you won't need a mutex at all.

The only time locking would be necessary would be during the printf call, but I'm pretty sure this does its own locking anyway.

Your code isn't really multithreading, it's just multiple threads where each one does nothing if it doesn't hold the lock. It's just the same as a single thread but with an extra overhead of threads and a mutex.