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. Threads

Threads

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 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.
  • G Offline
    G Offline
    ginjikun
    wrote on last edited by
    #1

    Hi All! i would like to get some help regarding creating objects inside a thread. i have a thread and within the thread i am creating an object. main thread { obj o for(;;) { o.createnamedpipe; o.connectnamedpipe; if(connected) { o.createthread; o.startthread; } } } the above scenario always encounters an exception. is it because the obj is no longer valid when the o.startthread is started? i tried to use another thread thread and from there call the startthread... so ill have for(;;) { o.createnamedpipe; o.connectnamedpipe; if(connected) createthread(minorthread, o,...); } minorthread(lpParam) { obj o = static_castlpParam; o.createthread; o.startthread; } this however still fails. hope someone can help me. thanks in advance! newbie :)

    D S 2 Replies Last reply
    0
    • G ginjikun

      Hi All! i would like to get some help regarding creating objects inside a thread. i have a thread and within the thread i am creating an object. main thread { obj o for(;;) { o.createnamedpipe; o.connectnamedpipe; if(connected) { o.createthread; o.startthread; } } } the above scenario always encounters an exception. is it because the obj is no longer valid when the o.startthread is started? i tried to use another thread thread and from there call the startthread... so ill have for(;;) { o.createnamedpipe; o.connectnamedpipe; if(connected) createthread(minorthread, o,...); } minorthread(lpParam) { obj o = static_castlpParam; o.createthread; o.startthread; } this however still fails. hope someone can help me. thanks in advance! newbie :)

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Notice anything peculiar about your code snippet? Yeah, we can't decipher it either.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      G 1 Reply Last reply
      0
      • D David Crow

        Notice anything peculiar about your code snippet? Yeah, we can't decipher it either.


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        G Offline
        G Offline
        ginjikun
        wrote on last edited by
        #3

        Hi, i am sorry i wrote just words to explain the way i have coded it. basically what i have is a class (CIPCClass) which encapsulates namedpipe functions and in the mainthread i create an instance of that class CIPCClass and when a client has connected i call the startthread of the CIPCClass to continue the receiving of message while the main thread can again continue to listen for connecting clients. mainthread { CIPCClass obj; for(; ; ) { obj.CreatePipe(); int nRet = obj.ConnectNamedPipe(); if(nRet) obj.StartThread(); else break; } } the above approach did not work so i created a minorthread which receives the CIPCClass. and from the minorthread then i will call the startthread. still it did not work. hope i have explained it clear enough. sorry again. thanks for any help. newbie :)

        I D 2 Replies Last reply
        0
        • G ginjikun

          Hi All! i would like to get some help regarding creating objects inside a thread. i have a thread and within the thread i am creating an object. main thread { obj o for(;;) { o.createnamedpipe; o.connectnamedpipe; if(connected) { o.createthread; o.startthread; } } } the above scenario always encounters an exception. is it because the obj is no longer valid when the o.startthread is started? i tried to use another thread thread and from there call the startthread... so ill have for(;;) { o.createnamedpipe; o.connectnamedpipe; if(connected) createthread(minorthread, o,...); } minorthread(lpParam) { obj o = static_castlpParam; o.createthread; o.startthread; } this however still fails. hope someone can help me. thanks in advance! newbie :)

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          If code isn't indented I don't bother to look at it.

          Steve

          1 Reply Last reply
          0
          • G ginjikun

            Hi, i am sorry i wrote just words to explain the way i have coded it. basically what i have is a class (CIPCClass) which encapsulates namedpipe functions and in the mainthread i create an instance of that class CIPCClass and when a client has connected i call the startthread of the CIPCClass to continue the receiving of message while the main thread can again continue to listen for connecting clients. mainthread { CIPCClass obj; for(; ; ) { obj.CreatePipe(); int nRet = obj.ConnectNamedPipe(); if(nRet) obj.StartThread(); else break; } } the above approach did not work so i created a minorthread which receives the CIPCClass. and from the minorthread then i will call the startthread. still it did not work. hope i have explained it clear enough. sorry again. thanks for any help. newbie :)

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            Using the <pre&gr tags keep the indentation and any < or > symbols. It will also make it easier on people's eyes to read - so someone might actually answer. Iain.

            1 Reply Last reply
            0
            • G ginjikun

              Hi, i am sorry i wrote just words to explain the way i have coded it. basically what i have is a class (CIPCClass) which encapsulates namedpipe functions and in the mainthread i create an instance of that class CIPCClass and when a client has connected i call the startthread of the CIPCClass to continue the receiving of message while the main thread can again continue to listen for connecting clients. mainthread { CIPCClass obj; for(; ; ) { obj.CreatePipe(); int nRet = obj.ConnectNamedPipe(); if(nRet) obj.StartThread(); else break; } } the above approach did not work so i created a minorthread which receives the CIPCClass. and from the minorthread then i will call the startthread. still it did not work. hope i have explained it clear enough. sorry again. thanks for any help. newbie :)

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              ginjikun wrote:

              hope i have explained it clear enough.

              What does "did not work" actually mean?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              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