Hello,
I'm trying to use cstdatomic (std::atomic in the upcoming c++0x standard) in g++ 4.4, but it doesn't seems to work as expected and I would like to known if I missed something...
My goal in the code below is just to test differents ways of concurrency (mutex vs atomic) : 4 threads increments counters in 3 ways.
1 - with std::mutex : works perfectly but slightly slow (lock / unlock)
2 - with g++ atomics "builtins" : works perfectly
3 - with std::atomic : doesn't works.
here is the code :
#include
#include
#include
int cnt_mutex = 0;
int cnt_builtins = 0;
std::atomic
std::mutex smutex;
/* thread code */
void thrcode(int thrid)
{
/* counter local to thread */
int cnt_local;
for (cnt_local = 0; cnt_local < 10000000; cnt_local++)
{
/* c++0x fetchadd -> FAIL */
cnt_stdatomic.fetch_add(1);
/* g++ builtin fetchadd -> OK */
__sync_fetch_and_add(&cnt_builtins,1);
/* scoped std::mutex : OK */
{
std::unique_lock
cnt_mutex++;
};
};
printf("thread(%d) : cnt_local %dn",thrid,cnt_local);
};
int main() {
/* thread init */
std::thread m1(thrcode,1),m2(thrcode,2),m3(thrcode,3),m4(thrcode,4);
/* wait all thread */
m1.join(); m2.join(); m3.join(); m4.join();
/* display counters */
printf("end : cnt_mutex %d, cnt_builtins %d, cnt_stdatomic %dn",
cnt_mutex,cnt_builtins,(int)cnt_stdatomic);
};
compile with : g++ -std=c++0x mt.cpp -O3 -pthread && date && ./a.out && date
it give :
dimanche 4 octobre 2009, 19:10:28 (UTC+0200) (french time...)
thread(1) : cnt_local 10000000
thread(3) : cnt_local 10000000
thread(4) : cnt_local 10000000
thread(2) : cnt_local 10000000
end : cnt_mutex 40000000, cnt_builtins 40000000, cnt_stdatomic 39990400
dimanche 4 octobre 2009, 19:10:46 (UTC+0200)
cnt_stdatomic counter is incorrect... Someone could tell me where i'm wrong, did i miss something in code ?
(I'm using g++ version 4.4.1 Ubuntu 4.4.1-4ubuntu6)
Thanks !
Error with Font and imagettfbbox
I keep getting an error that says "Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /home/a6079442/public_html/rebuild/includes/csi.php on line 48Error in imagettfbbox
Validation
Hello I know this is a really vag question.I need to have a input field on a form that only submit's if the text inserted starts with any two letters and any four numbers
Echoing If Function?
A script I am using has If statements in the comments form to basically tell the form what to do. Currently the form works by opening in a pop up for those who want to read/write comments. I'm
Join Query Help
Hi all,I am having problems with the below code, which we shall call 'my first join query'! Suprise suprise its not working and I am getting an error I have not seen before:QuoteParse error: parse
email CODING Problem
Email coding problem.I need to send a section of the info to $tf and the same as a Cc to $email and also I need the full info to be sent to my@mail.com. how to do that?summery:only selected Info: name
Oracle11g Patch issue
Hi all,I'm getting the following error while installing Oracle11g Patch 11.1.0.7.0 on IBM-AIX/oracle/Disk1/stage/Components/oracle.owb.rsf/11.1.0.7.0/1/Datafiles/filegroup16.jar.when I look into the
Automatically Detect Phone Model for WAP Jar Deployment
Making a wap site is fairly simple, but I'd like to know if there's a way to make it so that the wap site automatically detects the phone model and deploys the appropriate jar. Deploying the
Parse String
I need to parse the string below into three variables. How would I do that?john + 10/20/2008 - 10/30/2008+ and - are separators
Problems with strings containing
Hey all,I have encountered something strange in a script. I am trying to write an XML header and then fill in the file:Code: $xmlFile = "fetchableData.xml";$fh = fopen($xmlFile,
Quick Syntax Question
Hi folks,I'm getting the following error: "unexpected T_LNUMBER". I'm trying to build a dynamic table in PHP it was working great until I attempted to include a java reference in one of my