how do insert lock instruction befofre incrementation?
lock c++, something like that.
lock c++
Started by
Guest_h4x_*
, Sep 10 2009 04:04 AM
5 replies to this topic
#1
Guest_h4x_*
Posted 10 September 2009 - 04:04 AM
Guest_h4x_*
|
|
|
#2
Posted 10 September 2009 - 07:36 AM
lock isn't a keyword in C/C++. Are you trying to apply an ASM concept?
#3
Guest_h4x_*
Posted 10 September 2009 - 10:12 PM
Guest_h4x_*
i am trying to increment 4 bytes using multiple threads.
so whats the c construction for lock?
so whats the c construction for lock?
#4
Posted 11 September 2009 - 04:24 AM
The thread library you're using should provide some sort of mutex construction. Look at the documentation to see. Are you using pthreads or Windows API to create your threads? I can help you with either.
As far as the C construction for lock, there is none unless you're absolutely sure that your program will run only on Intel processors. In this case you'll have to write your increment instruction entirely in ASM, but that depends on the compiler. On a Microsoft compiler you can do this:
I forget the exact syntax for GNU GCC, but it's something like:
Also, make sure you declare that variable as volatile.
As far as the C construction for lock, there is none unless you're absolutely sure that your program will run only on Intel processors. In this case you'll have to write your increment instruction entirely in ASM, but that depends on the compiler. On a Microsoft compiler you can do this:
//32-bit processors only __asm lock inc myvar; //32- and 64-bit processors __asm lock add myvar,1;
I forget the exact syntax for GNU GCC, but it's something like:
asm("lock add myvar,1;","","");
Don't quote me on that.Also, make sure you declare that variable as volatile.
Edited by dargueta, 11 September 2009 - 04:26 AM.
Fixed formatting
sudo rm -rf /
#5
Guest_h4x_*
Posted 11 September 2009 - 04:46 AM
Guest_h4x_*
Ok nvm, for me c is an inferior language wich i use only when im too tired to write in asm, such details as atomic access do not concern me.
#6
Posted 11 September 2009 - 05:33 AM


Sign In
Create Account

Back to top









