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. Asyncronus class and your method

Asyncronus class and your method

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 1 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.
  • R Offline
    R Offline
    Ruscoff
    wrote on last edited by
    #1

    Hi all, i've a question(hypothetical situation): There are two class class1 with a void funct_cl1()and other methods; (class1 use observer paradigm, funct_cl1 will be called with high frequency) class2 is a thread with some functions; In class2 i initialized class1 pointer like this: class1* cls1 = new class1() and i use some method of its but never funct_cl1. if i put in pause (p.e with a long sleep) the thread of class2, the funct_cl1 belong to cls1 can be anyway executed with observer paradigm or is it block? Regards Marco

    M 1 Reply Last reply
    0
    • R Ruscoff

      Hi all, i've a question(hypothetical situation): There are two class class1 with a void funct_cl1()and other methods; (class1 use observer paradigm, funct_cl1 will be called with high frequency) class2 is a thread with some functions; In class2 i initialized class1 pointer like this: class1* cls1 = new class1() and i use some method of its but never funct_cl1. if i put in pause (p.e with a long sleep) the thread of class2, the funct_cl1 belong to cls1 can be anyway executed with observer paradigm or is it block? Regards Marco

      M Offline
      M Offline
      Moak
      wrote on last edited by
      #2

      Hi Marco, I try an answer. Yes you can call a method from another thread, any object can be accessed from other threads. The real question is if the called functionality will be multithreading safe. Maybe this isn't even an issue in your case and you just wondered about ownership: Sleep() will only stop execution of one thread, but not prevent memory access from other threads. For example if class 2 creates an object of class1, which then is only used/called from another thread context, you don't even have to worry about multithreading (as long as lifetime of "class2 object thread" is longer than "class1 object thread"). Hope it helps /M

      Webchat in Europe :java: (only 4K)

      R 1 Reply Last reply
      0
      • M Moak

        Hi Marco, I try an answer. Yes you can call a method from another thread, any object can be accessed from other threads. The real question is if the called functionality will be multithreading safe. Maybe this isn't even an issue in your case and you just wondered about ownership: Sleep() will only stop execution of one thread, but not prevent memory access from other threads. For example if class 2 creates an object of class1, which then is only used/called from another thread context, you don't even have to worry about multithreading (as long as lifetime of "class2 object thread" is longer than "class1 object thread"). Hope it helps /M

        Webchat in Europe :java: (only 4K)

        R Offline
        R Offline
        Ruscoff
        wrote on last edited by
        #3

        perfect! thank you!

        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