From: Loic Domaigne <tech-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
josv-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
Bert Wesarg <bert.wesarg-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>,
Karsten Weiss
<K.Weiss-Pt+Xe7GJXK+P2YhJcF5u+nqWYbMAw+HU@public.gmane.org>
Subject: Re: For review: pthread_cleanup_push.3
Date: Sun, 30 Nov 2008 21:10:24 +0100 [thread overview]
Message-ID: <4932F330.1010603@domaigne.com> (raw)
In-Reply-To: <492C69E6.3030402-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2008-11-30 20:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-14 17:19 For review: pthread_cleanup_push.3 Michael Kerrisk
[not found] ` <cfd18e0f0811140919g11e625a2i8546b3296d008dce-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-22 7:17 ` Loic Domaigne
[not found] ` <4927B203.3000702-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
2008-11-24 22:04 ` Michael Kerrisk
[not found] ` <cfd18e0f0811241404o1415d18bq497ff34b29502263-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-25 21:11 ` Loic Domaigne
[not found] ` <492C69E6.3030402-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
2008-11-30 20:10 ` Loic Domaigne [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4932F330.1010603@domaigne.com \
--to=tech-z4jmkddsf89wk0htik3j/w@public.gmane.org \
--cc=K.Weiss-Pt+Xe7GJXK+P2YhJcF5u+nqWYbMAw+HU@public.gmane.org \
--cc=bert.wesarg-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org \
--cc=josv-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.