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
2 answers

Thread local storage (TLS) - Compiler error

I have declared a variable: static __thread int a; I am getting the following error: fatal error (dcc:1796): __thread not supported in the specified target environment How can I resolve this? Should I enable some flags in make file? I am on…
kp11
  • 2,055
  • 6
  • 22
  • 25
3
votes
3 answers

qt signal/slot and pthreads dont play well together

Can someone tell me why this qt code will not call the Callback when ASYNC_TIMERS is defined (ie m_timer.start is called from the pthread but the slot never runs). Obviously it is to do with being called from a pthread as it works when ASYNC_TIMERS…
othane
  • 143
  • 1
  • 5
3
votes
1 answer

In modern Linux x86-64 is it safe for userspace to overwrite the GS register?

In a 64-bit C program, using glibc, pthreads and so on (nothing exotic), is it safe to overwrite the GS register, without restoring it, on current kernel and glibc versions? I know that the FS register is used by pthreads/glibc for the thread-local…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
3
votes
1 answer

How to Install PHP-Zts manually on the Centos 7

I want to install pthreads. When I'm trying to install I will receive this error: checking for ZTS... no configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled now, how I can install Php with enabled Zts?
Shahrad Elahi
  • 774
  • 12
  • 22
3
votes
2 answers

Comparing Haskell threads to kernel threads - is my benchmark viable?

This one is actually for my university project. In my essay, I need to inlcude evidence that Haskell threads are faster to create than plain kernel threads. I know that it's better to refer to some research paper, but the point is that I have to do…
user500944
3
votes
0 answers

C Pthread taking much longer than single threaded

I've made a matrix multiplier piece of code designed to quantify how much faster threading is for each size of matrix. The code where threads are made and executed is below. I'm new to threading but whenever I use threading it seems to take about 12…
3
votes
1 answer

Is it legal to call pthread functions on thrd_t?

The C11 support to thread is fine but not exaustive. In case I need to use pthread functions, I would like to understand if it is legal to cast thrd_t to pthread_t. For example: #include #define_GNU_SOURCE #include #include…
Giovanni Cerretani
  • 1,693
  • 1
  • 16
  • 30
3
votes
0 answers

Explanation why std::this_thread::sleep_for() sleep time differs between MSVC and MinGW-GCC?

Identifying the Problem I was busy editing a library for lua bindings to rtmidi. I wanted to fix MinGW-GCC and LLVM/Clang compilation compability. When I was done making the edits and compiling the bindings, I noticed a weird timing issue caused by…
Badope
  • 55
  • 3
3
votes
1 answer

Pthread_create fails after creating several threads

I'm developing an application which handles client connections. I'm spawning a thread for each request, since there will be short tasks. However, I keep having a problem after handling a certain amount of connections. Specifically, after 381…
mfontanini
  • 21,410
  • 4
  • 65
  • 73
3
votes
4 answers

c++ correct use of mutex

i have multithreaded project and i've run it through valgrind with --tool=helgrind and it showed me few errors. I'm using mutex there exaxtly how i found on the net how to use it, can you please show me whats wrong? #include #include…
tominko
3
votes
2 answers

Why can't I pass my "for" index directly to a pthread_create call?

#define THREADS_NUMBER 10 Given a function f: void *f(void *arg){ pthread_mutex_lock(&mutex); printf("%i\n", *((int*) arg); pthread_mutex_unlock(&mutex); } I don't understand why writing this: pthread_t…
Axel Carré
  • 303
  • 1
  • 5
3
votes
1 answer

How to create lock at specific location on heap using pthread library?

I am allocating memory using mmap to store some data in set associative manner where I want to access sets concurrently. So, if there are K sets then I am allocating K+1 slots per set where first slot is used for metadata. Here at start of metadata…
3
votes
5 answers

Problem with pThread sync issue

I am facing a sync issue with pthread. threadWaitFunction1, is a thread wait function. I expect line no. 247 flag = 1 to be executed only after 243-246 has finished. But i find it strange that sometimes, it jumps directly to 247 before 243-246 has…
RajSanpui
  • 11,556
  • 32
  • 79
  • 146
3
votes
1 answer

Proper use of MPI_THREAD_SERIALIZED with pthreads

After reading some MPI specs I'm lead to understand that, when initializing with MPI_THREAD_SERIALIZED, a program must ensure that MPI_Send/Recv calls that occur in separate threads must not overlap. In other words, you need a mutex to protect MPI…
Captain Head
  • 333
  • 1
  • 2
  • 9
3
votes
4 answers

C: Undefined symbols for architecture x86_64

I call the function phtread_kill(gpsNavigationThread, 0) and ge the following error Undefined symbols for architecture x86_64: "_phtread_kill", referenced from: _startgpswatchdog in ccXXNhjy.o ld: symbol(s) not found for architecture x86_64 I…
some_id
  • 29,466
  • 62
  • 182
  • 304