Afficher un message
Vieux 16/10/2007, 08h58   #8
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Basic Question on POSIX Threads

On Oct 15, 3:58 pm, "Laurent D.A.M. MENTEN"
<laurent.men...@teledisnet.be> wrote:
> > You're right about the race condition, of course, and I doubt
> > that his code would work on a modern system (dual core or more).
> > But it won't even compile with a conformant C++ compiler. His
> > function glue must be `extern "C"', and thus cannot be a member.
> > (On the other hand, it *can* be static, in order to avoid all
> > risk of name collision.)


> Anyway, it does compile (gcc 3.3.5 + linux 2.6.11 + x86_64)


This is a known bug in g++, which will presumably be fixed in a
future release. At which point, your code will stop compiling.

[...]
> It is a shame so many people here are not able to understand not
> everyone in this world is a C++ guru or theorician.


It's a shame so many people don't care about writing correct
code. Gianni pointed out the fact that your code simply isn't
correct from a threading point point of view. (His point was in
fact considerably more important than mine.) Your code doesn't
work reliably under Windows, Linux or Solaris. I don't know
about other systems, but I'm pretty sure that it doesn't work
under any Posix system. Gianni also pointed out a workable
solution---I personally find using the strategy pattern simpler
for non-detached threads, but his solution also works in that
case as well.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

  Réponse avec citation
 
Page generated in 0,05595 seconds with 9 queries