c# - Mysterious P/Invoke threading deadlock (Mono only?) -
c# - Mysterious P/Invoke threading deadlock (Mono only?) -
i have unusual problem p/invoke phone call c library have no command of. have thread native method (getdata
) called continuously , sec native method (wrapped in managed method) (setsetting
) called 1 time in while on main thread. 2 methods may never called @ same time or error, wrap lock
block. unusual thing if phone call setsetting
programme hangs in getdata
method as setsetting
method reaches lock
keyword. create bit more clear, code:
object lobj = new object(); //the lock object public void setsetting() //the managed method calling sec native method { lock(lobj) { nativesetsetting(); //native method (irrelevant hangs before it's called) } } public void continuousgetdata() //method running in different thread { while(dostuff == true) { lock(lobj) { getdata(); //native method hangs } //here other code happening gives plenty time //not block lock thread //(it's not relevant problem, tried that) } }
so process looks this:
start new threadcontinuousgetdata
method call setsetting
method execution reaches lock
keyword in setsetting
method program hangs , if press pause in debug window, points native 'getdata` method same thing happens other ways of synchronizing thread (e.g. resetevents). got me thinking native phone call executed on main thread (where setsetting
is waiting native phone call finish) , can't execute because it's waiting itself.
some more information:
the problem occurs on mono mac (.net on windows works) the native library different on mac , windows (but don't know how much) it hangs in same native phone call (there more one, 1 makes ptp phone call on usb camera)is possible behavior of mono on mac or think it's different handling in platform specific native library? there else can synchronize threads safely?
i'm happy help
c# multithreading mono pinvoke deadlock
Comments
Post a Comment