Thread: Program design and outlay in large projects

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    43

    Program design and outlay in large projects

    I'm interested to know a little about the overall design of large programs which goes beyond a C programming course introduced in college.

    I'm particularly interested to know about the general consensus and conventions adopted in C/C++ programming for the internal messaging of operations and data in a program. For example internal program data and messaging exchanges between functions and structures, save for the case of global variables.

    I'm finding I'm having to replicate variables which carry actual data with messaging variables which carry signals of the data to corresponding functions and objects. This is making the program overly cumbersome and makes the implementation of the program less lucid.

    My own conclusions thus far leads to having a separate and distinct structure/object which is shared across the program and only carries the signals between functions. Is this the way to do it?

    I understand you don't want to be passing huge structures around in the program for the sake of avoiding internal messaging. But compartmentalizing structs/objects and only passing those necessary structs and objects if and when necessary coupled with a way of messaging across the internals of the program.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Please describe your application specifications so we have a concrete example of what you are trying to do. Phrases like "messaging variables which carry signals of the data to corresponding functions" are difficult to decipher in the abstract.

  3. #3
    Registered User
    Join Date
    Jan 2016
    Posts
    43
    Hi again algorism,

    Let's say there are two threads/functions running concurrently in the program and some of the data generated in one thread needs to be shared with the other thread/function. Some or all of the data may want to be shared between the two threads but I would also like to know how one thread is able to signal the other thread when certain procedures and/or conditions have been carried out.

    This is simply a question of a standardized style of implementation for a system which caters to the internal messaging of a program. I realize some of these issues can be totally avoided with careful implementation and careful ordering of functions and procedures. However I am sure there is a precedent for organizing the program execution with greater flexibility. Thereby this issue arises with respect to the messaging across program internals.

    Code:
    //
    // Header declarations
    //
    
    struct data
    {
        variables;
    } 
    
    void *thread_func1(struct data)
    {
        while(1)
        {
              ops:
                   ops A;
                       // Some data used from ops C or D;
                   ops B;
                       // Some data used from ops C or D;
        }
        
        return;
    }
    
    void *thread_func2(struct data)
    {
        while(1)
        {
              ops:
                  ops C;
                  ops D;
                       // Some data used from ops A or B;
        }
        
        return;
    }
    
    int main()
    {
        thread_func1(data);
        thread_func2(data);
        
        return;
    }
    Additional variables could be added to the struct, to say give a boolean signal when A, B, C, D or parts of A, B, C, D have competed. So in such a scenario at least 4 additional variables would be added to the struct to provide the relevant signals. Are there better ways to implement things like these?
    Last edited by wiqxlzxsxj; 01-19-2016 at 04:07 PM.

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    So your concern is primarily with communication between threads? With threads, mutexes are used for mutually-exclusive access to shared resources (like shared memory). Condition variables are used to signal conditions.

    Have you read a tutorial on threads? This one on posix threads is good: https://computing.llnl.gov/tutorials/pthreads/ . Alternatively you might use the C11 or C++11 thread API.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  2. Proper coding style on large projects
    By Verneg in forum C Programming
    Replies: 0
    Last Post: 03-27-2010, 06:13 PM
  3. Design of Large C Projects/Program
    By amrishpurohit in forum Tech Board
    Replies: 5
    Last Post: 09-03-2008, 01:29 AM
  4. Replies: 11
    Last Post: 05-25-2007, 04:39 PM
  5. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM

Tags for this Thread