(* ocamlfind ocamlopt -o netclient_https_threads -thread -linkpkg -package threads,netclient,ssl,equeue-ssl netclient_https_threads.ml http://docs.camlcity.org/docs/godipkg/3.12/godi-ocamlnet/doc/godi-ocamlnet/html/Https_client.html *) open Printf module HTTP = Http_client module HTTPS = Https_client ;; let mutex = Mutex.create () let compact () = Mutex.lock mutex; Gc.compact (); Mutex.unlock mutex;; let () = Ssl.init ~thread_safe:true ();; let fresh_pipeline () = let pipeline = new HTTP.pipeline in let ssl_ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in let tct = HTTPS.https_transport_channel_type ssl_ctx in pipeline#configure_transport HTTP.https_cb_id tct; pipeline ;; let f () = begin try Mutex.lock mutex; let pipeline = fresh_pipeline () in let call = new HTTP.get "https://www.google.com/" in pipeline#add call; pipeline#run (); Mutex.unlock mutex; printf "ok\n%!"; flush stdout; with e -> Printf.eprintf "Error: %s\n%!" (Printexc.to_string e) end; ;; let threads = Queue.create ();; for i = 1 to 10 do Queue.add (Thread.create f ()) threads; (*Thread.join (Queue.take threads)*) done;; while not (Queue.is_empty threads) do Thread.join (Queue.take threads) done;;