_______________________________________________ Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
bonasso bonasso@traclabs.com writes:
In ACL one starts a process with a function as follows:
(mp::process-run-function 'start-raps rap::rap-state* 2 nil)
where you give process-run-function the function name and the rest are the args to that function.
I couldn't really find how to do that in abcl. system::run-program was the closest thing but the definition in the manual didn't seem to be what I was looking for.
Looking at the documentation of "process-run-function" it seems that what you want is to run a function in a another thread and not a system program (which is what "run-program" is for). You should look in the manual for the THREADS package, especially the "make-thread" function.
The interface of "make-thread" is slightly different from the interface of "process-run-function" due to the fact that "make-thread" receives a function, but not it's arguments.
However you can work around this by providing your own wrapper function similar to this:
(defun my-make-thread (name function &rest arguments) (threads:make-thread (lambda () (apply function arguments)) :name (if (symbolp name) (symbol-name name) name)))
And then you can use it like this:
(setf my-thread (my-make-thread 'my-thread-name #'format nil "This is an example: ~s" 10))
(let (output) (setf output (threads:thread-join my-thread)) output)
And output should contain the string "This is an example: 10".
_______________________________________________ Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
_______________________________________________ Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
_______________________________________________ Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
On Thu, May 29, 2014 at 9:49 PM, bonasso bonasso@traclabs.com wrote:
Some lisps have an allow-schedule for processes, such as (mp::process-allow-schedule). Basically, this function allows processes other than the running (and hence calling) process to run. All other processes of equal or higher priority to the calling process will have a chance to run before the calling process is next run. This function is useful when a process seems to be using all available resources.
I couldn't find anything like that in the threads package unless it had to do with mutex...
Is there an equivalent function in abcl?
This is called yield in Java land. That might ring a bell to you.
BTW unless you're using implementation-specific features, it probably makes sense to use the bordeaux-threads portability library to have the same threading API on all major Lisps.
bonasso bonasso@traclabs.com bonasso@traclabs.com writes:
In ACL one starts a process with a function as follows:
(mp::process-run-function 'start-raps rap::rap-state* 2 nil)
where you give process-run-function the function name and the rest are the args to that function.
I couldn't really find how to do that in abcl. system::run-program was the closest thing but the definition in the manual didn't seem to be what I was looking for.
Looking at the documentation of "process-run-function" it seems that what you want is to run a function in a another thread and not a system program (which is what "run-program" is for). You should look in the manual for the THREADS package, especially the "make-thread" function.
The interface of "make-thread" is slightly different from the interface of "process-run-function" due to the fact that "make-thread" receives a function, but not it's arguments.
However you can work around this by providing your own wrapper function similar to this:
(defun my-make-thread (name function &rest arguments) (threads:make-thread (lambda () (apply function arguments)) :name (if (symbolp name) (symbol-name name) name)))
And then you can use it like this:
(setf my-thread (my-make-thread 'my-thread-name #'format nil "This is an example: ~s" 10)) (let (output) (setf output (threads:thread-join my-thread)) output)
And output should contain the string "This is an example: 10".
Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
_______________________________________________ Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
_______________________________________________ Armedbear-devel mailing list Armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
armedbear-devel@common-lisp.net