Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:24:02+00:00 2026-05-23T22:24:02+00:00

I’m writing an XML-RPC module in OCaml using the xml-rpc-light library. I’d like to

  • 0

I’m writing an XML-RPC module in OCaml using the xml-rpc-light library. I’d like to have a server which can receive concurrent requests and gather the data sent by all the requests in a common ‘state’. To be concrete, but simplifying the real problem, suppose the server provides the function

send : int -> bool

which sends an integer and returns true on success and false on failure, and that the server wants to keep a list of all the integers that were ever called since it started (including duplicates).

I understand the XML-RPC part. The part I’m having trouble to implement in OCaml is synchronizing the various client calls on the server side so that they are thread safe.

I’ve written a client class

class client =
    object
        val xr_client = new XmlRpc.client "http://localhost:11111"
        method send n = xr_client#call "send_integer" [`Int n] in
    end

which calls the appropriate send_integer remote method with some integer n.

I’ve also written a server class

class server =
    object(self)
        val mutable state = (ref [] : int list ref)
        val xr_server = new XmlRpcServer.netplex ()
        val m = Mutex.create ()
        method send n =
            let send_sync s n = (Mutex.lock m; s := n::!s; Mutex.unlock m) in
            (send_sync state n; `Boolean true)
        method init () =
            xr_server#register "send_integer"
                ~signatures:[[`Int; `Boolean]]
                (function
                   | [`Int x] -> self#send x;
                   | _ -> XmlRpcServer.invalid_params ());
            xr_server#run ()    
    end

which has a mutable state to keep all the integers and a send method to actually execute the client calls. For each client call, I just update the state. But if a second call comes before the second is finished, I run into thread safety problems. That’s why I’ve added the Mutex bit which uses a single class field mutex to acquire a lock on updating the state.

My questions are:

  1. Would synchronization be achieved by this?
  2. Are there neater ways of doing it?
  3. Is synchronization built-in in the XML-RPC server already, making all of this unnecessary?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:24:03+00:00Added an answer on May 23, 2026 at 10:24 pm

    After solving compilation problems with this code, I realised that we can’t use the threads library together with xmlrpc-light; at least directly. So, we can’t use the Mutex module anyway.

    Synchronisation is obtained by configuring the XML-RPC server to allow only one thread at a time during runtime. This can be achieved by providing our server with a configuration file similar to the adder example but setting max_threads = 1 in the last line. If we allow, say, 2 threads, then sometimes the change is made in the mutable state of one thread, sometimes it is made in the mutable state of the other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.