Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multi-Threaded Application

Multi-Threaded Application

Scheduled Pinned Locked Moved C / C++ / MFC
data-structures
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sujan Christo
    wrote on last edited by
    #1

    Hi All, I am working on a multi-threaded appln.In that I want to create an array of worker threads (like CWinThread *multthreads[maxsize]), which manipulates on some data until i ask them to stop(Using waitForSingle/MultipleObject) PEACEFULLY(not terminating). Say if i may want to stop the thread @ the 5th position. I am awaiting for your comments Thanx in advance SUjan

    N B V 3 Replies Last reply
    0
    • S Sujan Christo

      Hi All, I am working on a multi-threaded appln.In that I want to create an array of worker threads (like CWinThread *multthreads[maxsize]), which manipulates on some data until i ask them to stop(Using waitForSingle/MultipleObject) PEACEFULLY(not terminating). Say if i may want to stop the thread @ the 5th position. I am awaiting for your comments Thanx in advance SUjan

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      I suggest you look at and use http://www.codeproject.com/threads/threadlibrary.asp[^] Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

      S 2 Replies Last reply
      0
      • N Neville Franks

        I suggest you look at and use http://www.codeproject.com/threads/threadlibrary.asp[^] Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

        S Offline
        S Offline
        Sujan Christo
        wrote on last edited by
        #3

        Hi Franks, Thanx 4 the link. I'll look into it.

        1 Reply Last reply
        0
        • N Neville Franks

          I suggest you look at and use http://www.codeproject.com/threads/threadlibrary.asp[^] Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

          S Offline
          S Offline
          Sujan Christo
          wrote on last edited by
          #4

          Hi Franks, I tried a dialog based program 4 multithreading. Here i am adding the sourcing which i have created. #define MAX_CONNECTIONS 5 #include static CWinThread *multthreads[MAX_CONNECTIONS]; static CEvent m_eventShutdown[MAX_CONNECTIONS]; static HANDLE hShutDown[MAX_CONNECTIONS]; static int shutdownWait[MAX_CONNECTIONS]; static int ShutThreadIndex; int tableCount = 0; //OnInitDialog for (int count=0;countm_bAutoDelete = FALSE; multthreads[0]->ResumeThread(); hShutDown[1] = multthreads[0]->m_hThread; } //To Shutdown the thread i am using void CMultiTestingDlg::ShutdownThread(int i) { ShutThreadIndex = i; shutdownWait[ShutThreadIndex] = INFINITE; m_eventShutdown[ShutThreadIndex].SetEvent(); TRACE1("\nShutdown Index %d\n",i); } The problem i am facing is, when i give shutdownthread, sometimes it is closing the correct thread, sometimes it is not closing the correct thread. PLEASE HELP ME. AM I GOING ON THE RIGHT DIRECTION. SORRY FOR TROUBLING YOU MUCH. THANX IN ADVANCE Sujan

          N 1 Reply Last reply
          0
          • S Sujan Christo

            Hi Franks, I tried a dialog based program 4 multithreading. Here i am adding the sourcing which i have created. #define MAX_CONNECTIONS 5 #include static CWinThread *multthreads[MAX_CONNECTIONS]; static CEvent m_eventShutdown[MAX_CONNECTIONS]; static HANDLE hShutDown[MAX_CONNECTIONS]; static int shutdownWait[MAX_CONNECTIONS]; static int ShutThreadIndex; int tableCount = 0; //OnInitDialog for (int count=0;countm_bAutoDelete = FALSE; multthreads[0]->ResumeThread(); hShutDown[1] = multthreads[0]->m_hThread; } //To Shutdown the thread i am using void CMultiTestingDlg::ShutdownThread(int i) { ShutThreadIndex = i; shutdownWait[ShutThreadIndex] = INFINITE; m_eventShutdown[ShutThreadIndex].SetEvent(); TRACE1("\nShutdown Index %d\n",i); } The problem i am facing is, when i give shutdownthread, sometimes it is closing the correct thread, sometimes it is not closing the correct thread. PLEASE HELP ME. AM I GOING ON THE RIGHT DIRECTION. SORRY FOR TROUBLING YOU MUCH. THANX IN ADVANCE Sujan

            N Offline
            N Offline
            Neville Franks
            wrote on last edited by
            #5

            All thread functions DataAccessThreading() are accessing the same global data and they don't know which instance of the thread they are. So the first thread to check eventShutdown[ShutThreadIndex] which see it and behave as requested. I would wrap: static CWinThread *multthreads[MAX_CONNECTIONS]; static CEvent m_eventShutdown[MAX_CONNECTIONS]; static HANDLE hShutDown[MAX_CONNECTIONS]; static int shutdownWait[MAX_CONNECTIONS]; static int ShutThreadIndex; in a class and create an array of these. The pass the array instance address into the DataAccessThreading() function. Each thread knows which intance it is and only needs to check its specific eventShutdown. Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

            S 2 Replies Last reply
            0
            • S Sujan Christo

              Hi All, I am working on a multi-threaded appln.In that I want to create an array of worker threads (like CWinThread *multthreads[maxsize]), which manipulates on some data until i ask them to stop(Using waitForSingle/MultipleObject) PEACEFULLY(not terminating). Say if i may want to stop the thread @ the 5th position. I am awaiting for your comments Thanx in advance SUjan

              B Offline
              B Offline
              Bob Stanneveld
              wrote on last edited by
              #6

              Hello, I started a multithreaded application a few weeks ago and I find this[^] class extremely usefull. Your code would look like this: CThread threads[maxsize]; // some code threads[4].Stop(); // Function Kill also applies... // more code Hope this helps.. Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.

              S 1 Reply Last reply
              0
              • S Sujan Christo

                Hi All, I am working on a multi-threaded appln.In that I want to create an array of worker threads (like CWinThread *multthreads[maxsize]), which manipulates on some data until i ask them to stop(Using waitForSingle/MultipleObject) PEACEFULLY(not terminating). Say if i may want to stop the thread @ the 5th position. I am awaiting for your comments Thanx in advance SUjan

                V Offline
                V Offline
                valikac
                wrote on last edited by
                #7

                What data and how are the threads processing the data? Kuphryn

                1 Reply Last reply
                0
                • N Neville Franks

                  All thread functions DataAccessThreading() are accessing the same global data and they don't know which instance of the thread they are. So the first thread to check eventShutdown[ShutThreadIndex] which see it and behave as requested. I would wrap: static CWinThread *multthreads[MAX_CONNECTIONS]; static CEvent m_eventShutdown[MAX_CONNECTIONS]; static HANDLE hShutDown[MAX_CONNECTIONS]; static int shutdownWait[MAX_CONNECTIONS]; static int ShutThreadIndex; in a class and create an array of these. The pass the array instance address into the DataAccessThreading() function. Each thread knows which intance it is and only needs to check its specific eventShutdown. Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

                  S Offline
                  S Offline
                  Sujan Christo
                  wrote on last edited by
                  #8

                  Dear Franks, THANX A LOT. I was literally struggling with this. I'll try as per your suggestion. Incase of need i'll trouble(SORRY 4 that) again. Moreover i was having a doubt that whether i am going in the right direction.So your reply helps me a lot. THANX A LOT Yours Sujan

                  1 Reply Last reply
                  0
                  • B Bob Stanneveld

                    Hello, I started a multithreaded application a few weeks ago and I find this[^] class extremely usefull. Your code would look like this: CThread threads[maxsize]; // some code threads[4].Stop(); // Function Kill also applies... // more code Hope this helps.. Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.

                    S Offline
                    S Offline
                    Sujan Christo
                    wrote on last edited by
                    #9

                    Hi Bob, Just now only i saw your reply. Thanx, i'll go through the article. Sujan

                    1 Reply Last reply
                    0
                    • N Neville Franks

                      All thread functions DataAccessThreading() are accessing the same global data and they don't know which instance of the thread they are. So the first thread to check eventShutdown[ShutThreadIndex] which see it and behave as requested. I would wrap: static CWinThread *multthreads[MAX_CONNECTIONS]; static CEvent m_eventShutdown[MAX_CONNECTIONS]; static HANDLE hShutDown[MAX_CONNECTIONS]; static int shutdownWait[MAX_CONNECTIONS]; static int ShutThreadIndex; in a class and create an array of these. The pass the array instance address into the DataAccessThreading() function. Each thread knows which intance it is and only needs to check its specific eventShutdown. Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

                      S Offline
                      S Offline
                      Sujan Christo
                      wrote on last edited by
                      #10

                      Dear Franks, I tried by creating a class and used it as you have said, still getting the same problem. Do you have any sample code, which does this. If you do have, will you please post it. I am in deep trouble. SORRY FOR DISTURBING YOU AGAIN. if the code is too large you can send it to my mail id also AWAITING YOUR REPLY Yours Sujan

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups