#!/usr/local/bin/swipl /* * This FCGI example involves multiple threads accepting requests * * Copyright (C) 2015 Keri Harris */ :-use_module(library(fcgi)). service_requests(ID) :- forall(fcgi_accept, service_request(ID)). service_request(ID) :- format(atom(Flag), 'count__~w', [ID]), flag(Flag, N, N+1), format('Content-type: text/html\n\n', []), format('Multi-threaded FCGI\n', []), format('

Multi-threaded FCGI

\n', []), format('

Requests handled:

\n', []), forall(between(0, 9, X), ( format(atom(ThreadFlag), 'count__~w', [X]), flag(ThreadFlag, TN, TN), format('

Thread ~w: ~w

\n', [X, TN]) )), fcgi_finish. main :- forall(between(1, 9, X), thread_create(service_requests(X), _, [detached(true)])), service_requests(0). :- main.