caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alex Baretta <alex@barettadeit.com>
To: Luca Pascali <luca@barettadeit.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Mutex and posix
Date: Sat, 15 Jan 2005 18:53:56 +0100	[thread overview]
Message-ID: <41E958B4.3000708@barettadeit.com> (raw)
In-Reply-To: <41E55E70.2080309@barettadeit.com>

Luca Pascali wrote:
> Xavier Leroy wrote:
> 
>> [...]
>> The latter is a recent addition to the POSIX threads API -- it's not
>> in the original POSIX threads spec (POSIX 1003.1c-1995).  I wouldn't
>> rely on this function being available in all POSIX threads
>> implementations.
>>
>>  
>>
> I didn't know this.
> 
>>> Polling continously is different. If I have two threads that are 
>>> running with scantimes one multiple of the other, it is possible that 
>>> one of the two threads (the slower one) fails always or almost always 
>>> the try_lock command.
>>>   
>>
>>
>> It's hard to give useful suggestions without knowing more about your
>> application, but it could be the case that you're using mutexes to do
>> things they are not really designed for, i.e. plain mutual exclusion,
>> for which neither trylock nor timedlock are needed.
>>
>> Maybe your application needs a more complex but better suited
>> synchronization mechanism, which can generally be built on top of
>> mutexes and conditions, or (at a higher semantic level) Concurrent
>> ML-style events.
>>
>> - Xavier Leroy
>>
>>  
>>
> I haven't an application.
> I was just thinking about how I could port some programs organizations 
> into Ocaml.
> 
> The case that rised my question was:
> If I have a shared resource (let's say a pipe or a queue, or a generic 
> file descriptor) for performing, for example, asyncronous communication 
> between threads, it's quite dangerous in terms of deadlocks to perform 
> myself a polling or locking one thread indefinetly until the resource is 
> freed.
> Polling with try_lock can bring to a deadlock or to a long freezing if 
> one thread locks the mutex periodically, let's say, every 100 ms for 10 
> ms and the other one looks for the same mutex periodically about every 
> 1200 ms. The probabilty to fall into the locking period is incredibly high.

The fact that a program is deadlock free does not depend on the 
synchronization API but only on the algorithm. If the program deadlocks, 
the program is faulty. You can actually build correctness proofs in 
concurrent computation models to make really sure that your algorithm 
works fine. Never rely on OS timing unless you are modeling a time 
dependent system.



Alex


-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


  reply	other threads:[~2005-01-15 17:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-12 10:53 Luca Pascali
2005-01-12 15:56 ` [Caml-list] " Xavier Leroy
2005-01-12 17:29   ` Luca Pascali
2005-01-15 17:53     ` Alex Baretta [this message]
2005-01-15 17:49 ` Alex Baretta
2005-01-15 19:37   ` Brian Hurt
2005-01-17  8:52     ` Alex Baretta
2005-01-19  3:31       ` Brian Hurt
2005-01-19  9:34         ` Alex Baretta
2005-01-17 12:33   ` Luca Pascali

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41E958B4.3000708@barettadeit.com \
    --to=alex@barettadeit.com \
    --cc=caml-list@inria.fr \
    --cc=luca@barettadeit.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).