Multiple threads and lock synchronization to method

Posted on 2011-10-08
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()
       //do your stuff

Open in new window

Question by:deleyd
    1 Comment
    LVL 85

    Accepted Solution

    No...the order of thread creation does NOT guarantee they will be run in that order.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now