multithreading - C multi thread control with semaphores -


i'm trying learn threads , semaphores.

i wish write code 4 threads, outputs string "foo dee", wish thread 1 type "f", 2 type "o", thread 3 type "e" , "d" , 4th thread type spaces.

how can chain threads "foo dee" on screen mutual work of of them.

i don't want solution example of syntax work upon.

thanks help.

edit: working on linux

trying force threads operate in sequence kind of defeats purpose of creating threads begin with. of other threads must wait on pre-defined behavior occur. accomplish goal, have block threads in way not different operating sequentially (and on top of this, add overhead of thread creation , management)

... if want this, i'd use signals instead of semaphors. semaphors , mutexes used control concurrent access shared resource. forcing execution order, there no shared resource speak of.

the idea behind signals 1 thread wait until thread kicks gear. take @ following functions:

pthread_cond_wait() pthread_cond_signal() 

i think they're best way want.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -