Questions tagged [pthread-key-create]
13 questions
10
votes
1 answer
How does pthread_key_t and the method pthread_key_create work?
I am having some trouble figuring out how pthread_key_t and pthread_key_create work. From my understand, each thread has TLS (thread local storage) and that a key is used to access the thread local storage. What I do not get is when a key is…

user972276
- 2,973
- 9
- 33
- 46
4
votes
1 answer
Destruction order of the main thread and the use of pthread_key_create
I was wondering about the use of pthread_key_create while passing in a destructor function.
I wanted to have something like this:
static ComplexObject foo;
void workoncomplex(void *) {
foo.dosomestuff();
}
static pthread_key_t…

Salgar
- 7,687
- 1
- 25
- 39
3
votes
1 answer
How to use Thread-specific data correctly
I am programming using pthread. I need a global variable that it has different value for different threads. And threads will use same function to deal with this variable, such as change its value. If one thread change its value, the value in other…

Nick Dong
- 3,638
- 8
- 47
- 84
2
votes
2 answers
What happens if pthread_key_delete is called on a key after a failed pthread_key_create?
Suppose the following code:
pthread_key_t key;
pthread_key_create(&key, NULL); /* failure here */
pthread_key_delete(key);
If pthread_key_create fails, is the call to pthread_key_delete considered undefined behavior? How about if…

Vilhelm Gray
- 11,516
- 10
- 61
- 114
2
votes
1 answer
I've not understood the reason in use of pthread_key_create, can you tell why?
We can pass argument to a thread when using pthread_create /(not key_), if it is over using value per thread. If about using static storage, we use mutexes, so, what is it saying we use pthread_key_create? With example & emphasize on why it is born…

user683595
- 397
- 1
- 3
- 10
0
votes
3 answers
Thread-specific data
I have a client program as follows and I need to make it multithreaded i.e one thread per connection. But the variable sockfd is to be kept global to one thread. I understand to do this I need to use pthread_key_t, pthread_key_create...etc. But, I…

Lipika Deka
- 3,774
- 6
- 43
- 56
0
votes
1 answer
pthread does not see instance variable passed as argument
I have a class in C++ that uses boost python. I am trying to run python code in a thread from C++ using pthread. The problem is that the code below isn't producing any output. I was expecting an output John DOE in stdout. It seems that…

pseudo
- 385
- 2
- 19
0
votes
1 answer
C, pthreads initialized in loop does not execute assigned function properly despite mutex
I am having trouble debugging my C program where the goal is to create 5 threads and have each of them working on size-2 chunks of an array of length 10. The goal is to get the sum of that array. My actual program is a little less trivial than this…

vgbcell
- 189
- 1
- 2
- 14
0
votes
1 answer
single thread and multiple thread
Would anyone know a way of explaining or could you direct me to some material regarding single Thread and multiple thread? I don't understand them at all. Every explanation I read is in very complicated English.
I want to understand them completely.…

Rajkumar
- 11
- 1
0
votes
0 answers
Segmentation fault during pthread_create()
Okay so I'm trying to bubble sort two files in a separate threads(main thread and the secondary thread in which I created using pthread_create). My bubble sort works perfectly, I tested it several times so I didn't included here, my problem it is…

user3757928
- 57
- 4
0
votes
2 answers
In C, when using the name of the function in pthread_create is it the same as using a reference?
I'm not sure if I said it right.
pthread_create(..., ..., &some, ...);
...is the same as:
pthread_create(..., ..., some, ...);
I'm learning threads, if you could give a website or a video that makes it really simple, it would be great.…

SadSeven
- 1,247
- 1
- 13
- 20
0
votes
1 answer
Segmentation Fault or SizeOf not used correctly
So I am working on a program where I am using pthreads to solve a problem in parallel. Right now, I am getting a seg fault when I run the following code in the function: average_power.
This is the pertinent part of the code that I'm pretty sure the…

phouse512
- 650
- 4
- 15
- 27
0
votes
1 answer
Why accessing pthread keys' sequence number is not synchronized in glibc's NPTL implementation?
Recently when I look into how the thread-local storage is implemented in glibc, I found the following code, which implements the API pthread_key_create()
int
__pthread_key_create (key, destr)
pthread_key_t *key;
void (*destr) (void…

spockwang
- 897
- 1
- 6
- 15