java - Adjust Fairness in Multithreading -


how can adjust fairness between given k threads generate output?
in other words imagine have k threads printing "1" , n threads printing "2".
how can put fairness between threads each thread print(for example "1") as other (k - 1) print(for example "1").and same n thread printing "2".

before create threads, create array[0..numthreads-1] of empty semaphores, 1 each thread going create. signal each thread on creation incrementing semaphore index, 0..numthreads-1.

in thread function, have wait on semaphore[index], print something, signal [(index+1) mod numthreads] semaphore, loop round wait on semaphore[index] again.

once have done that, nothing should happen @ all.

throw in 1 semaphore unit, anywhere.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -