[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Multiple threads and lock synchronization to method

Posted on 2011-10-08
1
Medium Priority
?
199 Views
Last Modified: 2012-05-12
If I create a thread which runs SomeMethod below, and then create 5 more threads which try to run SomeMethod below before thread #1 is finished, am I guaranteed that the threads will run in the order they were created?

That is, after the first thread finishes with SomeMethod, is it random chance who the next thread will be who gets to run SomeMethod? Or am I guaranteed that it will be the "next in line" thread, that is, the 2nd thread I created, followed by the 3rd, 4th, 5th, and 6th thread.
private static object lockObject = new Object();

public static SomeMethod()
{
    lock(lockObject)
    {
       //do your stuff
    }
}

Open in new window

0
Comment
Question by:deleyd
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 36936875
No...the order of thread creation does NOT guarantee they will be run in that order.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question