pthreads

Conditional wait with pthreads

I seem to be running in to a possible deadlock with a pthreads conditional variable. Here is the code thread function(){ for (condition){ do work /* should the thread continue? */ if (exit == 1){ break; /* exit for */ } } /* end for */ pthread_mutex_lock(&mtxExit); exit = 0; pthrea...

pthread_create fails w/ ENOMEM ?

I am seeing pthread_create() fail with rc=12 (ENOMEM), on a 64-bit RHEL machine with 4GB of real memory. The 'top' command shows the process is using 1G of virtual memory when thread creation fails. I am able to create 16 joinable threads, but the 17th and subsequent calls fail with the ENOMEM error (which apparently means memory -or- s...

Return Value of a pthread_create

I am attempting to make the following call, PID = pthread_create(&t, NULL, schedule_sync(sch,t1), NULL); schedule_sync returns a value, I would like to be able to grab that value, but from what Ive read about pthread_create, you should pass a "void" function. Is it possible to get the return value of schedule_sync, or am I going to ha...

recv() is not interrupted by a signal in multithreaded environment

I have a thread that sits in a blocking recv() loop and I want to terminate (assume this can't be changed to select() or any other asynchronous approach). I also have a signal handler that catches SIGINT and theoretically it should make recv() return with error and errno set to EINTR. But it doesn't, which I assume has something to do ...

Concurrent access to a large collection of items

I'm working on a simulation project using c++ on both windows and linux. There will be several thousand objects (Perhaps 3000-5000) in the simulation. In plan to have several threads performing actions on the objects so that it makes good use of multi core machines, for example one thread handling movement and location of the objects, o...

check for threads still running after program exits

Hello gcc 4.4.3 c89 pthreads I use valgrind for checking memory errors. I am just wondering if there is any tool for linux that can detect running threads that haven't been terminated after the program finishes. I am running a multi-thread application and need a tool to make sure all threads have finished. Many thanks for any sugg...

pthread scheduling problems.

I have two threads in a producer-consumer pattern. Code works, but then the consumer thread will get starved, and then the producer thread will get starved. When working, program outputs: Send Data...semValue = 1 Recv Data...semValue = 0 Send Data...semValue = 1 Recv Data...semValue = 0 Send Data...semValue = 1 Recv Data...semValue = 0...

How to start a new thread for a procedure for a member object

I am trying to start a method from my main() as a new thread with pthread: int main(int argc, char** argv) { pthread_t shipGeneratorThread; Port portMelbourne; pthread_create(&shipGeneratorThread, NULL, portMelbourne.generateShips(), NULL); return (EXIT_SUCCESS); } The Port class has a function that generate...

Why can't access cocoa control in a pthread?

When I use pthread in cocoa, and want to access cocoa control in pthread function(setBtnState), it doesn't work. What's the problem? The following is the source code: AppController.h 1 // 2 // AppController.h 3 // PThreadTest 4 // 5 // Created by zhu on 10-9-5. 6 // Copyright 2010 __MyCompanyName__. All rights reserved...

How to increase thread priority in pthreads?

I am using pthread in Linux. I would like to increase the thread priority by setting the parameters sched_param.priority. However, I could not find much info from the net regarding the range of the thread priority I could set, or about the description of the thread priority. Also, I would like to know about the relative thread priority ...

AIX dynamic linking

I'm working on porting a library onto AIX. It works on Solaris, Windows and Linux but AIX is giving me headaches. I'm at a point where it builds and runs but I have an issue with some of the libraries it's linking in. Ideally I want to be able to ship a library that just requires the c runtime to be available with no other dependencies. ...

how efficient is a try_lock on a mutex?

Possible Duplicate: how efficient is locking an unlocked mutex? how much does a mutex costs? How efficient is a try_lock on a mutex? I.e. how much assembler instructions are there likely and how much time are they consuming in both possible cases (i.e. the mutex was already locked before or it was free and could be locked). ...

How to interrupt select/pselect running in QThread

I have a QThread that reads from a socket and sends a signal (QT signal) when there are any data available. This would be easy with blocking read(2), but i need to be able to stop the thread from outside without waiting for too long. If I were using pthread I would use pselect and pthread_kill(thread_id, some_signal), but QThread doesn'...

sem_wait not working as expected?

Follow up question to my pervious question: http://stackoverflow.com/questions/3579860/conditional-wait-with-pthreads I changed my code to use semaphores instead of mutex locks and conditional signals. However, I seem to have run in to a condition that I cannot explain. Here is the abstract function thread work { while (true) s...

not stopping all threads in gdb

GDB normally stops all threads if a breakpoint is reached (or Ctrl+C is pressed in the GDB shell). I'm aware that commands like scheduler-locking and schedule-multiple exists, but I see no possibility to let a defined thread run in the background while another is debugged. ...

why does thread procedure should be static or member function

why does thread procedure should be static or member function? any valid reason? ...

pthreads: If I increment a global from two different threads, can there be sync issues?

Hi all, Suppose I have two threads A and B that are both incrementing a ~global~ variable "count". Each thread runs a for loop like this one: for(int i=0; i<1000; i++) count++; //alternatively, count = count + 1; i.e. each thread increments count 1000 times, and let's say count starts at 0. Can there be sync issues in this case? O...

Mutex Initialization -(UNIX)

In the following code.A mutex is initialized.what is the significance of NULL. pthread_mutex_init(&a->monitor,NULL); I want to know why we pass NULL as the second parameter. ...

Coding Style: lock/unlock internal or external?

Hello, Another possibly inane style question: How should concurrency be locked? Should the executor or caller be responsible for locking the thread? e.g. in no particular language... Caller::callAnotherThread() { _executor.method(); } Executor::method() { _lock(); doSomething(); _unlock(); } OR Caller::callAnothe...

return() versus pthread_exit() in pthread start functions

The following program shows that we can use return() or pthread_exit() to return a void* variable that is available to pthread_join()'s status variable. (1) Should there be a preference for using one over the other? (2) Why does using return() work? Normally we think of return putting a value on the stack but since the thread is comple...