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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with multi threading

Problem with multi threading

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 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
    SHIBU K V
    wrote on last edited by
    #1

    I have placed a gif animation Control(Gif89) in my Dialog based application and in a thread i tried to move the gif's control (with a loaded picture) through the bottom of my Dialog using Move Window() function.A delay of 1ms is introduced between successive calls to move window. I use a timer to communicate with an external device connected to serial port. It takes almost 3 seconds to finish communication. During this time my thread seems to be strucked and gif control is not moved over my main dialog.How can i avoid this?. the code in the thread for moving control is given below int offsetx=0;//65 int offsety=444; int step=0; while(killthread) { m_santa.MoveWindow(offsetx+step,offsety,159,76); Sleep(1); step=step+1; if(offsetx+step>483)//314) step=0; With regards Shibu "Help yourself through helping others"

    M 1 Reply Last reply
    0
    • S SHIBU K V

      I have placed a gif animation Control(Gif89) in my Dialog based application and in a thread i tried to move the gif's control (with a loaded picture) through the bottom of my Dialog using Move Window() function.A delay of 1ms is introduced between successive calls to move window. I use a timer to communicate with an external device connected to serial port. It takes almost 3 seconds to finish communication. During this time my thread seems to be strucked and gif control is not moved over my main dialog.How can i avoid this?. the code in the thread for moving control is given below int offsetx=0;//65 int offsety=444; int step=0; while(killthread) { m_santa.MoveWindow(offsetx+step,offsety,159,76); Sleep(1); step=step+1; if(offsetx+step>483)//314) step=0; With regards Shibu "Help yourself through helping others"

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Firstly, Sleep() does not have anywhere near 1 ms granularity. Sleep(1) will sleep for about 50 ms probably. But what's causing the apparent hang is that (I'm guessing here, CMIIW) the thread did not create m_santa, the main thread did. Since messages for a window must be handled by the thread that created the window, MoveWindow() ends up doing a SendMessage() to the main thread, to have it move the window. SendMessage() does not return until the message is processed. But since the main thread is busy doing your serial port comm, it is not running its message loop. Thus you have a deadlock, the main thread is busy, and the 2nd thread can't continue until the main thread is done being busy. --Mike-- If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

      A 1 Reply Last reply
      0
      • M Michael Dunn

        Firstly, Sleep() does not have anywhere near 1 ms granularity. Sleep(1) will sleep for about 50 ms probably. But what's causing the apparent hang is that (I'm guessing here, CMIIW) the thread did not create m_santa, the main thread did. Since messages for a window must be handled by the thread that created the window, MoveWindow() ends up doing a SendMessage() to the main thread, to have it move the window. SendMessage() does not return until the message is processed. But since the main thread is busy doing your serial port comm, it is not running its message loop. Thus you have a deadlock, the main thread is busy, and the 2nd thread can't continue until the main thread is done being busy. --Mike-- If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

        A Offline
        A Offline
        Andreas Masur
        wrote on last edited by
        #3

        Well...depending on the operating system 'Sleep()' will sleep between 10 (Single CPU Windows NT) milliseconds and 50 milliseconds (Windows 98). I do not know of the top of my head whether Windows 2000 or XP have better resolution... Ciao, Andreas "Software is like sex, it's better when it's free." - Linus Torvalds

        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