DEV Community

sofaki000
sofaki000

Posted on

4 2

Getting started with pthreads

  1. Installing pthreads library
  2. Compiling pthread programs
  3. Pthreads API

Installation

Installing pthreads library on linux:

sudo apt-get install libpthread-stubs0-dev


Compilation

You can compile threaded programms with gnu compiler with the following command:

1)

gcc -pthread file.c

or

2)

gcc -pthread file.c -o thread -lpthread

where:
-lpthread command will tell the compiler to execute the program with pthread.h library.
gcc is the compiler command.
file.c is the name of c program source file.
-o is option to make object file.
thread is the name of object file.


Pthreads API

All identifiers in the threads library begin with pthread_.

Some frequently used methods are:

1) pthread_ = Threads themselves and miscellaneous subroutines
2) pthread_attr_ = Thread attributes objects
3) pthread_mutex_ = Mutexes
4) pthread_mutexattr_ = Mutex attributes objects.

Also the pthread.h header file should be included in each source file using the Pthreads library.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay