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. Problem with using OleLoadPicture in multithreaded application

Problem with using OleLoadPicture in multithreaded application

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
11 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.
  • A a mulay

    I am having problems using OleLoadPicture in multithreaded application.:(( Is this function really thread safe and does not pose any threats? Does it have any disadvantages? - Like I've heard that it creates temporary files to cache the images we load. How to tackle the multithreaded scenario as my application is creating more than 100 threads, each of which uses this function, and then one of the threads crashes while calling OleLoadPicture. Thanks in advance, Amit.

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #2

    Can you explain why you make 100 threads that use OleLadPicture?


    WhiteSky


    A 1 Reply Last reply
    0
    • H Hamid Taebi

      Can you explain why you make 100 threads that use OleLadPicture?


      WhiteSky


      A Offline
      A Offline
      a mulay
      wrote on last edited by
      #3

      The use of this function has been made in a dll. This dll is going to be used from a webservice. Right now I am trying do load testing through a C# appliaction and make the dll threadsafe. If I am using it for single thread then it works fine, but for multiple threads some threads finish their working successfully, and one of them crashes the application. There is no problem with image.

      H 1 Reply Last reply
      0
      • A a mulay

        The use of this function has been made in a dll. This dll is going to be used from a webservice. Right now I am trying do load testing through a C# appliaction and make the dll threadsafe. If I am using it for single thread then it works fine, but for multiple threads some threads finish their working successfully, and one of them crashes the application. There is no problem with image.

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #4

        Are you sure this error is of thread not OleLadPicture?


        WhiteSky


        A 1 Reply Last reply
        0
        • H Hamid Taebi

          Are you sure this error is of thread not OleLadPicture?


          WhiteSky


          A Offline
          A Offline
          a mulay
          wrote on last edited by
          #5

          The problem is not with the thread. The thing is that, some threads will finish successfully (They execute OleLoadPicture sucessfully) and suddenly in a random thread the function OleLoadPicture will not work, and then rest all threads which have yet to call this OleLoadPicture function, will not be able to execute it.

          H 1 Reply Last reply
          0
          • A a mulay

            The problem is not with the thread. The thing is that, some threads will finish successfully (They execute OleLoadPicture sucessfully) and suddenly in a random thread the function OleLoadPicture will not work, and then rest all threads which have yet to call this OleLoadPicture function, will not be able to execute it.

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #6

            How to run your threads immediately?


            WhiteSky


            A 1 Reply Last reply
            0
            • H Hamid Taebi

              How to run your threads immediately?


              WhiteSky


              A Offline
              A Offline
              a mulay
              wrote on last edited by
              #7

              WhiteSky wrote:

              How to run your threads immediately?

              I am not getting your question. Are you asking me post the code? Well, the threads are created from C# code and the call to function OleLoadPicture is in a C++ dll. This dll contains both managed and unmanaged code.

              H 1 Reply Last reply
              0
              • A a mulay

                WhiteSky wrote:

                How to run your threads immediately?

                I am not getting your question. Are you asking me post the code? Well, the threads are created from C# code and the call to function OleLoadPicture is in a C++ dll. This dll contains both managed and unmanaged code.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #8

                oh :rolleyes: it seems that I asked of you:)if you dont have prolem with OleLoadPicture and all things is ok and also threads working without problem except a thread I think your problem is on memory why?because you said you got this error in random case so I think you need to free memory (I had a problem like this with threads but my program sudden terminated and I was wodering when I trace my prgroam line to line it was working but if I run it didnt work...my problem was I needed to close threads and free memory) Now my guess is this,Did you check for free memory?:)


                WhiteSky


                A 1 Reply Last reply
                0
                • H Hamid Taebi

                  oh :rolleyes: it seems that I asked of you:)if you dont have prolem with OleLoadPicture and all things is ok and also threads working without problem except a thread I think your problem is on memory why?because you said you got this error in random case so I think you need to free memory (I had a problem like this with threads but my program sudden terminated and I was wodering when I trace my prgroam line to line it was working but if I run it didnt work...my problem was I needed to close threads and free memory) Now my guess is this,Did you check for free memory?:)


                  WhiteSky


                  A Offline
                  A Offline
                  a mulay
                  wrote on last edited by
                  #9

                  As you said there was this problem too that the threads were not getting terminated. Then one of my friends suggested using mutex object. So I tried to use mutex whereever memory allocation is needed and it worked. :-D Also the threads are getting terminated properly. But still there is a problem and that is of the memory not getting freed. Anyway, I will look into it. Thank you, Amit.

                  H 1 Reply Last reply
                  0
                  • A a mulay

                    As you said there was this problem too that the threads were not getting terminated. Then one of my friends suggested using mutex object. So I tried to use mutex whereever memory allocation is needed and it worked. :-D Also the threads are getting terminated properly. But still there is a problem and that is of the memory not getting freed. Anyway, I will look into it. Thank you, Amit.

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #10

                    If you want to use CreateMutex you need to call RleaseMutex for each mutext(why its not free)


                    WhiteSky


                    A 1 Reply Last reply
                    0
                    • H Hamid Taebi

                      If you want to use CreateMutex you need to call RleaseMutex for each mutext(why its not free)


                      WhiteSky


                      A Offline
                      A Offline
                      a mulay
                      wrote on last edited by
                      #11

                      Yes, I have used ReleaseMutex for each CreateMutex call. There must be some code that is doing leaking.

                      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