Giter Site home page Giter Site logo

Is this tread safe? about threadpool HOT 2 CLOSED

danechitoaie avatar danechitoaie commented on July 18, 2024
Is this tread safe?

from threadpool.

Comments (2)

flandr avatar flandr commented on July 18, 2024

It wouldn't be a very useful thread pool if it wasn't safe to interact with from multiple threads ;)

I'm not sure if I understand your proposed use, though. You don't need a thread to "consume the pool"; the pool itself is composed of worker threads that consume the tasks that you add via the execute or schedule interfaces. If you instantiate a threadpool with a maximum worker count of one then it implements the scenario you've described: one worker thread will execute all tasks enqueued via execute in sequential order.

The workers listen for tasks until the pool is destroyed; the drain method merely waits until all tasks added prior to its invocation have completed.

from threadpool.

danechitoaie avatar danechitoaie commented on July 18, 2024

Oh, make sense now. Sorry if my questions was not clear, I'm new to C++ so maybe I didn't asked the right things the right way.

Basically I'm looking to use this in combination with a filesystem watch library that will trigger an event each time a file has changed on disk in some folders. When that happens I just need to execute/queue a task with one param being the file path that was changed. For some reason I was under the impression that only when calling drain the execution of the tasks starts. Makes more sense that drain just waits.

I think it's clear now. Thank you.

from threadpool.

Related Issues (2)

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.