Question

I am comparing a task queue/thread pool pattern system to an n-threads system in D. I'm really new to the D programming language but have worked with threads in C, Java, and Python before. I'm using the Tango library, and I'm building a webserver as an example.

I decided to use tango.core.ThreadPool as my thread pool, as my project is focused on ease of use and performance between traditional threading and task queues.

The documentation shows that I have 3 options:

  1. ThreadPool.wait() - Blocks the current thread while the pool consumes tasks from the queue.
  2. ThreadPool.shutdown() - Finishes the tasks in the pool but not the ones in the queue.
  3. ThreadPool.finish() - Finishes all tasks in the pool and queue, but then accept no more.

None of these things are what I want. It is my understanding that your list of tasks should be able to grow in these systems. The web server is very simple and naïve; I just want it to try its best at scaling to many concurrent requests, even if its resource management only consists of consuming things in the task queue as quickly as possible.

I suspect that it's because the main thread needs to join the other threads, but I'm a bit rusty on my threading knowledge.

Was it helpful?

Solution 2

I discovered that the way I was constructing my delegate contributed to blocking in some part of the code. Instead of closing over the object returned by SocketServer.accept, I now pass that object as a parameter to my delegate. I don't know why this was the solution, but the program now works as expected. I heard that closures in D version 1 are broken; maybe this has something to do with it.

OTHER TIPS

what about void append(JobD job, Args args) ? from the docs it works like the Executor.execute(Runnable) form java (submit a task to be run some time in the future)

note that here it is a LIFO queue instead of the expected FIFO queue so allocate enough workers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top