Sunday, 15 March 2015

c - The logic of my multithreaded application? -



c - The logic of my multithreaded application? -

i have create 3 threads:

reading strings console, ";" stops reading counting characters of string displaying strings

and utilize pipes communication.

the problem have no thought how work. have advices? i've been thinking of this:

thread1 reads single string, thread2 counts character number, , thread3 saves output in external array.

and repeating until strings read, display output in thread3.

but problem can't threads run 1 1 in order, , don't know external array in thread3 be.

break downwards problem per thread.

thread 1:

a loop reads characters 1 @ time stdin send character thread 2 through pipe[1] if character read not '.', goto 1. otherwise, terminate thread.

thread 2:

a loop reads characters 1 @ time pipe[1] send character thread 3 through pipe[2] increment charcount variable. if character read not '.', goto 1. otherwise, print charcount , terminate thread.

thread 3:

a loop reads characters 1 @ time pipe[2] print character stdout] if character read not '.', goto 1. otherwise, terminate thread.

thread main()

create pipes create threads wait threads terminate. terminate

as order threads created, code things wouldn't matter. however, preference start thread 3, 2, 1.

c linux multithreading

No comments:

Post a Comment