Coder Social home page Coder Social logo

Comments (4)

addisonElliott avatar addisonElliott commented on June 7, 2024

QtPromise is used for promises in this library. The thread safety declaration is here: https://qtpromise.netlify.app/qtpromise/thread-safety.html

Fundamentally, I believe it relies on the Qt event loop which is thread safe if used correctly.

from httpserver.

AimplainLeo avatar AimplainLeo commented on June 7, 2024

Thanks Elliot. If could please show me the right method for processing heavy task with other module (such as ObjectDetection -OD- module - which run in other thread), without run qconcurrent for promise ( i cannot init this module alot of times, only one OD instance for whole project). Now, i can use async with timeout for send result. But it is not useful if processing time in OD is less or more than time out of task. Thank you very much!

from httpserver.

addisonElliott avatar addisonElliott commented on June 7, 2024

So, I'll provide a simplified example of what I do. I use HttpServer in a production application and I have blocking code that I run on a separate thread that is promisified.

Fundamentally, I want to point out this question is unrelated to this library however. Given that, I'm going to close this issue as well.

See the below Gist for an example of how you can do this: https://gist.github.com/addisonElliott/183f61b8594d294a5bb8d7b6486cf492

Note that this example won't work as-is. It's just meant to demonstrate the concept.

Details

  • Qt's event loop is thread safe is used properly. So, I rely on that to communicate between the threads. Note that no data is shared between the threads except via the Qt event loop. Otherwise, it wouldn't be safe.
  • WorkerThread is the class that starts the separate thread that processes various things. The main thread should initiate WorkerThread.
  • The Worker class has a list of slots that are executed on the separate thread. This is only meant to be used internally by WorkerThread.
  • WorkerThread has the helper function execAsyncPromise that invokes a given slot in the Worker class on the separate thread.
  • WorkerThread::setControllersOffline() - This function creates a promise that will execute the blocking function on Worker
  • Worker::setControllersOffline() - This function is executed on the separate thread and can be blocking.

from httpserver.

AimplainLeo avatar AimplainLeo commented on June 7, 2024

Wow, thank you very much!

from httpserver.

Related Issues (8)

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.