vb.net - misunderstanding how the threads work -


i have problem, big problem threads in vb.net

first of want tell didn't work threads before (just on school), read lot of pages it, none of them me problem.

my main question here understand logic, , after if possible, solve problem have, both related, going explain problem.

the code hasn't comments and/or documentation related, , program developed lot of years ago , guy did not working on office, nobody knows how works :s

i have list called listofproccess, , when 1 works fine.

in callback function in queueuserworkitem fill information p, execute thread, suppose

that list contain array information type

listofproccess[].type = 'a/b/c/d/e/f/g/' 

also list include id.

code:

if listofproccess.count > 0      threading.threadpool.setminthreads(1, 1)      threading.threadpool.setmaxthreads(4, 4)       each p in listofproccess         try              threading.threadpool.queueuserworkitem(new threading.waitcallback(object p.function))           catch e exception             sendmail("mail@mail", "alerts@mail.ie", "", e.stacktrace)         end try     next 

problems: have 2 problems here:

  1. sometimes execute item in list i.e. 'a' in infinite loop, , expends resources of machine, if close , restart again, works, didn't know if problem threads or not, sincerely think other thing, because problem starts 2 or tree weeks ago, , program still running during year.

  2. this 1 think related threads, if have 2 (or more) p on list this:

    p[1].type = 'a/b/c/d/e/f/g/' p[1].id = 1

    p[2].type = 'ww/xx/ff/yy/aa/rr/' p[2].id =2

when system execute this, way follows 'random' ie. takes first one, a, b,c , after ww, , come first. problem bigger if have more items in list, 4 or 5; not big problem, because program works, not works 100% fine, works, more try understand why works on way.

any welcome.

the second problem race condition problem, can't guarantee order of execution threads, there non-zero probability threads replace each other's values. there lot of wayss solve issue: algorythms (either lock-oriented , lock-free), synchronization techniques , on, , there no silver-bullet solution this.

first problem unclear me, can't understand mean a infinite loop - may can happen if link items deleted (from other thread) ones , there no way go out of task, links in list broken. still should solved sychronization.

i think should start msdn articles or book multithreading in general, , after should split program step step small parts understand.

update:

p.function - infinite loop should consider code of delegate. if there condition restart work, should check recursion limit. example, if there an optimistic locking algorythm, code can find out update tried isn't valid, , restart it. , if links broken, never end it's task, , stay forever in infinite loop.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -