Questions tagged [pthreads]

Pthreads (POSIX Threads) is a standardised C-based API for creating and manipulating threads. It is currently defined by POSIX.1-2008 (IEEE Std 1003.1, 2013 Edition / The Open Group Base Specifications Issue 7).

The API is mostly covered by the header documented at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html and the behaviour by http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09

See https://en.wikipedia.org/wiki/POSIX_Threads for more details and further reading. The POSIX.1-2008 Base Definitions is available online at http://pubs.opengroup.org/onlinepubs/9699919799/

POSIX Threads is also covered extensively in Programming with POSIX Threads by David Butenhof.

A port to MS-Windows (x86/x64) is available at: https://sourceware.org/pthreads-win32/

pthreads is also the name of an Object Oriented API that allows user-land multi-threading in PHP created by Joe Watkins

8869 questions
3
votes
1 answer

pthread mutex not unlocking on wait

I'm using c posix threads, and i've encountered a problem I don't quite understand and would like some fresh eyes to see what the problem could be. In summary, I'm creating 3 threads which check some program state, signal that they are ready, and…
Riglerr
  • 31
  • 2
3
votes
0 answers

Data race with detached pthread detected by valgrind

I am creating two detached pthread: pthread_attr_t tha1; void* fun1(void*){ return 0; } void* fun2(void*){ return 0; } int main(){ pthread_t th1, th2; pthread_attr_init(&tha1); pthread_attr_setdetachstate(&tha1,…
Jahid
  • 21,542
  • 10
  • 90
  • 108
3
votes
2 answers

PHP Pthread - Couldn't fetch DOMDocument

I am trying to code php threads. I'm creating a DOMDocument in the constructor but for some reason the newly created document, although assigned to a member variable, disappears. Code-listing 1: class workerThread extends Thread { …
Paiku Han
  • 581
  • 2
  • 16
  • 38
3
votes
3 answers

Asynchronous I/O reading from a file

I've gotten ideas for multiple projects recently that all involve reading IP addresses from a file. Since they are all supposed to be able to handle a large amount of hosts, I've attempted to implement multi-threading or creating a pool of sockets…
user3408678
  • 155
  • 4
  • 17
3
votes
2 answers

Difference between pthread_cond_signal before and after pthread_mutex_unlock

I am trying to implement a concurrent queue, and skeleton of implementation is as following: struct queue { int try_pop() { pthread_mutex_lock(&mutex_); int rt; while( (rt = do_pop()) == -1) { …
g-217
  • 2,069
  • 18
  • 33
3
votes
1 answer

Multithreading in PHP 7

How to do multithreading in PHP7? The first problem I see with pthread is coming directly from PHP manual. https://secure.php.net/manual/en/intro.pthreads.php The pthreads extension cannot be used in a web server environment. Threading in PHP…
Amr Eladawy
  • 4,193
  • 7
  • 34
  • 52
3
votes
1 answer

Is there a way to link a linux's thread TID and a pthread_t "thread ID"

On linux a thread is identified by a pthread_t or a TID. I'm looking for bridges between these two kinds of thread ids: given a pthread_t can I get it's TID ? apparently not without hacking in pthread's internals :( but i'm still asking in case…
Antoine
  • 13,494
  • 6
  • 40
  • 52
3
votes
1 answer

gcc arguments: -pthread. What does it do?

I'm getting started with multi-thread programming using gcc under Debian 8. I've successfully written and run a multi-threaded test app (foobar.c), but I'm confused by the Makefile (copied from an example). In particular, the command that works is …
DontPanic
  • 2,164
  • 5
  • 29
  • 56
3
votes
1 answer

Measuring speed up of a multi threaded C program (implementation using Pthreads)

I currently have a multi-threaded C program coded using Pthreads which uses 2 threads. I want to increase the no. of threads and measure speed up upon doing so. I would like to run my code in an automated manner where the no. of threads used keeps…
Abhijeet Mohanty
  • 334
  • 1
  • 6
  • 21
3
votes
1 answer

Async/Thread on PHP7 with FPM

I found that pthreads does not work on web environment. I use PHP7.1 on FPM on Linux Debian which i also use Symfony 3.2. All I want to do is, for example: User made a request and PUT a file (which is 1GB) PHP Server receives the file and process…
xangr
  • 879
  • 14
  • 28
3
votes
3 answers

Thread Context Switching

I am working on a C/C++ project which involves a UI and a background service which does some heavy processing by fetching data over the network. In order that my UI doesn't become unresponsive, I would want to spawn a separate thread and then call…
Alok Save
  • 202,538
  • 53
  • 430
  • 533
3
votes
2 answers

Using Pool class in PHP7 pthreads extension

I took the most basic demo of pthreads PHP7 extension that uses Pool class (this demo https://github.com/krakjoe/pthreads#polyfill) and extended it a little so I can grab results from the thread (or at least I think I can): $pool = new…
martin
  • 93,354
  • 25
  • 191
  • 226
3
votes
1 answer

I want to program in parallel in C, should i avoid to use pthread_join()?

i would like to create multiple threads and launch it at the same time they are created, for the code to goes the fastest possible i tried to do this : for (i = 1; i < nbClients+1; i++) { pthread_create(&tClient, NULL, procedureClient, &i); …
Henley n
  • 3,593
  • 2
  • 10
  • 13
3
votes
1 answer

C Printf not printing inside of a thread?

Now this is just a little test, and part of a school assignment. In my code printf is not printing at least to me being able to see it. Is this a result of the thread not functioning? The print line works outside of the thread. Thank you for any…
TheMangaStand
  • 193
  • 3
  • 13
3
votes
5 answers

Error : cannot initialize a variable of type 'int' with an lvalue of type 'void'

I am trying pthread example. Here is my code: #include #include #include void*AsalK1(void *gelen); int main(){ int *i; i= new int; *i=1; int sonSayi; pthread_t th1, th2, th3, th4; …
Nurullah
  • 103
  • 3
  • 4
  • 14