Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

SetThreadPriority() - idle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SetThreadPriority() - idle

    I seen a few examples to reset the thread-priority with PB.

    I am looking to set the thread idle or just above.

    I was thinking about using SetThreadPriority() with the idle flag.

    Not sure if this is reliable to mix this one.

    Also.. if it's ok to use, can it be done from inside the thread procedure itself?
    Maybe using GetCurrentThreadID() or so?

    Thanks,
    hellobasic

  • #2
    Edwin I've set priority OK but not from within.

    What I do is...
    Code:
     THREAD CREATE functionanme (param) SUSPEND to hthread
     SetThreadPriority  hThread, value
     THREAD  RESUME  hThread
     ...
    .. but I don't see any reason you couldn't do it from within the context of the thread.

    EXCEPT:

    SetThreadPriority requires a HANDLE not an ID so GetCurrentThreadID() is useless but GetCurrentThread (), which returns a handle ONLY valid in that thread's context should work.

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      There is also a threadid PB-call, maybe i can use that one from inside the thread?
      hellobasic

      Comment


      • #4
        >There is also a threadid PB-call, maybe i can use that one from inside the thread?

        I've used THREADID and the PB THREADID function returns the same unique identifier as does Windows via direct call. I've used that, too.

        On the larger challenge you face.....

        First of all, it's easy enough to test if your priority change is working: you can GetThreadPriority() and compare it to whatever you last set it to and see if they match. If they do, it works (hint: it works). If they don't, show failing code.

        Second of all, it does not make design sense to change a thread's priority during execution of the thread function... at least not to me it doesn't. At the point at which you elect to launch an additional thread of execution you should know the priority at which you want it to execute.

        The only thing which 'might' make sense is if your thread function is sitting in a polling loop, and you want to increase or decrease the polling frequency at certain times.

        But using a polling loop is terribly inefficient anyway. Better you should use Windows Events as demonstrated here: Terminate Worker Threads Using Windows Events (and Using Thread Local Storage) Demo Dec 23 2005

        You can play with that logic to effect a priority change, but a priority change should not be necessary *IF* your thread function is already codes to use a wait state with the WinAPI synchronization functions ... Windows is exceptionally efficient at querying for signalled events. That is, your thread function consumes very few resources while waiting for something to do, and then executes at the priority you have set when it DOES have something to do.

        But... what is it you are trying to accomplish? Maybe someone will have an idea for you.

        (You might also want to send in the same New Feature Suggestion I have sent in...
        I think we could use...
        Code:
        THREAD GET|SET PRIORITY [to value]| newpriority [TO oldpriority]
        .. and while we're at at how about..
        THREAD GET|SET SECURITY  (params)
        MCM
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          During startup my PwrDev IDE is parsing the winapi.inc for tooltips/declarations.
          For myself i have no issue with it, it's really fast but still it might 1 or 2 seconds or worse on really low PC's.

          Though i want to have somewhat more control over this and i really have no need for superspeed in these kind of threads and i don't want the IDE suffer under this.

          I have encountered this with another IDE where parsing is somewhat different and sometimes slower (due disk access or so).
          I am not looking for a better parsing technique yet, i am looking for 'set thread to idle' for my future programming.

          Window GUI's should not suffer under async. executed parts.
          Microsoft's Visual Studio for example is truly annoying, after loading the project it's doing all kinds of stuff and you can click what you want but it'
          s not reacting.
          This all without any indication what he's doing.

          Setting it to idle from inside the thread makes programming more easy, the code would be at one location only.
          Now we need a wrapper, not so bad also.
          hellobasic

          Comment


          • #6
            Do you have a splash screen? Splash Screens are often used to give the user something to do while the program initializes. Maybe some action photos of naughty Catholic High School Girls could distract the user whilst you parse?

            Code:
            FUNCTION WinMain ...
            
                 hGlobal  = Block of memory to hold results of parsing 
                 THREAD CREATE functiontoReadWinApi.Inc file ( hGlobal)  SUSPEND  to hThread
                 SetthreadPriority  whatever. 
                 THREAD RESUME hThread
                 THREAD CLOSE hThread 
                 CreateWindow (SplashScreen) 
                 ShowWindow (SpashScreen) 
                 WHILE GetMessage ....
                 WEND
            
            FUNCTION WndProcSplash.....
            
                 SELECT CASE wMsg
                    CASE %PWM_WINAPI_PARSE_COMPLETE
                        enable stuff requiring Win32API be parsed. hGlobal in lparam 
                        PostMessage  hWnd, WM_CLOSE          ' close splash window
            
            ..
            FUNCTION ParseFunction (hGlobal)
            
               Parse file, store info in hglobal 
            
               PostMessage hWndSplash, %PWM__WINAPI_PARSE_COMPLETE, %NULL, hGlobal
            
            END FUNCTION
            Something like that, anyway.

            (Look ma, no GLOBALs!)

            MCM
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              I'll make some tests soon.

              Thanks,
              hellobasic

              Comment

              Working...
              X