03-03-2009
17,
0
Join Date: Jan 2009
Last Activity: 19 January 2011, 8:50 AM EST
Posts: 17
Thanks Given: 1
Thanked 0 Times in 0 Posts
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..