AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi BeginThreadAffinity() or SetThreadAffinity
Thema durchsuchen
Ansicht
Themen-Optionen

BeginThreadAffinity() or SetThreadAffinity

Ein Thema von Razor · begonnen am 7. Mai 2008 · letzter Beitrag vom 9. Mai 2008
 
Razor
(Gast)

n/a Beiträge
 
#10

Re: BeginThreadAffinity() or SetThreadAffinity

  Alt 9. Mai 2008, 12:53
Here we go this is more like it 8)

AffinityMask CPU to use
1 0
2 1
3 0,1
4 2
5 0,2
6 0,1,2

function SetThreadAffinityMask(hThread: THandle; dwThreadAffinityMask: DWORD): DWORD; stdcall;


Steps:
1. Create a new class derived from TThread.
2. Include an AffinityMask property (or type DWORD) with a SetAffinityMask procedure.
3. Call SetThreadAffinityMask on the SetAffinityMask procedure.
4. Change your programs to inherit from your new thread class.
5. Use your new property MyThread.AffinityMask = 3 (3 for dual processor systems)

Delphi-Quellcode:
Code


unit ExThread;
 
interface
 
uses
  Classes;
 
type
  TExThread = class(TThread)
  private
    FAffinityMask: DWord;
    procedure SetAffinity(const Value: DWord);
    { Private declarations } 
  protected
    procedure Execute; override;
  public
    property AffinityMask : DWord read FAffinityMask write SetAffinity;
  end;
 
implementation
 
{ Important: Methods and properties of objects in VCL can only be used in a
  method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure TExThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }
 
 
{ TExThread } 
 
procedure TExThread.Execute;
begin
  { Place thread code here } 
end;
 
procedure TExThread.SetAffinity(const Value: DWord);
begin
  FAffinityMask := SetThreadAffinityMask(Handle,Value);
  if FAffinityMask = 0 then raise Exception.Create('Error setting thread affinity mask : ' + IntToStr(GetLastError));
end;
 
end.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:27 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz