KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is wrong with this code? i get a 'Object synchronization method was called from an unsynchronized block of code'. I found one result on google that said i may be releasing a mutex before locking but according to my output this is not the case. Here is the mutex code without the other code in between. -edit- sorry guys, wrong paste. My output 1W 1W 2W code using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace sqliteTest { class Program { static volatile Mutex mut1 = new Mutex(); static volatile Mutex mut2 = new Mutex(); static void Main(string[] args) { mut1.WaitOne(); Console.WriteLine("1W"); Thread oThread = new Thread(new ThreadStart(fn2)); oThread.Start(); mut1.WaitOne(); Console.WriteLine("1W"); update(0); } static void fn2() { mut2.WaitOne(); Console.WriteLine("2W"); mut1.ReleaseMutex(); Console.WriteLine("1R"); mut2.WaitOne(); Console.WriteLine("2W"); update(1); mut1.ReleaseMutex(); Console.WriteLine("1R"); } static void update(int t) { mut2.ReleaseMutex(); Console.WriteLine("2R"); if (t == 0) { mut1.WaitOne(); Console.WriteLine("1W"); } } } }
Tags (comma-separated)
Save Edits
Cancel