Talk:POSIX Threads
From Wikipedia, the free encyclopedia
I thinks pthreads is a better name for this. --129.7.248.159 19:32, 19 Jan 2005 (UTC)
- pthread wins the Google test against pthreads, as does libpthread vs libpthreads. I always call it pthreads myself in programming discussion, but I think 'pthread' is a more appropriate entry. I'll make a pthreads article with a REDIRECT directive, though, as a lot of people do indeed also call it pthreads. --I am not good at running 02:09, 25 Apr 2005 (UTC)
-
- Typically you create an article at the singular and redirect the plural, but this really should be plural:
- Do you write a multi-threaded program with one thread? Nope.
- Intro: "pthread is an abbreviation for POSIX threads..." which naturally leads to pthreads not pthread since it's "POSIX threads".
- I've never cared for the google test, but if you restrict your search to "pthread -pthread.h" and "pthreads -pthread.h" you get 267,000 vs. 275,000, respectively. Cburnett 02:25, Apr 25, 2005 (UTC)
- Typically you create an article at the singular and redirect the plural, but this really should be plural:
Contents |
[edit] AFD result - keep
Robert 03:52, 15 January 2006 (UTC)
[edit] cleanup
I'm cleaning this up; renamed from pthreads to POSIX Threads per AFD. I'm removing the text below as unencyclopedic and probably what prompted the AFD. —Quarl (talk) 2006-01-15 13:13Z
[edit] Code example
pthreads might be used in the following manner to prevent two threads from accessing the same data structure simultaneously:
pthread_cond_t cond_var; pthread_mutex_t mutex_var; int *array; /*both threads will access and modify this array, so we don't want one reading while the other is writing*/ int valid = 1; /* used to test if the data in the array is valid*/ void init() { pthread_cond_init(&cond_var); pthread_mutex_init(&mutex_var); } void thread1() { pthread_mutex_lock(&mutex_var); if(!valid) {/*must check in case the thread is context switched before it gets the mutex*/ /*make the thread wait without blocking the processor*/ pthread_cond_wait(&cond_var, &mutex_var); } valid = 0; /*edit and read from array*/ valid = 1; pthread_mutex_unlock(&mutex_var); pthread_cond_signal(&cond_var); /*tell the other thread to start working*/ } void thread2() { pthread_mutex_lock(&mutex_var); if(!valid) {/*must check in case the thread is context switched before it gets the mutex*/ /*make the thread wait without blocking the processor*/ pthread_cond_wait(&cond_var, &mutex_var); } valid = 0; /*edit and read from array*/ valid = 1; pthread_mutex_unlock(&mutex_var); pthread_cond_signal(&cond_var); /*tell the other thread to start working*/ }
[edit] broken link
[[1]] seems to be boken... someone minds if I remove it or has replacement of it? --DMIax 22:15, 14 February 2006 (UTC)
[edit] pthread_join()
Is there any sense to join second thread ? I guess, machine never reach this code as way as "return 0" (added to make compiler happy). 87.236.11.254 11:38, 19 December 2006 (UTC)
[edit] Pthreads vs. pthreads
There's a claim that "Pthreads is written with an upper-case P" without a citation. I maintain that "pthreads" is much more common than "Pthreads". Does anyone else agree? —75.0.180.18 07:34, 21 February 2007 (UTC)