Multiple threads and lock synchronization to method

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

deleydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
No...the order of thread creation does NOT guarantee they will be run in that order.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.