Discussion:
Linux C++ equivalent to InterlockedIncrement?
(too old to reply)
p***@workinghard.com
2008-12-19 20:19:27 UTC
Permalink
We have a formerly Windows program that uses InterlockedIncrement.

## InterlockedIncrement Function
##
## Increments (increases by one) the value of the specified 32-bit
## variable as an atomic operation.

We are porting that program to Linux and would like to know the
fastest way of performing the same operation without heavyweight
objects like mutexes being involved.

Google searches reveal some assembly language instructions, but we do
not want to use assembly, preferably it should be a function from
glibc.
Victor Bazarov
2008-12-19 20:25:55 UTC
Permalink
Post by p***@workinghard.com
We have a formerly Windows program that uses InterlockedIncrement.
## InterlockedIncrement Function
##
## Increments (increases by one) the value of the specified 32-bit
## variable as an atomic operation.
We are porting that program to Linux and would like to know the
fastest way of performing the same operation without heavyweight
objects like mutexes being involved.
Google searches reveal some assembly language instructions, but we do
not want to use assembly, preferably it should be a function from
glibc.
Uh... What's your C++ language question? I believe with your inquiry
you need to visit 'comp.os.linux.development.apps' or some such.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
A***@gmail.com
2008-12-19 21:57:13 UTC
Permalink
Post by p***@workinghard.com
We have a formerly Windows program that uses InterlockedIncrement.
## InterlockedIncrement Function
##
## Increments (increases by one) the value of the specified 32-bit
## variable as an atomic operation.
We are porting that program to Linux and would like to know the
fastest way of performing the same operation without heavyweight
objects like mutexes being involved.
Google searches reveal some assembly language instructions, but we do
not want to use assembly, preferably it should be a function from
glibc.
A quick search indicates that there are functions for kernal use but
not for user application use.

I suggest looking at how boost does atomic integer increment/decrement
for your particular platform. Either use that or implement something
similar.

HTH
Paavo Helde
2008-12-19 23:19:46 UTC
Permalink
Post by p***@workinghard.com
We have a formerly Windows program that uses InterlockedIncrement.
## InterlockedIncrement Function
##
## Increments (increases by one) the value of the specified 32-bit
## variable as an atomic operation.
We are porting that program to Linux and would like to know the
fastest way of performing the same operation without heavyweight
objects like mutexes being involved.
Google searches reveal some assembly language instructions, but we do
not want to use assembly, preferably it should be a function from
glibc.
The heavyweightness mostly depends on the cpu architecture, not on the
exact function used. On multicore machines InterlockedIncrement might also
have to sunchronize all cores, so it becomes heavyweight by itself.

I think there were some gnu extensions for atomic increments; ask in some
gcc group or search for 'atomic gcc'.

Paavo
Lance Diduck
2008-12-20 18:14:47 UTC
Permalink
Post by p***@workinghard.com
We have a formerly Windows program that uses InterlockedIncrement.
## InterlockedIncrement Function
##
## Increments (increases by one) the value of the specified 32-bit
## variable as an atomic operation.
We are porting that program to Linux and would like to know the
fastest way of performing the same operation without heavyweight
objects like mutexes being involved.
Google searches reveal some assembly language instructions, but we do
not want to use assembly, preferably it should be a function from
glibc.
__sync_fetch_and_add

Loading...