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. Thread sync

Thread sync

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

    Hey, In my App i have one thread that grabs frames from a camera and paste them on the client window. The client window belongs to the main thread of the App so when i try to resize it my App crushes. I think it happens because the window is a mutual resource of the threads so what happens is that both access him at the same time. how can i solve my problem? Thanks

    L B J 3 Replies Last reply
    0
    • C columbos14927

      Hey, In my App i have one thread that grabs frames from a camera and paste them on the client window. The client window belongs to the main thread of the App so when i try to resize it my App crushes. I think it happens because the window is a mutual resource of the threads so what happens is that both access him at the same time. how can i solve my problem? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, Your question is not very well formed. You should consider revising it and give us an error code, and any other relevant information.

      columbos14927 wrote:

      In my App i have one thread that grabs frames from a camera and paste them on the client window.

      Are you saying that you use Clipboard Operations[^] to paste an image? Are you sure about this?

      columbos14927 wrote:

      The client window belongs to the main thread of the App so when i try to resize it my App crushes.

      I certainly hope your monitors are not being crushed as that would get expensive very fast. :) I believe you mean crashes? If so... then you should have received an error code. When you ask for help from other software engineers... please give detailed information including any error code.

      columbos14927 wrote:

      I think it happens because the window is a mutual resource of the threads so what happens is that both access him at the same time.

      Windows belong to a single thread. However if you attempt to access resources that belong to that thread from other threads... Yes, this can cause problems.

      columbos14927 wrote:

      how can i solve my problem?

      I have no idea. I have no error code, no source code and no description of the application architecture. Best Wishes, -David Delaune

      C 1 Reply Last reply
      0
      • L Lost User

        Hi, Your question is not very well formed. You should consider revising it and give us an error code, and any other relevant information.

        columbos14927 wrote:

        In my App i have one thread that grabs frames from a camera and paste them on the client window.

        Are you saying that you use Clipboard Operations[^] to paste an image? Are you sure about this?

        columbos14927 wrote:

        The client window belongs to the main thread of the App so when i try to resize it my App crushes.

        I certainly hope your monitors are not being crushed as that would get expensive very fast. :) I believe you mean crashes? If so... then you should have received an error code. When you ask for help from other software engineers... please give detailed information including any error code.

        columbos14927 wrote:

        I think it happens because the window is a mutual resource of the threads so what happens is that both access him at the same time.

        Windows belong to a single thread. However if you attempt to access resources that belong to that thread from other threads... Yes, this can cause problems.

        columbos14927 wrote:

        how can i solve my problem?

        I have no idea. I have no error code, no source code and no description of the application architecture. Best Wishes, -David Delaune

        C Offline
        C Offline
        columbos14927
        wrote on last edited by
        #3

        Hey, 1.The painting on the window is done by some function that is provided by frame grabber manufactorer. I pass to this function the the handle to my window and the frame and then i call the "RedrawWindow" function. 2.When i resize the window the App freezes and not responding to anything there are no error codes. Hope its more clear now...

        L 1 Reply Last reply
        0
        • C columbos14927

          Hey, 1.The painting on the window is done by some function that is provided by frame grabber manufactorer. I pass to this function the the handle to my window and the frame and then i call the "RedrawWindow" function. 2.When i resize the window the App freezes and not responding to anything there are no error codes. Hope its more clear now...

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi,

          columbos14927 wrote:

          1.The painting on the window is done by some function that is provided by frame grabber manufactorer.

          Have you considered contacting the manufacturer?

          columbos14927 wrote:

          2.When i resize the window the App freezes and not responding to anything there are no error codes.

          If you want to be a good software engineer then you will need to learn how to use your debugger. When your application freezes: 1.) Execute a Debug build of your application from Visual Studio with debugger attached. 2.) Inside your Visual Studio you need to do a 'Break All' 3.) In Visual Studio make sure that Debug->Windows->Thread is visible. If you are a keyboard kind of guy this would be: CTRL+ALT+H 4.) In Visual Studio make sure that Debug->Windows->Callstack is visible. If you are a keyboard kind of guy this would be: CTRL+7 5.) Each thread is listed in the window along with the top of the callstack. 6.) You can select a thread in the Visual Studio debugger... and the 'CallStack' window will show the callstack associated with that thread. Now you will be able to find what is causing the freeze. Sometimes I find that WinDbg[^] is more powerful. If you want to use this then you would: 1.) Compile a Debug version of your application with Visual Studio. 2.) Download and install Debugging Tools for Windows[^] 3.) Launch your application from WinDbg or conversely... attach to the running instance. 4.) Wait for the freeze, or invoke it. 5.) When it freezes... Choose Debug->Break from the menu or from keyboard CTRL+BREAK 6.) Issue the command: !analyze -v -hang to have WinDbg analyze any hangs. 7.) Inspect the callstack of all threads and look for possible causes to the hang: ~*kv 250 8.) Another useful command is: !runaway[^] for having a look at thread times. Sometimes a hanging thread is spinning in an infinite

          1 Reply Last reply
          0
          • C columbos14927

            Hey, In my App i have one thread that grabs frames from a camera and paste them on the client window. The client window belongs to the main thread of the App so when i try to resize it my App crushes. I think it happens because the window is a mutual resource of the threads so what happens is that both access him at the same time. how can i solve my problem? Thanks

            B Offline
            B Offline
            Bob Ciora
            wrote on last edited by
            #5

            Client area painting must occur in the main Windows thread. The problem is that the thread grabbing the frames is not the main Windows thread. So while it's drawing to the client area, any old windows message might come along and cause a crash as the two threads bump into each other. This is especially true when resizing - there are lots of "PAINT" messages hitting the dialog, and there's a good chance that PAINT handling is happening at the same time your other thread is drawing to the client area. Result is a crash. The solution is to have the main windows thread do the drawing. So you'll need a way to move the frames from the grabber thread to the windows thread, and signal your dialog that it's time to draw a new frame. You could try using a custom message, e.g. WM_USER+ ( see here: http://www.ucancode.net/Visual_C_MFC_Example/RegisterWindowMessage-WM_USER--VC-Example.htm[^] ). You can allocate a buffer to hold the frame and pass the pointer to that buffer as the LPARAM. The frame-grabber thread then just needs to PostMessage(...) to the Dialog. On the Dialog side, add the handler for the WM_USER+ message to draw the image pointed to by LPARAM. Don't forget to deallocate that buffer when done! This is just one example for moving information from some "outside" thread to the main windows thread. You can probably find many others. - Bob

            Bob Ciora

            C 1 Reply Last reply
            0
            • B Bob Ciora

              Client area painting must occur in the main Windows thread. The problem is that the thread grabbing the frames is not the main Windows thread. So while it's drawing to the client area, any old windows message might come along and cause a crash as the two threads bump into each other. This is especially true when resizing - there are lots of "PAINT" messages hitting the dialog, and there's a good chance that PAINT handling is happening at the same time your other thread is drawing to the client area. Result is a crash. The solution is to have the main windows thread do the drawing. So you'll need a way to move the frames from the grabber thread to the windows thread, and signal your dialog that it's time to draw a new frame. You could try using a custom message, e.g. WM_USER+ ( see here: http://www.ucancode.net/Visual_C_MFC_Example/RegisterWindowMessage-WM_USER--VC-Example.htm[^] ). You can allocate a buffer to hold the frame and pass the pointer to that buffer as the LPARAM. The frame-grabber thread then just needs to PostMessage(...) to the Dialog. On the Dialog side, add the handler for the WM_USER+ message to draw the image pointed to by LPARAM. Don't forget to deallocate that buffer when done! This is just one example for moving information from some "outside" thread to the main windows thread. You can probably find many others. - Bob

              Bob Ciora

              C Offline
              C Offline
              columbos14927
              wrote on last edited by
              #6

              Thanks allot!!!!

              1 Reply Last reply
              0
              • C columbos14927

                Hey, In my App i have one thread that grabs frames from a camera and paste them on the client window. The client window belongs to the main thread of the App so when i try to resize it my App crushes. I think it happens because the window is a mutual resource of the threads so what happens is that both access him at the same time. how can i solve my problem? Thanks

                J Offline
                J Offline
                JackDingler
                wrote on last edited by
                #7

                Another way to handle this may be to pause your camera app during dialog paint and resize functions. Assuming the API allows this.

                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