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. 'Pushing' a thread...

'Pushing' a thread...

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpalgorithmssecurityquestion
6 Posts 5 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.
  • M Offline
    M Offline
    Mr Freeze
    wrote on last edited by
    #1

    Hi, I'm wondering if it is possible to 'push' a thread to execute more often when another thread is waiting for some data from the first one? The concret case is the following: My application created a secondary thread for displaying data. The main thread modifies that data and to avoid displaying wrong data I use flags. When the secondary thread is busy, the first one waits until the security flag is reset. Depending on the compiler options the results are different: for 'standard optimization' there is no problem, but for 'speed optimized' the main thread waits forever because somehow the secondary thread doesn't continue... ?? Can someone help ?? Thanks :)

    K N M M M 5 Replies Last reply
    0
    • M Mr Freeze

      Hi, I'm wondering if it is possible to 'push' a thread to execute more often when another thread is waiting for some data from the first one? The concret case is the following: My application created a secondary thread for displaying data. The main thread modifies that data and to avoid displaying wrong data I use flags. When the secondary thread is busy, the first one waits until the security flag is reset. Depending on the compiler options the results are different: for 'standard optimization' there is no problem, but for 'speed optimized' the main thread waits forever because somehow the secondary thread doesn't continue... ?? Can someone help ?? Thanks :)

      K Offline
      K Offline
      Krouer
      wrote on last edited by
      #2

      You can increase the thread priority SetThreadPriority in MSDN

      1 Reply Last reply
      0
      • M Mr Freeze

        Hi, I'm wondering if it is possible to 'push' a thread to execute more often when another thread is waiting for some data from the first one? The concret case is the following: My application created a secondary thread for displaying data. The main thread modifies that data and to avoid displaying wrong data I use flags. When the secondary thread is busy, the first one waits until the security flag is reset. Depending on the compiler options the results are different: for 'standard optimization' there is no problem, but for 'speed optimized' the main thread waits forever because somehow the secondary thread doesn't continue... ?? Can someone help ?? Thanks :)

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Set the priority to THREAD_PRIORITY_HIGHEST or even THREAD_PRIORITY_TIME_CRITICAL, do your stuff and then put it back to THREAD_PRIORITY_NORMAL Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

        1 Reply Last reply
        0
        • M Mr Freeze

          Hi, I'm wondering if it is possible to 'push' a thread to execute more often when another thread is waiting for some data from the first one? The concret case is the following: My application created a secondary thread for displaying data. The main thread modifies that data and to avoid displaying wrong data I use flags. When the secondary thread is busy, the first one waits until the security flag is reset. Depending on the compiler options the results are different: for 'standard optimization' there is no problem, but for 'speed optimized' the main thread waits forever because somehow the secondary thread doesn't continue... ?? Can someone help ?? Thanks :)

          M Offline
          M Offline
          markkuk
          wrote on last edited by
          #4

          Have you declared the flag variable as volatile? If you didn't, the compiler doesn't know it may be changed in another thread, and can optimize away checks for its value.

          1 Reply Last reply
          0
          • M Mr Freeze

            Hi, I'm wondering if it is possible to 'push' a thread to execute more often when another thread is waiting for some data from the first one? The concret case is the following: My application created a secondary thread for displaying data. The main thread modifies that data and to avoid displaying wrong data I use flags. When the secondary thread is busy, the first one waits until the security flag is reset. Depending on the compiler options the results are different: for 'standard optimization' there is no problem, but for 'speed optimized' the main thread waits forever because somehow the secondary thread doesn't continue... ?? Can someone help ?? Thanks :)

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

            When you say a "flag" do you mean a bool variable? If so, then that is the wrong way to synchronize threads. Use a critical section instead. See InitializeCriticalSection() and related APIs. --Mike-- http://home.inreach.com/mdunn/ Help! Help! I'm being repressed!! :love: your :bob: with :vegemite: and :beer: Sonork - 100.10414 AcidHelm

            1 Reply Last reply
            0
            • M Mr Freeze

              Hi, I'm wondering if it is possible to 'push' a thread to execute more often when another thread is waiting for some data from the first one? The concret case is the following: My application created a secondary thread for displaying data. The main thread modifies that data and to avoid displaying wrong data I use flags. When the secondary thread is busy, the first one waits until the security flag is reset. Depending on the compiler options the results are different: for 'standard optimization' there is no problem, but for 'speed optimized' the main thread waits forever because somehow the secondary thread doesn't continue... ?? Can someone help ?? Thanks :)

              M Offline
              M Offline
              Mr Freeze
              wrote on last edited by
              #6

              Thanks for all your replies. It's right, I forgot to specify the flag as 'volatile'. Without this even when increasing the other thread's priority it wouldn't have worked. But I didn't use a critical section... I'll try to implement it in future :) cheers Marc

              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