Threadig approach

Flaviu_ 1,011 Reputation points
2022-09-05T10:09:26.617+00:00

I have a GUI MFC app, which should perform few long length operations, and these operations looks like:

    // pseudo code  
    CString PerformOp1()  
    {  
        CFile generate a file1.typ1  
        return file1.typ1.name  
    }  
      
    CString PerformOp2(const CString& file1.typ1)  
    {  
        // from file1.typ1 would be generate file2.typ2  
        return file2.typ2.name  
    }  
      
    // pseudo code  
    CString PerformOpFinal(const CString& file2.typ2)  
    {  
        From file2.typ2 whould be generate a final.typ3  
        return final.typ3.name  
    }  
  
  
auto file1 = PerformOp1();  
auto file2 = PerformOp2(file1);  
auto filefinal = PerformOpFinal(file2.typ2);  

Now, what is the correct approach to accomplish these operations ? And all should started on a button click from application GUI.

Now, if I do every step from within a thread, then I would have file handlers issues, it's very possibile to not have file1.typ1 finished and saved, and thats's why PerformOp2 would have trouble with that.

If I'll do eevrything in a single therad, the code will be pretty complicated, so, there will be a weak code.

If I'll use a thread pool, I'll have the syncronization issues, how can I know betewwn threads when the op1 is ready, to start op2, and so on.

How would be the correct approach for this task ? I'll appreciate any advice.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,761 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.