Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

ruby - Proper Mutex usage / Good coding style? -


within following code, producer periodically_fill_page_queue might add page queue being consumed (read: in consumer before status being_processed set).

class example    def initialize     @threads      = threadgroup.new     @page_queue   = queue.new     thread.abort_on_exception = true   end    def start     periodically_fill_page_queue     periodically_process_page_queue   end    def periodically_fill_page_queue     @threads.add(thread.new       loop         if @page_queue.empty?           page.with_state(:waiting).each |p|             p.queued!             @page_queue << f           end         end         sleep 2       end     end)   end    def periodically_process_page_queue     loop       until file = @page_queue.pop         sleep 2       end       page.being_processed       process(page)     end   end    def process(page)     sleep 120     page.processed   end  end   class page < activerecord::base    state_machine :state, :initial => :waiting      event :queued       transition :waiting => :queued     end      event :being_processed       transition :queued => :being_processed     end      event :processed       transition :being_processed => :processed     end    end  end 

to avoid this, i'd use mutex object:

def initialize   ...   @mutex = mutex.new end  def periodically_process_page_queue   loop     until file = @page_queue.pop       sleep 2     end     @mutex.synchronize { page.being_processed }     process(page)   end end 

is "good" coding style, or there more elegant approaches?

thanks!

not design. alternative designs might 1 of below, naturally have own can of worms.

"fork"

for each job start new thread or process, giving job

delegation

delegate task queue in each thread. each thread pulls own unique queue.

stride

you have circular buffer , each thread checks @ different interval. e.g. num_threads + thread.id isn't situation.

range

a thread responsible range of jobs. num_threads * thread.id isn't situation.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -