c - Run 3 parallel threads in a single core machine -


i have question ask. have program (process 1) has 3 threads:

  1. thread 1 runs continuously, receives packets lock socket (af_unix, non_block) , copies them buffer.
  2. thread 2 reads buffer , writes information received file (disk).
  3. thread 3 compresses file if file grows larger 5 mb

there process (process 2) continuously sending packets local socket read process 1. number of packets (of around 100 bytes) sent per second can high 3000-5000 packets per second. setup runs on embedded hardware arm v9 controller.

i have ensure none of packets lost , of them written disk. current implementation, receive sending errors @ process 2 "sendto" (resource unavailable) every , then.

i disable locks , mutexes avoiding race conditions (remove checks prevent write while read , vice-versa), sending errors "sendto".

then in second step, disable writing disk. now, thread 1 of process 1 can read fast possible local socket , there no sending error. guess since threads running on arm controller no hyperthreading, there 1 thread executing @ single point of time , os handling scheduling of threads.

my question here is,

is possible run 3 threads in parallel (each of them executing simultaneously) ? there gcc construct or compiler flag can force running of threads in parallel (in foreground) ? can change in program achieve above without splitting functionality multiple programs , using shared memory buffer ?

regards, anupam

no. can't force kind of thread order. first question, possible them execute simultaneously? yes. how can it? can't. operating system chooses that. can set priorities , things that, still think linux (or windows) switch threads pretty randomly , without telling you/allowing change scheduler. think threads programs running on computer; ones can execute , when? answer is, knows! there no way tell when thread block, if holding lock (which why you're getting resource busy response probably). how stop happening? make sure check see if resource still locked before trying use resource! then, doens't matter when threads lock resource.

also, if ipc, why using sockets? why not try pipe, , doesn't matter if lock it(unless more 1 thread writes resource @ time).


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -