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. TCP and Thread problem

TCP and Thread problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++helplounge
3 Posts 2 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.
  • J Offline
    J Offline
    Just Baballa
    wrote on last edited by
    #1

    Hi ppl, I am writing a simple TCP chat app in MFC c++ (dialog based), using two threads - one for listening and acceping and another one is for receiving and sending. The problem actualy occurs when I close (click on OK or Cancel) while some thread is running. I get an assert or/and unhandled exception pointing to a my code or some code inside dbgheap.c (Ln 1974: if (_BLOCK_TYPE(pHead->nBlockUse) >= 0 && _BLOCK_TYPE(pHead->nBlockUse) < _MAX_BLOCKS)) I suspect something about threads that are still running, though I tried to end them with TerminateThread and ExitThread. Please help.

    C 1 Reply Last reply
    0
    • J Just Baballa

      Hi ppl, I am writing a simple TCP chat app in MFC c++ (dialog based), using two threads - one for listening and acceping and another one is for receiving and sending. The problem actualy occurs when I close (click on OK or Cancel) while some thread is running. I get an assert or/and unhandled exception pointing to a my code or some code inside dbgheap.c (Ln 1974: if (_BLOCK_TYPE(pHead->nBlockUse) >= 0 && _BLOCK_TYPE(pHead->nBlockUse) < _MAX_BLOCKS)) I suspect something about threads that are still running, though I tried to end them with TerminateThread and ExitThread. Please help.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Don't use TerminateThread or ExitThread to stop your thread. Instead, use a flag to signal that the thread should stop:

      while (bThreadActive)
      {
      // Continue to process the thread
      }

      Then, when you want to stop this thread (through your main thread), set this variable to false and wait[^] for the thread to finish.


      Cédric Moonen Software developer
      Charting control

      J 1 Reply Last reply
      0
      • C Cedric Moonen

        Don't use TerminateThread or ExitThread to stop your thread. Instead, use a flag to signal that the thread should stop:

        while (bThreadActive)
        {
        // Continue to process the thread
        }

        Then, when you want to stop this thread (through your main thread), set this variable to false and wait[^] for the thread to finish.


        Cédric Moonen Software developer
        Charting control

        J Offline
        J Offline
        Just Baballa
        wrote on last edited by
        #3

        A helluva idea... I'll try that one, 10x

        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