Giter Site home page Giter Site logo

ezthreads's People

Contributors

mr-highball avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ezthreads's Issues

force terminate not respected

this used to work, however I during some refactors this must've been neglected. the main issue is that thread killing logic is inside the max runtime logic (which means if no max, then no force terminates will work). in addition to that, we need to verify this code actually works as it looks a little off to me now.
this was found out in #6

[question] How to report progress from download thread?

Hello!

I have main thread with form and progress bar.
To download some file I call function that create new thread.
Is it possible to call at any time some function with synchronisation with main thread?

procedure Download(Url: string);
var
  DownloadThread: IEZThread;
begin
  DownloadThread := NewEZThread();
  DownloadThread.AddArg('downloadUrl', Url);
  DownloadThread.Setup(BackgroundDownload);
  DownloadThread.Settings.UpdateSynchronizeStopEvents(True);
  DownloadThread.Events.UpdateOnStopCallback(BackgroundDownloadSetupComplete);
  DownloadThread.Start();
end;

procedure BackgroundDownload(const AThread: IEZThread);
begin
  // Here i have download object with progress callback that on each step has some chunk of data.
  // So i have all data to report progress.
  // But how from this thread (while it is running) i can report download progress to main thread?
  // I'm looking for something like AThread.Synchronize( {some function to execute from main thread} );
end;

procedure BackgroundDownloadSetupComplete(const AThread: IEZThread);
begin
  // Here we are in main thread
  // We can get download results from AThread
end;

I saw solution with thread pool, but i'm curious is it possible with this approach.

Freezes with FPC 3.2

Testing ezthreads_tester_ui with lazarus 2.0.9 and fpc 3.2.
After pressing Do it button main thread freezes after 10 sec.


Is there a way to set thread name?

Worker that executes every X seconds

Hello!

What is the best way to implement background worker, that will execute some method every 30 seconds?
And how to terminate worker by force when app closing?

[Docs] Would you be inclined to add an example with Synchronize?

Hey @mr-highball,

First I have to admit that I haven't dived into your framework's code to see if there is an example. I'm sorry if I'm asking for something already obvious on the code.

My ask is quite simple: On README.md, add a simple example with main thread synchronization denoted by the use of the TThread.Synchronise() procedure. That's it!!

Many thanks in advance!

Cheers,
Gus

The test TestForceKill and undelaying KillThread function does not kill the thread as experienced before under Linux

Hi, thank you for your great units. The code is easy to use.

I'm running Ubuntu with FreePascal 3.2.0 and Lazarus 2.0.12 and I use the matter it to check if the KillThread(ThreadID) behavior of the cthreads has common issues.

I have the issue that the KillThread(ThreadID) won't kill anything despite of giving a positive call result of 0, as written in the handbook. The thread continues the Execute part (..see attached script TestAsync.zip).

I have used your test program ezthreads_tester.lpr, extract the relevant part and added some timestamps (...see TestEzAsync.zip), to get a "second opinion" and to see if the KillThread issue is a "feature" under Linux. It seems to me, that there are the same issues in both programs (TestAsync and TestEzAsync). As you see I set the sleep time of the thread to 10 s, the program should be killed after 50 ms but the the program is running through the complete 10 s defined by the sleep time (..see CONFIG TestEzAsync and OUTPUT TestEzAsync).

I got similar results with my clunky command loop test when i call kill the execution process remains and jumps back to the next input prompt (OUTPUT TestAsync).

** Question 1** Is this behavior for cthread Linux specific and KillThread(...) malfunctioned?

** Question 2** Is there a possibility, to solve that issue BEYOND the permanent commented common solution, to flag the Execution procedure to stop at a certain point (in a loop for example)? I'd like to use the timeout-kill feature in a socket connection context (SQL request for example).

CONFIG TestEzAsync

  LThread:=TEZThreadImpl.Create;
  LThread
    .AddArg('sleep',10000)  // < -------------- HERE
    .AddArg('start',Now)
    .Settings
      .UpdateMaxRuntime(50) // <------------ HERE
      .UpdateForceTerminate(True)  //non-graceful termination, but guarantees no dangling threads after timeout
      .Thread
    .Events
      .UpdateOnStopNestedCallback(@CheckElapsed)
      .Thread
    .Setup(@Setup)
    .Start;

OUTPUT TestEzAsync

TestForceKill: force kill start 30-12-99 13:27:07
TestForceKill::CheckElapsed::elapsed time - 51
TestForceKill::force kill finished 30-12-99 13:27:17 <------- 10 s left

OUTPUT TestAsync

------- START --------
PROMPT> kill
KILL.REQUEST: 30-12-99 13:46:18
KILL.RESULT:  0 0 - means OK 30-12-99 13:46:18 <------- should stop here 
PROMPT> exit
----- READY ----------
```

TestAsync.zip
TestEzAsyn.zip

await() freezes in GUI apps during events

in #14 an example was provided that called Await() on an ezthread during the destructor of an object that was triggered by a form.close(). the solution was to pump via Application.ProcessMessages() in a loop checking on the thread state = esStarted

Ac's

  • detect GUI apps in Await and instead of just calling Sleep(), call Application.ProcessMessages() first

Notes

  • this should not break console apps, is there a way to detect the difference, or just check on if Assigned(Application)
  • in the Forms unit

Thread pool support

Does ezthreads support thread pool? If yes, is there any sample code for me to get started?

Add method for synchronizing to the UI

A request was made in #14 to simplify synchronizing events to the UI.

AC's

  • add a method to queue a callback for UI
  • should provide the reference to this ezthread

Notes

  • could we leverage a new ezthread and use the synchronize on stop event?

ezthread pool memory leak

worker threads appear to be holding on to a reference to the pool causing pools to have an additional reference count for each worker defined causing a memory leak as reported here in #6

unsure right now exactly the fix, need to do some research and report back here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.