Re: For review: pthread_cleanup_push.3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gidday Michael,

IIRC, I had an issue left:

I see a major deficiency in your code. Unless I am mistaken, the global
variable <done> and <cleanup_pop_arg> are accessed from two different
threads.

True.

Following the POSIX memory model, you need mutex to synchronize the
visibility.

Please educate me about the POSIX memory model ;-).  Say some more
here please.  Are you meaning that the change made in main are not
guaranteed to visible in the other thread, unless I use a
synchronization mechanism?  (or, perhaps, a barrier?)

Oh, that's a long story. Tomorrow perhaps (I just came home, and I guess Antje would like to spend some time with me...)

Please refer to St Butenhof's bible "Programming with POSIX Threads", §3.4, pp88-95.

An excerpt can be found at:
http://markmail.org/message/24zdwjjkbe4dqz5o

Basically:

1) the values you write prior to pthread_create(3) can be seen in the new thread.

2) the values you write prior to mutex_unlock(3) can be seen in any thread that locks later the same mutex.

3) the values you write prior to terminating a thread can be seen in the thread that joins.

4) the values you write prior to pthread_cond_{signal,broadcast}(3) can be seen by any thread that is awakened.

Failing to comply these rules may cause your program to fail in very subtle ways on multi-processors machine. Even if I may save here and there a mutex; I apply those rules religiously (but, yeah, I am a Pthreads fanatic ;-)

HTH,
Loïc.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux