In the world of C, there are many useful libraries, the most famous and most versatile (implementations spanning multiple platforms including windows, and knowing that many practical programming libraries do not provide Windows implementations) is glib this library, where there are parts to implement threads.
GLib library is the most common C language function library under Linux platform, it has good portability and practicability.
GLib is the base of GTK + library and Gnome. GLib can be used under multiple platforms, such as Linux, Unix, Windows, and so on. GLib provides a corresponding substitute for many standard, commonly used C language structures.
If you want to use the functions in the glib library in your program, you should include the Glib.h header file (Glib.h is already included in the Gtk.h and gnome.h headers).
But, because it's in Chinese, look at the person is not crooked nuts, Chinese programming novice mostly still accustomed to using Windows environment, also do not make a demand, the future will have a program as an example, which a simple application of multithreading knowledge to write a backup software, the implementation of the thread is used Windows own interface, all of which can find the appropriate documentation in MSDN.
GLib libraries are configured under Windows
The reason is not to say *nix system configuration is because, where the configuration is too little brain, especially Ubuntu, a command + network basic configuration completed.
Using the stable version of version 2.28.8, the highest stable available today is version 2.46.x
The glib package of some of the preprocessing steps is packaged in my network and can be downloaded directly, adding the IDE's path to use, which is available for the Visual C + + series compiler, if you need to recompile with the MinGW series compiler
If you want to configure yourself, you can also go to this site to download, or go to the GNU Project home page Download the latest source code and engineering documents to compile, there are many ways, do not use the existing binaries and choose to compile the most likely to use MinGW, in the MinGW Project's homepage also has introduced
If there are too few resources, you can refer to how to compile the GTK project, because the predecessor of glib is a part of GTK, only to be independent later.
Microsoft's cosmic Compiler, Visual Studio, does not support the standard after C89 (C90), but the features are implemented early (that is, there is no option to open the standard, but the new standard features that it has, can be used, and even more advanced)
So the next backup program will be written using Visual Studio 2013.
Configure glib-2.28.8
Download the compiled binary package, pretreatment good (some operations, not to say, there are tutorials on the web, remember to use Google, or to the blog park to find similar, but the version of older May and I used some way out, but can be based on gourd painting ladle), the path configuration to the project:
Create a WIN32 program and create a property sheet in the property manager (look for the bottom of the left column) (Create one for debug and release, set to be the same)
Open a new property sheet
Common Properties->vc++ directory-> contains directory-> edit add downloaded files in the Glib\glib2.28\include directory, not at ease can also add a glib\glib2.28\lib\glib-2.0\ Include directory
Common Properties->vc++ Directory-> Library directory-> edit add Glib\glib2.28\lib directory
Common Properties-> linker-> Enter-> Additional dependencies to add all the. lib files in the Glib\glib2.28\lib directory, and the names of these files are entered manually, if you use my version of this
Gio-2.0.lib glib-2.0.lib gthread-2.0.lib gmodule-2.0.lib gobject-2.0.lib
Common Properties->c/c++-> code generation-> Runtime open multithreading/MT
okay! into a
take a break .
In fact, for C programmers, the most important thing is to use a series of open source libraries, rather than the pursuit of the new standards, because the lower standards are easier to cross the platform, for the library This is the ancestors summed up a series of practical data structure and algorithms, even practical framework. We do not need to configure them, but from the inside to learn some of their technology, into their own code, after all, the library for many programmers write programs are overqualified, but sometimes have to use some necessary data structures and algorithms.
In the years of college, maybe it's just a copy of a crane tail, so I can not feel the teacher brought the teaching, but also made me deeply exposed to open source, open source gave me a lot of, such as more open programming ideas, a broader mind, more progress of the power, more small partners. And of course I know my own insignificance.
is a lot of people (such as the informed respondents and questioner), all mentioned to watch the source code of C, but this for beginners, even now I feel is not an easy thing, let alone the beginning of the students, especially for many of the last century, the great God, in order to save space and improve efficiency, is absolutely nothing! Although some usages can be accepted by modern times, you can see at the first glance that in order to construct a red-black tree node, the tree's pointer and the color information of the nodes are hidden in a pointer address?
/* Suppose there is a pointer to a node P_node
/Node_color = p_node->node_color & 1;/* The principle is to use the last bit to store the color.
In Linux, P_node->node_color is set to an unsigned long shape, storing pointers and color information in an integral form, rather than using a pointer type.
Node_pointer = (node_type*) P_node->node_color & ~3;/* Clears the value of bit on the last two digits * *
That is to clear the color information, leaving is the value of the pointer, that is, address.
Why, as long as I can ensure that the node is created in 32-bit/64-bit alignment, we can ensure that its last two bits/three bits are empty and will never be used.
* * 32-bit/sizeof (void*)//* is 4 * * * xxxx xxxx xxxx xxx xxxx xxxx xxxx xx00 * * *
64 bit * *
sizeof (void*); /* is 8 *////
* Front omitted 48 xxxx xxxx xxxx x000 * *
It means that, for pointers, because the compiler is going to be efficient at addressing, when it assigns an address, aligns the addresses in memory and aligns them by a multiple of the size of the pointer, which causes a few bits in the value of the pointer variable of the different bit program to be used for storage.
Concrete situation, the detailed explanation of the network road is very many, open a head to be good. But is it really something that we should have contacted in the first?
Is
How to say, in many cases, the C language gives us the function is not safe and reliable, but we can not use the new standard provided by the function of the case (very common) how do we do? Of course, write their own, how to write more perfect, nature is to see how others write, rather than their own smear of the mess, because it turns out that the good to the end will fall, although not bad.
The simplest way is to use a macro package, do some preprocessing, or the macro mechanism is not very like people will choose to use a function to package, also may be.
Note
Write at the end and fill in a few holes dug in front.
I don't know if it's intentional, General GNU Project on the Child home page, can not find (difficult to find) the corresponding item's download address, that is, light to see how the cow, how to use, but is not to tell you where to go, this time, first confirm you want to under the name of this software, Then go to the GNU project on the first page of the list of programs, where it can be found, rather than in those pages of confusion, the results are not found.
The most typical is an open-source software called GMP, used to compile MinGW dependencies, hoping to alert you.
The reason why I use 2.28.8 instead of 2.46.x is because I really don't want to compile on windows, because most of the time I write programs on Linux, so I just slack off.
For my file is not poisonous, I said toxic, there is a kind of called you to use Windows programming poison.
Well, actually, I admit that Visual Studio is indeed a compiler for the Invincible universe.
End
The next part of the third section I will use a backup program to run through
Operating system: Windows
Cross-platform: no
API call: Win32 API
Compiler: Visual Studio 2013
Language: Pure C programing Language
Will introduce some of the strange things that are often seen in open source code, such as
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif