Actually I don't like the ISO/IEC DTR 13211{5:2007 very much.
It is not really based on:
- Abstract Datatypes that might happen to use Monitors
(Most annoying)
- In case there are Datatypes, we always need some explizit destroy
(Less annoying)
As a result, since there are not really separate data types
in the proposal in carefully showing inheritance or union types,
we seen monsters like:
3.2.7.4 Examples
thread_send_message(t, exit).
3.6 Thread and message queue communication
thread_send_message(queue2, father(antonio))
3.6.1.2 Template and modes
thread send message(+queue or alias, @term)
So somehow in the evolution of this API, people where first
thinking of only sending messages to threads, like in the
Hewitt Actor model. (3.2.7.4 Examples)
Then it occured that no, we can also have queues separately
in existence, and communicate with them. ( 3.6 Thread and
message queue communication).
As a result the predicate has:
- An awful name, its called thread_send_message/2,
wouldn't be queue_send/2 be a better name?
- Incomplete documentation, 3.6.1.2 Template and modes
mentions only queue as argument and not thread as argument.
thread_send_message(+queue or alias, @term)
SWI-Prolog is more precise here:
thread_send_message(+QueueOrThreadId, +Term)
http://www.swi-prolog.org/pldoc/man?predicate=thread_send_message/2
- We always need alias/1 options, and all the predicates
need to also accept naming of an object. this has already
started in the ISO standard for streams.
But is this needed if we could do the following with references?
?- mutex_new(M), assertz(my_table(my_alias, M)).
Etc..
I was exploring an other path recently, preparing next release
1.1.5 of Jekejeke Prolog Runtime:
Enhanced Module thread:
http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/10_docu/05_frequent/07_theories/20_system/04_thread.html
New Module lock:
http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/10_docu/05_frequent/07_theories/21_misc/03_lock.html
New Module queue:
http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/10_docu/05_frequent/07_theories/21_misc/04_queue.html
Well, one cannot send a message to a thread in the
above API, still exploring whether this is really needed.(*)
Here is an example of a findall implemented via threads,
that explicitly deals with queues:
threadall/3 predicate: Findall via threads
https://gist.github.com/jburse/696ab00b089e615577002b7854e3ca7f#file-all-p
(No error handling yet implemented)
Bye
(*)
In the Go programming language (Golang) from Google there are
also first Go routines, i.e. the go statement, and then later
channels as first class objects.
Maybe could learn from Golang, and enhance the module "queue"
into a module "channel", adding things like closing a channel,
or selecting from multiple channels.
http://guzalexander.com/2013/12/06/golang-channels-tutorial.html
Jan Burse schrieb: