Pastebin

Paste #443: Thread function

< previous paste - next paste>

Pasted by Flawless

Download View as text

function TUnitTest.ThreadMutex(const Sender: XInterface): XResult; xcc;
var
  X, Y, Z: XInt;
begin
  for X := 0 to GlobalLoops-1 do
  begin
    GMutex.Lock();
    Z := Global+1;
    for Y := 0 to 10000 do
      SetGlobal(Z);
    GMutex.UnLock();
  end;
  Result := xsOK;
end;

this is instantiated in the unit test like so:

    16: begin
          XAssert(XMutexCreate(nil, nil, False, XMutex, GMutex));
          XAssert(XThreadCreate(nil, @ThreadMutex, False, 1024, XThread, T1));
          XAssert(XThreadCreate(nil, @ThreadMutex, False, 1024, XThread, T2));
          XAssert(XThreadCreate(nil, @ThreadMutex, False, 1024, XThread, T3));
          XAssert(T1.Join());
          XAssert(T2.Join());
          XAssert(T3.Join());
          Assert(Global = GlobalLoops*3);
        end;

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.