Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » synchronized statement in C++

This thread is locked; no one can reply to it. rss feed Print
synchronized statement in C++
axilmar
Member #1,204
April 2001

Here is a little article I wrote about how to do a synchronized statement in C++ that works in a similar way to Java. It's not very important, nor does it relate to games or Allegro, but I think it is cool :). Enjoy.

kazzmir
Member #1,786
December 2001
avatar

Thats kind of fun. I dont do a whole lot of multithreaded C++ work anymore but if I ever do I will surely use this.

A J
Member #3,025
December 2002
avatar

thats a nice trick, pity it doesn't scale well.

___________________________
The more you talk, the more AJ is right. - ML

vpenquerch
Member #233
April 2000

Ah, yes, in my ideal world, etc, etc.

But, hey, Rome wasn't built in a day.

Nice one, Axilmar.

HoHo
Member #4,534
April 2004
avatar

Besodes scaling it also seems to lack portability

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

A J
Member #3,025
December 2002
avatar

why would you start 2 of the same threads anyway ?

___________________________
The more you talk, the more AJ is right. - ML

gillius
Member #119
April 2000

Using RAII for mutexes should compile out to be the same code anyway. There's not a problem with it, in fact I use this idiom a lot. I don't understand the purpose of the flag attached to the mutex, though. Even if there was some overhead (I seriously expect there to be completely 0 overhead), I'd still use it since it is exception and return safe, and it is infinitely more convenient. I wouldn't go through the extras to make it look like Java. You can still do it in 1 line of code without the macro and it will look like normal C++.

Gillius
Gillius's Programming -- https://gillius.org/

Go to: