POSIX threads and data safety


 
Thread Tools Search this Thread
Top Forums Programming POSIX threads and data safety
# 1  
Old 03-03-2009
POSIX threads and data safety

I created multiple POSIX threads (on readhat Linux) in a C program in my app. What I am doing is - I am creating threads equal to the number of CPUs in the system and and equal number of instances of a certain data structure, basically a queue implementation. I am assigning one ID to the thread and same ID is given to the queue. Threads process data from the queue. Thread #1 always process data from queue #1 (and from this queue only) and so on. However, data that is processed from queue #1 has some state dependency wrt the previously processed data from the queue. Think of a network traffic analyser - to establish a connection, we need to take previous state into consideration.

My question is -
(a) in such a scenario, will my app be (thread) safe ?
(b) Yes, data from a queue is picked by a corresponding thread but what if the threads switch CPUs ?
(c) Do posix threads switch CPUs ?

Last edited by radiatejava; 03-03-2009 at 04:31 AM..
# 2  
Old 03-03-2009
pthreads can switch cpu's. Your model has problems.

In reading I have seen sched_setaffinity() mentioned in the context of pthreads. I have never tried it.

Have you considered pthread_setspecific() to control data access? It kind of sounds like you are doing that, but maybe in a less conventional way.
# 3  
Old 03-04-2009
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Solaris

SUNFIRE V240 procedure to shutdown with safety in order to replace power cables

Question: Which commands to use to shutdown with safety the server; (2 Replies)
Discussion started by: doudou2012
2 Replies

2. UNIX for Advanced & Expert Users

Linkage of POSIX threads function calls

I wonder if someone knows what is the rationale behind linking function calls of the POSIX threads library at link-time vs. run-time. For example, if I create the following program: #include <pthread.h> void noop() { return; } int main() { pthread_self(); pthread_atfork(noop,... (1 Reply)
Discussion started by: jsimsa
1 Replies

3. Programming

need help with posix threads

Hi, I am new to posix threads. The no of threads to be created depends on the runtime. If I get the number of threads, I need to forward declare pthread_t mythread; how to do that can I use pointers and use malloc()?? I also have another question. The pthread_join is used to make... (0 Replies)
Discussion started by: brett01
0 Replies

4. UNIX for Advanced & Expert Users

Posix threads

Hi, consider the code below: #include <stdio.h> . . struct myStruct { char *message ; int id; }; . . . void *thread_function( void *ptr ); nt main() { pthread_t thread1, thread2 ,thread3 ; struct myStruct nico1; (2 Replies)
Discussion started by: Behnaz
2 Replies

5. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

6. Programming

POSIX threads

Hello ! Let's supose I have a main function in C , and two POSIX threads. I give you an example down : int main() { int something; char else; void *FirstThread(); void *SecondThread(); .. <start those two pthreads ..> return 0;} void *FirstThread() { ... } void *SecondThread()... (2 Replies)
Discussion started by: !_30
2 Replies

7. Programming

select/poll and Signal Safety

Hi I am struggling to understand why one should use pselect()/ppoll() instead of wrapping an ordinary select() or poll() call around sigprocmask(). The linux man page talks about “race conditions”, but how would such dangers occur? I plan to use poll() for an application (since ppoll() isn't... (0 Replies)
Discussion started by: nopcoder
0 Replies
Login or Register to Ask a Question