Benjamin H. Bryant
2008-Feb-03 04:56 UTC
[Backgroundrb-devel] Defer multiple methods within the same worker to the thread pool?
Within a threaded worker, I would like to have multiple methods. Will the following code work? def method_1(args) thread_pool.defer(args) do |args| #work end end def method_2(args) thread_pool.defer(args) do |args| #work end end . . . or, should I have one "meta"-method and pass which sub-method to perform via args? def meta_method(args) thread_pool.defer(args) do |args| if args[:method] == "method_1" #do work end if args[:method] == "method_2" #do work end end end Thanks, Ben
Ryan Leavengood
2008-Feb-03 05:02 UTC
[Backgroundrb-devel] Defer multiple methods within the same worker to the thread pool?
On Feb 2, 2008 11:56 PM, Benjamin H. Bryant <iambenbryant at gmail.com> wrote:> Within a threaded worker, I would like to have multiple methods. Will > the following code work? > > def method_1(args) > > thread_pool.defer(args) do |args| > #work > end > > end > > def method_2(args) > > thread_pool.defer(args) do |args| > #work > end > > endYes that will work fine. The thread_pool.defer call just packages the block and arguments into a class which is put into a queue. The thread_pool pulls from that queue and executes the packaged code in the order it was received. Since I was making use of thread_pool.defer myself I read the source to see what it was doing, which is nothing too crazy. Regards, Ryan
Apparently Analagous Threads
- [LLVMdev] Hash Table Virtual Calls with Conflict Resolution Stubs
- Refactoring module
- Cannot start workers in production mode
- [LLVMdev] Do all user-written passes have to be run through a PassManager object (called from outside the LLVM infrastructure)?
- register_status for excess thread_pool?