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 !
PECL uploadprogress for php5.2
Hey, I just installed PHP5 via .htaccess on my 1and1 Shared Hosting Account.How would I exactly install the "PECL uploadprogress"?http://pecl.php.net/package/uploadprogress---There are
Why do I get this error?
Error:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/runevid/public_html/Quests/finished_tutorial.php on line
Passing vars to the DB
I have 3 small testing tables:ID TYPE1 pepperoni2 C. bacon3 tacoID TYPE1 small2 med3 largeID TYPE1 bud2 hef3 mil best4 7up5 orange6 cokeEach one is a select menu. How would I pass these as
Java API in PHP?
I have an application that we use internally here at the office.The software company provides a Java API.Is there a way to use this Java API with PHP?or am i stuck having to use tomcat and jsp to
Snapshot from video
anyone knw how to make a snapshot maker from avi n mkv format.for example if i give a direct link (mysite.com/song.avi) then it will give a snapshot in jpg format
whats wrong with my code please help!!!
this is the errorWarning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/www/IpSearch.php on line Code: <?php$srch = $_REQUEST["srch"];if (empty($srch)) {
Rounding a number queried from a database
I know that to display a rounded number you just do echo "round($number)";. But how would I convert the $number varible into a rounded number, so that when I say echo "$number";
Not capturing all the information we require in the form.......
Hi Guys,I was wondering if you would share some more of your knowledge today, I'm hoping it will be quite a simple answer for you but one that is boggling us here! ;-)We have an html form that users
Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to another and whoever they have subscribed to is echoed back on there profile page. my users table
Menu restriction
How can I restrict the individual menu that would appear when a user logs in so that all users are confined to the transactions for which they have authorizations only as this also helps at a glance