Author Topic: Change Thread Priority ?  (Read 1622 times)

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Change Thread Priority ?
« on: December 09, 2010, 06:00:06 am »
Hi Roman,

do you see a chance to set the thread priority by user?

I think the HID data receive Thread runs with "THREAD_PRIORITY_NORMAL".
But if you have a slow CPU and the main thread is very CPU intensive it meight result in data loss.
I use a 450MHz Win2000 laptop for such tests. And as described before I got data loss if the main thread is very busy.

Would be great to have an option to set the Thread priority with this values (from windows.pas):
Code: [Select]
  THREAD_PRIORITY_LOWEST              = THREAD_BASE_PRIORITY_MIN;
  {$EXTERNALSYM THREAD_PRIORITY_LOWEST}
  THREAD_PRIORITY_BELOW_NORMAL        = THREAD_PRIORITY_LOWEST + 1;
  {$EXTERNALSYM THREAD_PRIORITY_BELOW_NORMAL}
  THREAD_PRIORITY_NORMAL              = 0;
  {$EXTERNALSYM THREAD_PRIORITY_NORMAL}
  THREAD_PRIORITY_HIGHEST             = THREAD_BASE_PRIORITY_MAX;
  {$EXTERNALSYM THREAD_PRIORITY_HIGHEST}
  THREAD_PRIORITY_ABOVE_NORMAL        = THREAD_PRIORITY_HIGHEST - 1;
  {$EXTERNALSYM THREAD_PRIORITY_ABOVE_NORMAL}

Greetz Dominik

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Change Thread Priority ?
« Reply #1 on: December 09, 2010, 07:41:29 am »
Hello

Thank you for your information.

Yes we can add such option into our device components.

But there is one problem.
It will not resolve your problem.
The data lost is usual situation in serial communication and device tasks.
Your application should check data integrity and input stream whenever it is possible.

Roman Novgorodov
DeepSoftware.Com
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Change Thread Priority ?
« Reply #2 on: December 09, 2010, 08:10:08 am »
Hello Roman,

Software can check data integrity and  can send request to device, so device can send data again...

But if device not have enough memory to store realtime data and send again?

We need usb serial emulation version of this device? This can solve the problem? But I know  usb bulk transfers can be delayed.

So our device must have enough memory to store pending and coming data. is not?

« Last Edit: December 09, 2010, 08:11:50 am by hid1 »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Change Thread Priority ?
« Reply #3 on: December 09, 2010, 12:35:12 pm »
Hello

Quote
But if device not have enough memory to store realtime data and send again?

I think in this case device should stop data receiving and driver will return error on Write() method call.
Possible your device supports specific control request for checking current state of internal buffer.

I don't know :-)
Device can be various, please ask hardware designer of your usb device.

Roman Novgorodov
DeepSoftware.Com
« Last Edit: December 09, 2010, 01:11:05 pm by Roman Novgorodov »
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Change Thread Priority ?
« Reply #4 on: December 09, 2010, 01:47:55 pm »
hardware designer says:

"Ask your software designer, api, DLL *.sys  coder etc  "
;D

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Change Thread Priority ?
« Reply #5 on: December 09, 2010, 02:30:37 pm »
Hello

Quote
hardware designer says:
"Ask your software designer, api, DLL *.sys  coder etc  "

:-) It seems like recursion.

In this case device will refuse the data receiving and Write() operation will fail in sys driver.
You can try to reproduce this situation.

Roman Novgorodov
DeepSoftware
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Change Thread Priority ?
« Reply #6 on: December 10, 2010, 07:45:40 am »
Hi Roman,

Quote
The data lost is usual situation in serial communication and device tasks.
That is not the problem.

Quote
Your application should check data integrity and input stream whenever it is possible.
My application uses the nrHID thread to put incoming data into a memory pointer chain. Nothing else.
And the data computing is done by a worker thread.

So I think we uses the fastest methode to receive the HID data.

I did a test and patched the nrclasses unit:
Code: [Select]
constructor TnrThreadIO.Create(anrComm: TnrBaseIO);
begin
  inherited Create(True);
  // DS
  Priority := tpHigher;
  fnrComm := anrComm;
  FreeOnTerminate := True;
  Resume;
end;

Without setting the thread priority I lost ~60 packages from 41000.
Using the higer Priority the lost is zero.

So changing the priority in code and at designtime would be a very nice option - and I think it´s not a very difficult task  ;)

Greetz Dominik

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Change Thread Priority ?
« Reply #7 on: December 23, 2010, 08:37:44 am »
Hi Roman,

thx for adding the priority to 9.13.

But why is it not available for RS232, too?
This is also thread based ...

Greetz Dominik