PreviousUpNext

15.3.515  src/lib/std/src/pthread/cpu-bound-task-pthreads.api

## cpu-bound-task-pthreads.api
#
# Server pthreads to offload cpu-intensive computations
# from the main threadkit pthread.
#
# Any number of cycleservers can be started.
# Typically you'll want to start one cycleserver
# for each core on the host, or perhaps one less
# for better interactive response (to keep one core
# free for the main threadkit pthread).
#
# For load balancing, the cycleservers take tasks
# from a single internal taskqueue on a first-come
# first-served basis
#
# See also:
#
#     src/lib/std/src/pthread/io-bound-task-pthreads.api
#     src/lib/std/src/pthread/io-wait-pthread.api

# Compiled by:
#     src/lib/std/standard.lib


stipulate
    package pth =  pthread;                                                     # pthread                       is from   src/lib/std/src/pthread.pkg
herein

    # This api is implemented in:
    #
    #     src/lib/std/src/pthread/cpu-bound-task-pthreads.pkg

    api Cpu_Bound_Task_Pthreads {
        #
        get_count_of_running_pthreads: Void -> Int;                             # You'll typically want this to be equal to the number of cores, or one less.
        #
        start:      String -> Int;                                              # 'String' will be logged as the client requesting startup.
        #                                                                       # Returns number of cycleservers now running -- count includes the just-started one.

        Do_Stop = { who:   String,                                              # 'who' will be logged as the client requesting shutdown.
                    reply: Void -> Void
                  };
        stop:     Do_Stop -> Void;

        Do_Echo = { what:  String,                                              # 'what' will be passed to 'reply'.
                    reply: String -> Void                                       # This is mainly just for unit testing and such.
                  };
        echo:  Do_Echo -> Void;

        do:    (Void -> Void) -> Void;                                          # This is the workhorse call. Arg is thunk to evaluate -- any reply needed will be embedded within it.
    };
end;

## Code by Jeff Prothero: Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext