((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/pthreads" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.")) (section 2 "pthreads" (p "Maintain and talk to a pthread pool.")) (section 2 "Overview" (p "Most of the egg's work is done in the startup: a pool of " (tt "pthreads") " waiting for a job is initialized.") (p "Only code having a C calling convention can be sent to the pool (and asynchronously call back to Scheme). Scheme code runs in the CHICKEN thread.")) (section 2 "Issues" (ul (li "Requires recent chicken version 4.11 or at least git master rev. 8294683 of 2016-01-14") (li "Starts currently 5 pthreads. TBD: make this configurable and start as many threads a the operating system configured processors are available.") (li "The Scheme API is not yet tested."))) (section 2 "Requirements" (p "None.")) (section 2 "API" (section 3 "C" (def (sig (syntax "typedef int (*C_pthread_request_function_t)(void *);" (id typedef)))) (def (sig (procedure "extern int start_asynchronous_request(C_pthread_request_function_t function, void *data, void *callback);" (id extern))) (p "Send " (tt "function") " to be executed at any thread of the pool.  " (tt "Function") " must accept one argument, the " (tt "data") ".  " (tt "Callback") " must be a " (tt "C_GC_ROOT") " object holding the procedure to receive the result for " (tt "function") ".")) (def (sig (procedure "void C_interrupt_call(void *callback, void *result, void *value)" (id void))) (p "Tell CHICKEN to call the procedure held in the " (tt "C_GC_ROOT") " object " (tt "callback") " on the result of applying the " (tt "C_GC_ROOT") " object " (tt "result") " to " (tt "value") ".") (p "Predecessor of " (int-link "concurrent-native-callbacks") " - it may be easier to use the latter."))) (section 3 "Scheme" (def (sig (procedure "(pool-send! JOB DATA CALLBACK) -> undefined" (id pool-send!))) (p "All arguments given as non-null-c-pointer.") (p (tt "JOB") ": The C procedure to call") (p (tt "DATA") ": Opaque pointer for parameter passing.") (p (tt "CALLBACK") ": Pointer to callback procedure wrapped in a " (tt "C_GC_ROOT") ". The callback is called with the value returned by " (tt "JOB") ".")))) (section 2 "Examples" (ul (li (link "https://github.com/0-8-15/sqlite3pth" "sqlite3pth egg repository") " on github.")) (pre "       (define sqlite3-start-prepare\n         (foreign-lambda*\n          void\n          ((<sqlite3-prepare-args> s) (nonnull-c-pointer callback))\n          \"start_asynchronous_request(\n            pthread_sqlite3_prepare, s, callback);\"))") (ul (li "Ask the author for alpha code running fuse on pthreads."))) (section 2 "About this egg" (section 3 "Author" (p "Jörg F. Wittenberger")) (section 3 "Source Code" (p "The " (link "https://github.com/0-8-15/pthreads" "pthreads egg repository") " is maintained on github.")) (section 3 "Version History" (p "Version 0.1: Initial import.") (p "Before: This code was ported from an RScheme module of the same author several years ago. Since it's been used in " (link "http://ball.askemos.org" "Askemos/BALL") ". Years later, in 2010, it was converted into an module of it's own.")) (section 3 "License" (p "BSD"))))