Thread: C for windows with Microsoft Visual Studio 2010

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    C for windows with Microsoft Visual Studio 2010

    Hi at all guys my name is Michele Rossini and i am java developer: now i'm starting to develop in C in windows enviroment with microsoft visual studio.

    I have to modify an application for windows in a way that it becomes thread-safe.

    Can you post me some simple examples for pleasure?
    Whic are the .h to manage the thread in c for window ?

    I must to do the same actitivity but in Linux,AS400 and other platform...:-(

    Thank a lo in advance..
    michele rossini

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by michele.rossin View Post
    I have to modify an application for windows in a way that it becomes thread-safe.
    Is this a multi-threaded application?

    Quote Originally Posted by michele.rossin View Post
    Whic are the .h to manage the thread in c for window ?
    If you will be using windows thread interface, it's in windows.h.

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    2
    Hi thank for the response.

    No, the application that i must modify is not multithread.
    I know that must use Windows.h to manage the thread ,but what are the rules to make an application multithreading in C ?

    Any suggestion ?

    Thank in advance

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    If the application is not multithreaded, then you don't need any special handling. If you want to make a multithreaded application, you need to choose if you want to use the standard template class <thread> or windows based thread.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    505
    In C, you get problems when two threads want to access the same global variable at once.
    So you need to write the code to minimise use of globals, especially for writing. This includes "static" local variables. If you need any globals, protect them with
    mutexs.
    You might say, why not just declare a structure MYGLOBALS, populate it with the global variables, and pass it to every function? That won't solve the problem, if two threads get hold of the same pointer, you have exactly the same problem.
    However most programs can be written so that most of the functionality doesn't have any threading issues. You will get problems with a few things which are inherently shared resources.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Visual Studio is usually not recommended for C programming, because its support for anything resembling a modern C language standard was pretty lousy last time I checked. C++ is a different story though. Their C++ support is pretty good. Look at MinGW if you really want to program C on windows.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by Elkvis View Post
    Visual Studio is usually not recommended for C programming, because its support for anything resembling a modern C language standard was pretty lousy last time I checked. C++ is a different story though. Their C++ support is pretty good. Look at MinGW if you really want to program C on windows.
    From what I understand, VS C is based on the C89 standard (versus C99 or later). For example, local variables have to be declared at the start of a function as opposed to being able to be declared later on in a function (which C++ does allow, including Visual Studio's C++).

    As for a multi-threading example using Windows threading interface (versus STL <thread>), here's a link to a zip of a Windows console program written in C that copies a file using two threads, the original thread for reading, and a created thread for writing. The code includes linked list based messaging functions used to communicate and synchronize the threads, and the messaging functions use Windows mutexes and semaphores, which requires a bit more code to setup in main(), but the rest of the code in each function is simple and small.

    http://rcgldr.net/misc/mtcopy.zip
    Last edited by rcgldr; 04-11-2014 at 03:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ 2010, sans visual studio pro 2010?
    By ysg in forum C++ Programming
    Replies: 4
    Last Post: 02-25-2013, 02:02 PM
  2. run option gone from Microsoft Visual C++ 2010
    By juice in forum Tech Board
    Replies: 3
    Last Post: 09-30-2012, 06:54 AM
  3. Visual Studio 2010 Help
    By dnelsalty in forum C++ Programming
    Replies: 15
    Last Post: 08-30-2009, 06:07 PM
  4. Windows 7 RC, Visual Studio 2010 Beta, Office 2010 beta, anyone in?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-20-2009, 01:57 PM