Thread: Looking for advice on C++ mulithreading

  1. #46
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It does not really matter how well known, common or uncommon it is. The problem is that you're forcing complexity into the code that is brittle and hard to digest. It's completely fine to use such pattern, and yes, I would say it is recommended, but getting such patterns right can still be a problem. You should abstract that code behind a class that maintains its invariants. Not only is it easier to code/test, but reading the code would be much more trivial too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #47
    Registered User
    Join Date
    Feb 2015
    Posts
    1
    Guys sorry to bother you but i really need help regarding my ict proj.. i'm just a freshman and still trying to learn c++.. i saw the one of the dead forums which was posted by a fellow schoolmate but not my batchmate in fact i dont even know him just saw the same proj given by the professor and the same school acronyms...so i found out about this site..since i dont know how to post a thread cause i'm new to the site but hopefully i can get some help.. the poblem is:

    ICT02 Programming Project:
    Write a C++ program that would display the menu of a restaurant and will accept orders, compute for the total amount and compute for customer change after entering the given cash.
    The program should be looping and will end once the user answers No to the question: Another Customer (Y or N).

    So i had some codes still confused of the looping cause i have to cls if the answer is no.. and i dont know how to make it repetitive cause im conufsed if i should state another variable if he says yes.. here is my code:
    insert
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
     
     
        cout<<"SHOW MY HOUSE\n\n"; 
        cout<<"Menu\n\n\n" <<;
        cout<<"Meal#        Food/Recipe                       Price | Drink#    Lechong Pitchel Price\n\n";    
        cout<<"1            Lechong kawali                    55P   | 7         Buko shake      45P\n\n";
        cout<<"2            Lechong Kaldero(Lrg Lechon)       75P   | 8         Iced Tea        30P\n\n";
        cout<<"3            Lechong Sandok (Lechon bits)      50P   | 9         Coke            25P\n\n";
        cout<<"4            Lechong Mangkok(Lechong adobo)    55P   | 10        Sprite          25P\n\n";
        cout<<"5            Lechong Batok  (Lechon overload) 120P   | 11        Sago't gulaman  30P\n\n";
        cout<<"6            Lechong Manok                     55P   | 12        Four Season     30P\n\n";
     
     
        char answer; 
        string name;
        int norder[12], quantity, order;
        double amount, change, cash; 
     
     
        norder[1] = 55;
        norder[2] = 75;
        norder[3] = 50;
        norder[4] = 55;
        norder[5] = 120;
        norder[6] = 55;
        norder[7] = 45;
        norder[8] = 30;
        norder[9] = 25;
        norder[10] = 25;
        norder[11] = 30;
        norder[12] = 30;
        
     
     
        cout<<"Customer Name: ";
        cin>>name;
        cout<<"Enter the Order: ";
        cin>>meal;
        cout<<"Quantity: ";
        cin>>quantity;
        cout<<"Aditional Order (Y/N): ";
        cin>>answer;
        {
        If( answer ==y)
        cout<<"Enter the Order: ";
        cin>>meal;
        cout<<"Quantity: ";
        cin>>quantity;
        cout<<"Aditional Order (Y/N): ";
        
        cout<<endl;
        cin.ignore();    
     
        int price = *(norder + (order - 1));
     
        cout<<"Customer name: " <<name <<endl;
        cout<<"Total Amount: " <<price * quantity <<endl;
        cout<<"Total Cash: " <<endl;
        cout<<"Change: " <<endl <<endl;
     
        cin.get();
    }


    Also credit to Khebabz i think i forgot the name.. i followed some of his format on his reply to what i saw to his post...and i would like to apologize to the one that posted this thread..im just desperate for some help sir..cause im new to the site and dont know how to post a thread

  3. #48
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    O.o >.> <.<

    jaykayhaps do not hijack someone else's thread with something totally unrelated.

    Start a new thread for your question.
    Last edited by Aslaville; 02-26-2015 at 10:01 AM.

  4. #49
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by rcgldr View Post
    The double swap method isn't that uncommon.
    Quote Originally Posted by Elysia View Post
    The problem is that you're forcing complexity into the code that is brittle and hard to digest.
    It depends if someone has used or seen this method used before. As another example, in a bottom up merge sort, it's common to swap pointers to the original and temp arrays / vectors in order to change the direction of the merge operations on each merge pass. Do a web search for "double buffer swap pointers" and you'll find a lot of hits like this:

    However, some graphics cards have the ability to specify the address in memory where the buffer used for rendering is stored. If you're redrawing the entire scene each frame (which is often the case when rendering video or 3D), you simply need to swap two pointers (the pointer to the buffer you're drawing to, and the pointer to the buffer being drawn on screen).

    http://wiki.osdev.org/Double_Buffering

    As an alternative, I could have created a two element circular queue, where each element is a pointer to an array, with change_x advancing the head index / pointer and print_x advancing the tail index / pointer, but swapping pointers was simpler.
    Last edited by rcgldr; 02-26-2015 at 11:15 AM.

  5. #50
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I know what double buffering is. Though I am not an expert in graphics, I do believe there is a "rendering" thread. So there would only be one thread that does the rendering, then swaps the buffer, lets the graphics subsystem render that while it proceeds with rendering the new second buffer. This is different from what you're doing with two threads that's competing for the buffers while both threads are swapping the buffer.

    Like I said, even if it's a known pattern, if the complexity is enough, you should simplify it. Not everyone might know this pattern.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #51
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by Elysia View Post
    Though I am not an expert in graphics, I do believe there is a "rendering" thread. So there would only be one thread that does the rendering, then swaps the buffer, lets the graphics subsystem render that while it proceeds with rendering the new second buffer.
    In a double buffer case, it's equivalent to two pointer swaps, one swap for the rendering thread, one swap for the graphics subsystem. In some cases, the graphics sub-system can automatically "advance" a pointer to the next frame buffer to display (for double or triple buffering), then generate a vertical sync interrupt that the rendering thread is pending on (if vertical sync enabled) so that the rendering thread then "advances" to it's next free frame buffer for rendering. In a game, the rendering thread is also getting object position updates from a physics thread. If vertical sync isn't enabled, then the rendering thread will advance the graphics sub-system frame pointer as soon as it renders a frame, which creates "tearing" effects when the swap is done during a display cycle, but movement between frames is usually small enough that it's not an issue.
    Last edited by rcgldr; 02-26-2015 at 12:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c# mulithreading
    By Mastermosley in forum C# Programming
    Replies: 13
    Last Post: 03-15-2009, 03:53 PM
  2. i need some advice
    By raja9911 in forum C Programming
    Replies: 1
    Last Post: 01-31-2006, 06:29 AM
  3. RAM advice
    By Grade in forum Tech Board
    Replies: 31
    Last Post: 03-23-2003, 09:18 PM
  4. Looking for advice
    By NapoleonIII in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-13-2002, 12:25 PM
  5. Need your help, advice
    By Coconut in forum Tech Board
    Replies: 2
    Last Post: 10-09-2002, 08:23 PM

Tags for this Thread