tag:blogger.com,1999:blog-7764126179108633515.post4538232776422440397..comments2023-11-26T05:25:06.785+03:00Comments on Ilya Martynov's blog: volatile and threadingIlya Martynovhttp://www.blogger.com/profile/03019237563335985484noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-7764126179108633515.post-20228370915220461512022-12-07T09:02:20.427+03:002022-12-07T09:02:20.427+03:00You never understand how much time and money you n...You never understand how much time and money you need to|you should|you have to} make investments to hit a lucky spin and celebrate yet another <a href="https://로스트아크.com/1xbet-korea.html" rel="nofollow">1xbet korea</a> day of winning cash on slots. When we talk about free slots we do not imply that these are games where you get higher chances to win cash. Simply put, these are games with an RTP that is above 96%.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-20562983176074641862022-02-05T10:51:38.621+03:002022-02-05T10:51:38.621+03:00Coin Casino Review 2021 » Free Spins, Bonuses &...Coin Casino Review 2021 » Free Spins, Bonuses & Games<br />Coin Casino Review 2021 ➤ Read about the ✓High Payouts ✔️ Welcome Bonus ✔️ Fast Payments <a href="https://casinowed.com/coin-casino/" rel="nofollow">코인카지노 조작</a> ✔️ Games & Slots ❱ Get More Info!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-22085106965698607802008-10-08T11:38:00.000+04:002008-10-08T11:38:00.000+04:00@Ilya: With all my respect to Andrei I should say ...@Ilya: With all my respect to Andrei I should say that article which you cited above http://www.ddj.com/cpp/184403766 is somewhat out of touch with reality.<BR/><BR/>Good post!Andrew Selivanovhttps://www.blogger.com/profile/11416362711326329087noreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-52340135462045844362007-08-12T17:17:00.000+04:002007-08-12T17:17:00.000+04:00You may also find this video of Hans Boehm interes...You may also find this video of Hans Boehm interesting:<BR/><BR/>http://irbseminars.intel-research.net/<BR/><BR/>(first one on the page). <BR/><BR/>He discusses the ins and outs of designing the C++ memory model for the next revision of the standard and illustrates some of the scarier optimisations that are valid in the single threaded world but that break multi-threaded code. The volatile issue is also touched upon briefly, IIRC.<BR/><BR/>I too, should have said: good post :)<BR/><BR/>EddUnknownhttps://www.blogger.com/profile/02611938658562785090noreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-33151242484423742062007-08-12T06:35:00.000+04:002007-08-12T06:35:00.000+04:00@ilya: Global state with a primitive ad-hoc sync m...@ilya: Global state with a primitive ad-hoc sync mechanism like this is not a good idea, even if you can avoid the compiler-generated-deadlock using volatile, I'm still not even sure if that gives you any sort of guarantees at a lower level (as the instruction pipeline will do out-of-order execution as it sees fit.) I suppose calling it 'bad practice' is simply my opinion. <BR/><BR/>Along with this, using a mutex to lock has the advantage that your system will put the thread to sleep rather than idly wasting CPU cycles and taking up time from the scheduler, and it will awake it appropriately when the kernel object related to the mutex is 'open.'<BR/><BR/>I've seen code like it too (like I said, I did it too a long time ago,) and I will stand on my own if necessary when I say it is an incredibly poor method to acheive what is so graciously provided as a system construct.<BR/><BR/>Also, I forgot to mention in my first comment: good post. :)Austin Seipphttps://www.blogger.com/profile/08003235138924772402noreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-42117519019909327252007-08-12T04:53:00.000+04:002007-08-12T04:53:00.000+04:00assuming your scoped_locks are supposed to be cons...<I>assuming your scoped_locks are supposed to be constructed with gMutex as an argument</I><BR/><BR/>Yep, I've just corrected this. Thanks.<BR/><BR/><I>Your code as it stands looks like it will deadlock.</I><BR/><BR/>Right, I didn't realize this. I've fixed this too.<BR/><BR/><I>You should really be using boost::condition for this kind of thing.</I><BR/><BR/>Agree. After I fixed the deadlock the code looks less elegant then it would if I were using boost::condition.<BR/><BR/><I>Using volatile (only) for synchronisation is a bad</I><BR/><BR/>This is what some of papers on this topic say. Yet, there are examples online which show basically the same code as in my blog post. See for example <A HREF="http://www.ddj.com/cpp/184403766" REL="nofollow"><BR/>http://www.ddj.com/cpp/184403766</A>. It is written by C++ guru Andrei Alexandrescu who I'd suppose knows what he is talking about. Anyway I agree unless you know what you are doing (in this case I don't) it is safer to just use standard thread synchronization primitives like mutexes.Ilya Martynovhttps://www.blogger.com/profile/03019237563335985484noreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-42737235275230954142007-08-12T02:34:00.000+04:002007-08-12T02:34:00.000+04:00You should really be using boost::condition for th...You should really be using boost::condition for this kind of thing. <BR/><BR/>Your code as it stands looks like it will deadlock (assuming your scoped_locks are supposed to be constructed with gMutex as an argument).<BR/><BR/>Using volatile (only) for synchronisation is a bad idea because even though it stops the compiler re-ordering operations, it does not stop the processor from doing so; the barrier operations injected by the pthreads calls really are needed.Unknownhttps://www.blogger.com/profile/02611938658562785090noreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-36084203281128819612007-08-11T20:55:00.000+04:002007-08-11T20:55:00.000+04:00austin, could you elaborate "Obviously synchronizi...austin, could you elaborate <I>"Obviously synchronizing like that is an incredibly bad practice anyway"</I>? The code in my blog post is made up but it does resemble some simple examples of threaded programs one can find elsewhere on web so I'm curious what exactly you think is a <I>"bad practice"</I>?Ilya Martynovhttps://www.blogger.com/profile/03019237563335985484noreply@blogger.comtag:blogger.com,1999:blog-7764126179108633515.post-52057392803009553952007-08-11T20:13:00.000+04:002007-08-11T20:13:00.000+04:00I picked up the note on volatile in this instance ...I picked up the note on volatile in this instance long ago when I first read "Programming Applications for Microsoft Windows" by J. Richter.<BR/>Obviously synchronizing like that is an incredibly bad practice anyway (I did it a time or two myself before I read Richter's book) and it should be somewhat self evident, so you're asking to get bitten in the ass one way or another if you trust such a route. :) And locks are ugly in themselves although they solve the problem to their own extent (although you still may get an ass-biting if you're not careful.)Austin Seipphttps://www.blogger.com/profile/08003235138924772402noreply@blogger.com