Introduction to Multi-Threaded Programming
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Validate an E-Mail Address with PHP, the Right Way
- Technical Support Rep
- Senior Perl Developer
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Introduction to MapReduce with Hadoop on Linux
- Cari Uang
36 min 22 sec ago - user namespaces
3 hours 29 min ago - yea
3 hours 55 min ago - One advantage with VMs
6 hours 24 min ago - about info
6 hours 57 min ago - info
6 hours 58 min ago - info
6 hours 59 min ago - info
7 hours 1 min ago - info
7 hours 2 min ago - abut info
7 hours 4 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
there are errors when linking
shindow@shindow-laptop:~/code$ gcc thread.c -o thread
/tmp/ccXY7Wqj.o: In function `main':
thread.c:(.text+0x40): undefined reference to `pthread_create'
thread.c:(.text+0x6e): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
i check it at :http://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux-c-programming
so gcc -pthread thread.c -o thread is correct
Excellent
Hi,
First of all thanks for this tutorial. Its simple and very clear.
All mistakes in the sample example were already mentioned by others :)
Even I used
while(1) {
pthread_mutex_lock(&count_mutex);
if(x == 4000) {
pthread_mutex_unlock(&count_mutex);
pthread_exit(NULL);
return;
}
x++;
printf("Thread ID%ld: X is now %d.\n",
pthread_self(), x);
pthread_mutex_unlock(&count_mutex);
}
which will ensure x value to be 4000. See I got it from your tutorial :D.
Thanks again.
Just Add
The follow link is a interesting guide:
https://computing.llnl.gov/tutorials/pthreads/
Tcp Client and Server
How would you create a tcp server and client, whereby the server wants to be able to see any move made by the client and vice versa?[c-sharp]
Did the first commenter
Did the first commenter seriously use goto? GTFO and learn to program.
Accessing the variable "x"
Accessing the variable "x" outside the mutexed area is not really a good idea.
I would rather have used something like this:
void *mythread(void *data) { start: pthread_mutex_lock(&count_mutex); if (x < 4000) { x++; printf("Thread ID%ld: X is now %d.\n", pthread_self(), x); pthread_mutex_unlock(&count_mutex); goto start; } else { pthread_mutex_unlock(&count_mutex); } pthread_exit(NULL); }This is one of the rare cases where a "goto" is useful ;-)
Thanks for the tutorial.
Restructuring the increment loop
How about this?
bool run=true;
while(run) {
pthread_mutex_lock(&count_mutex);
if(run=(x<4000) x++;
printf("Thread ID%ld: X is now %d.\n",
pthread_self(), x);
pthread_mutex_unlock(&count_mutex);
}
I think changing the
I think changing the increment line to
if (x < 4000) {x++};
would be better, otherwise the count goes higher than 4000 as the while check is outside the mutex. Otherwise, thanks for the example, it was very clear.
code analyzer for multi threaded programming
Errors in multi threaded application programming like Thread block, Dead lock and Race conditions can also be solved using static tools. Companies like Symbian , Juniper networks ,Research in Motion(Blackberry),Cisco are using Coverity Prevent, a Static analysis code inspection tool for analyzing source code for fixing defects. Coverity Prevent is also used by the Department of Homeland security to scan many open source projects. you can get more info at at http://www.Coverity.com
LinuxThreads and NPTL
Perhaps you would like to revisit
http://pauillac.inria.fr/~xleroy/linuxthreads/
It's stated that "LinuxThreads is now obsolete and is being replaced by NPTL."
Thank you for the introduction.
pthreads is not obsolete.
pthreads is not obsolete. it's just the implemention in glibc and kernel.
Excellent
This is my first MT program, this tutorial gave me a clear idea..wonderful..!!
ThanX a lot..!!
Yes
The article helped me to understand.
Thanks...
Compile error with the source code
I think this line :
pthread_t tid[10];
Should be changed into :
pthread_t tids[10];
Because code uses "tids" instead of "tid" ... a small syntax error.
Thank you for the tutorial it helped a lot.
The sample code is buggy
Thanks for the tutorial,
I tried the sample code provided in this article. After a small change of the variable name tid to tids, I compiled the program with no errors. However, the result was not what I was expecting .Actually the variable X goes up to 4009 not the expected value 4000. I think it might be because the lock is inside the while loop..further stop condition should be implemented after the thread got the mutex.
thanks
Re: Introduction to Multi-Threaded Programming
Probably should have covered condition variables.
Re: Introduction to Multi-Threaded Programming
i need some more examples programmes for threads.could u send to my id?.my id is " panusuyadevi@yahoo.co.in "
thanku
Re: Introduction to Multi-Threaded Programming
IT is a wonderfull sample...
I would like to know more about pthreads..
could pls assist me where i could get more information and samples --Jai
Re: Introduction to Multi-Threaded Programming
IT is a wonderfull sample...
I would like to know more about pthreads..
could pls assist me where i could get more information and samples
Re: Introduction to Multi-Threaded Programming
Wonderfully written. Convered all the basic issues with MT programming in just a page.
Re: Introduction to Multi-Threaded Programming
Very well written. Simple yet precise.