Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
shared memory synchronization across processes using futexes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Avik Ghosh  
View profile  
 More options Sep 2 2010, 9:56 pm
Newsgroups: comp.programming.threads
From: Avik Ghosh <avik.gh...@gmail.com>
Date: Thu, 2 Sep 2010 18:56:33 -0700 (PDT)
Local: Thurs, Sep 2 2010 9:56 pm
Subject: shared memory synchronization across processes using futexes
Hello all,

If I have two or more unrelated processes (not threads, and not forked
from a single process) in a multiprocessor environment, can I depend
on a futex to provide synchronization ? (the futex would be in shared
memory mapped by all the processes)  I have not used futexes before,
but it seems that the not-contended case is solely in user space.

What should I do to ensure that the writes to shared memory by a
process are visible by another process, possibly running on a
different processor ?

Avik.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Terekhov  
View profile  
 More options Sep 3 2010, 8:10 am
Newsgroups: comp.programming.threads
From: Alexander Terekhov <terek...@web.de>
Date: Fri, 03 Sep 2010 14:10:21 +0200
Local: Fri, Sep 3 2010 8:10 am
Subject: Re: shared memory synchronization across processes using futexes

Avik Ghosh wrote:

> Hello all,

> If I have two or more unrelated processes (not threads, and not forked
> from a single process) in a multiprocessor environment, can I depend
> on a futex to provide synchronization ? (the futex would be in shared
> memory mapped by all the processes)  I have not used futexes before,
> but it seems that the not-contended case is solely in user space.

> What should I do to ensure that the writes to shared memory by a
> process are visible by another process, possibly running on a
> different processor ?

Futex interface shall be used on top of something along the lines of the
upcoming std::atomic<> and it's C incarnation ala

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1349.htm

See also

http://www.cl.cam.ac.uk/~pes20/cpp/tech.pdf

regards,
alexander.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Avik Ghosh  
View profile  
 More options Sep 3 2010, 11:48 am
Newsgroups: comp.programming.threads
From: Avik Ghosh <avik.gh...@gmail.com>
Date: Fri, 3 Sep 2010 08:48:01 -0700 (PDT)
Local: Fri, Sep 3 2010 11:48 am
Subject: Re: shared memory synchronization across processes using futexes
On Sep 3, 8:10 am, Alexander Terekhov <terek...@web.de> wrote:

Thanks, (this will take me a while to digest!)

Does this mean that for now the simplest way for me to synchronize
shared memory across processes (not threads) is via semaphores?

Avik.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Terekhov  
View profile  
 More options Sep 3 2010, 12:14 pm
Newsgroups: comp.programming.threads
From: Alexander Terekhov <terek...@web.de>
Date: Fri, 03 Sep 2010 18:14:03 +0200
Local: Fri, Sep 3 2010 12:14 pm
Subject: Re: shared memory synchronization across processes using futexes

Avik Ghosh wrote:

[...]

> Does this mean that for now the simplest way for me to synchronize
> shared memory across processes (not threads) is via semaphores?

You can use futex interface (lock_queue_wait() and lock_queue_wake())
along the line of

sema_lock:

  WHILE // CAS/LL-SC
    !atomic_decrement_if_binand_7FFFFFFF_is_not_zero_ccacq(&lock)
      lock_queue_wait(&lock, 0) // wait if sem.value is zero

sema_unlock:

  uintptr_t lock_queue;
  IF atomic_increment_rel(lock_queue = &lock) > 0x80000000
    THEN lock_queue_wake(lock_queue, 1)

(try/timed operations omitted for brevity)

BTW, fast mutex:

mutex_lock:

  WHILE
    atomic_bit_test_set_ccacq(&lock, 1)
      lock_queue_wait(&lock, 1) // wait if locked bit is set

mutex_unlock:

  uintptr_t lock_queue;
  IF atomic_decrement_rel(lock_queue = &lock)
    THEN lock_queue_wake(lock_queue, 1)

"ccacq" stands for acquire-but-with-"control condition"-hint
(to avoid redundant memory barrier(s) -- arch specific stuff).

"rel" is a classic release.

regards,
alexander.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Schwartz  
View profile  
 More options Sep 5 2010, 12:48 am
Newsgroups: comp.programming.threads
From: David Schwartz <dav...@webmaster.com>
Date: Sat, 4 Sep 2010 21:48:01 -0700 (PDT)
Local: Sun, Sep 5 2010 12:48 am
Subject: Re: shared memory synchronization across processes using futexes
On Sep 2, 6:56 pm, Avik Ghosh <avik.gh...@gmail.com> wrote:

> If I have two or more unrelated processes (not threads, and not forked
> from a single process) in a multiprocessor environment, can I depend
> on a futex to provide synchronization ? (the futex would be in shared
> memory mapped by all the processes)  I have not used futexes before,
> but it seems that the not-contended case is solely in user space.

> What should I do to ensure that the writes to shared memory by a
> process are visible by another process, possibly running on a
> different processor ?

You can, but why not use a portable interface that will use futexes
where they're known to work anyway? (Specifically, POSIX process
shared mutexes.)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Avik Ghosh  
View profile  
 More options Sep 5 2010, 5:34 am
Newsgroups: comp.programming.threads
From: Avik Ghosh <avik.gh...@gmail.com>
Date: Sun, 5 Sep 2010 02:34:30 -0700 (PDT)
Local: Sun, Sep 5 2010 5:34 am
Subject: Re: shared memory synchronization across processes using futexes
On Sep 5, 12:48 am, David Schwartz <dav...@webmaster.com> wrote:

> On Sep 2, 6:56 pm, Avik Ghosh <avik.gh...@gmail.com> wrote:

> > If I have two or more unrelated processes (not threads, and not forked
> > from a single process) in a multiprocessor environment, can I depend
> > on a futex to provide synchronization ? (the futex would be in shared
> > memory mapped by all the processes)  I have not used futexes before,
> > but it seems that the not-contended case is solely in user space.

> > What should I do to ensure that the writes to shared memory by a
> > process are visible by another process, possibly running on a
> > different processor ?

> You can, but why not use a portable interface that will use futexes
> where they're known to work anyway? (Specifically, POSIX process
> shared mutexes.)

Yes, I think that is what I will do.

So far I have only used pthread_mutex calls in threads (created using
pthread_create) where the address space is shared. I now gather that I
can use them in dissimilar processes, as long as the pthread_mutex
object is created on shared memory.

Thanks for all the help guys,

Avik.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »