Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Reentrant definition
Forum Update on Monday, May 27th 2025

[SOLVED] Reentrant definition

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • 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.
  • W Offline
    W Offline
    willypuzzle
    wrote on last edited by
    #1

    I don't understand reentrant definition:

    http://harmattan-dev.nokia.com/docs/library/html/qt4/threads-reentrancy.html

    what does he means with "each invocation uses its own data"?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      Example:

      Imagine you have a sort() function that sorts a given array of integers. If the function is "reentrant", you can safely call it simultaneously from different threads, but only if each thread passes its own separate array to the function. Calling it multiple times in parallel on the same array would not be safe. Also, if the function was not reentrant, then calling the function simultaneously from different threads would not be safe, even if each thread uses its own separate array. That would be the case, e.g., if the function internally uses global/static variables.

      --

      In C++, object functions usually are reentrant, simply because each object (instance) has its own separate member variables, so there are no conflicts, as long as each thread calls the function on its own separate object (instance). But as soon as multiple threads try to call the function on the same object (instance), there will be conflict again, so object functions usually are not tread-safe. Thread-safety requires that all access to member variables is carefully protected by, e.g., Mutexes. Don't assume thread-saftey, unless the docs explicitly state it.

      And take care: Object functions still can be non-reentrant, e.g., if static member variables are involved :-/

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • W Offline
        W Offline
        willypuzzle
        wrote on last edited by
        #3

        Ok, thanks, I have well understood :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved