Developing with WinSock2, error with CreateThread() function

I begin to develop my tool, which works with net at the TCP level, and have got the following problem: Creating thread for accept() function of Winsock I have googled and looked for the references and evereywhere there is info about creating new thread: It must have DWORD WINAPI (unsigned long __stdcall) in prefix It must accept LPVOID argument And such function will be used as the 3rd

用WinSock2进行开发,CreateThread()函数出错

我开始开发我的工具,它在TCP级别与net一起工作,并且遇到以下问题: 为Winsock的accept()函数创建线程 我已经搜索了一下,找到了有关创建新线程的参考信息和everey: 它必须具有前缀中的DWORD WINAPI(无符号长__stdcall) 它必须接受LPVOID参数 而这样的函数将作为LPTHREAD_START_ROUTINE结构的CreateThread()函数中的第三个参数使用。 但编译后我得到了下一个错误: (131):错误C2664:'CreateThread

can't seem to find std::thread in msvc++ 2010 express

I've been reading about various new additions to c++ recently that i'm really excited about and i've already been through the new std::unique_ptr and std::shared_ptr objects, which are incredibly useful, and now i'm looking for that native thread library i've heard about and can't seem to find it anywhere. I was reading and went looking for thread.h and msvc++ 2010 expres

似乎无法在msvc ++ 2010 express中找到std :: thread

最近我一直在阅读有关c ++的各种新增功能,我非常兴奋,并且已经通过了新的std :: unique_ptr和std :: shared_ptr对象,这些对象非常有用,现在我正在寻找对于我听说过的本地线程库,似乎无法在任何地方找到它。 我正在阅读并去寻找thread.h和msvc ++ 2010 express似乎没有它。 msvc ++的最新版本是不是附带这个新的线程库,还是仅仅是没有附带的快速版本,或者我只是傻傻的,不得不去寻找它在互联网上的副本? 我目前必须通

Explicitly stating a Constructor outside the class

I was trying to implement singleton pattern with an assumption of just using a private constructor, private instance of the class and a public static method to return the instance. But I encountered an error to the following code in Visual Studio // Singleton Invoice #include <iostream> using namespace std; class Singleton { public: //Public Static method with return type of Class to a

在类之外明确声明构造函数

我试图通过假定只使用私有构造函数,类的私有实例和公共静态方法来实现单例模式来返回实例。 但是我在Visual Studio中遇到以下代码的错误 // Singleton Invoice #include <iostream> using namespace std; class Singleton { public: //Public Static method with return type of Class to access that instance. static Singleton* getInstance(); private: //Private Constructor Singleton(); //Private St

Is Meyers' implementation of the Singleton pattern thread safe?

Is the following implementation, using lazy initialization, of Singleton (Meyers' Singleton) thread safe? static Singleton& instance() { static Singleton s; return s; } If not, why and how to make it thread safe? In C++11, it is thread safe. According to the standard, §6.7 [stmt.dcl] p4 : If control enters the declaration concurrently while the variable is being initializ

Meyers的Singleton模式线程是否安全?

以下是Singleton (Meyers'Singleton)线程安全的使用延迟初始化的实现吗? static Singleton& instance() { static Singleton s; return s; } 如果没有,为什么以及如何使它线程安全? 在C ++ 11中,它是线程安全的。 根据标准, §6.7 [stmt.dcl] p4 : 如果控制在变量初始化时同时进入声明,则并发执行应等待初始化完成。 GCC和VS支持该功能(动态初始化和破坏并发,也称为MSDN上的Magic Statics)

Finding C++ static initialization order problems

We've run into some problems with the static initialization order fiasco, and I'm looking for ways to comb through a whole lot of code to find possible occurrences. Any suggestions on how to do this efficiently? Edit: I'm getting some good answers on how to SOLVE the static initialization order problem, but that's not really my question. I'd like to know how to FIND object

查找C ++静态初始化顺序问题

我们遇到了一些静态初始化命令失败的问题,我正在寻找方法来梳理大量代码以查找可能的事件。 有关如何有效地做到这一点的任何建议? 编辑:我得到了一些关于如何解决静态初始化顺序问题的很好的答案,但这不是我的问题。 我想知道如何查找受此问题影响的对象。 在这方面埃文的答案似乎是迄今为止最好的; 我不认为我们可以使用valgrind,但我们可能有内存分析工具可以执行类似的功能。 只有在给定构建的初始化顺序错误的情

Singleton instance declared as static variable of GetInstance method

I've seen implementations of Singleton patterns where instance variable was declared as static variable in GetInstance method. Like this: SomeBaseClass &SomeClass::GetInstance() { static SomeClass instance; return instance; } I see following positive sides of this approach: The code is simpler, because it's compiler who responsible for creating this object only when GetInst

Singleton实例声明为GetInstance方法的静态变量

我已经看到实例变量在GetInstance方法中被声明为静态变量的Singleton模式的实现。 喜欢这个: SomeBaseClass &SomeClass::GetInstance() { static SomeClass instance; return instance; } 我看到了这种方法的以下积极方面: 代码更简单,因为编译器只负责在第一次调用GetInstance时创建此对象。 代码更安全,因为没有其他方式可以获取对实例的引用,但是使用GetInstance方法,并且没有其他方法可以更改实例,

Can any one provide me a sample of Singleton in c++?

I write a singleton c++ in the follow way: class A { private: static A* m_pA; A(); virtual ~A(); public: static A* GetInstance(); static void FreeInstance(); void WORK1(); void WORK2(); void WORK3(); } } A* A::GetInstance() { if (m_pA == NULL) m_pA = new A(); return m_pA; } A::~A() { FreeInstance(

任何人都可以在c ++中为我提供一个Singleton样本吗?

我按照以下方式编写单例c ++: class A { private: static A* m_pA; A(); virtual ~A(); public: static A* GetInstance(); static void FreeInstance(); void WORK1(); void WORK2(); void WORK3(); } } A* A::GetInstance() { if (m_pA == NULL) m_pA = new A(); return m_pA; } A::~A() { FreeInstance() // Can I wr

Static variables initialisation order

C++ guarantees that variables in a compilation unit (.cpp file) are initialised in order of declaration. For number of compilation units this rule works for each one separately (I mean static variables outside of classes). But, the order of initialization of variables, is undefined across different compilation units. Where can I see some explanations about this order for gcc and MSVC (I know

静态变量初始化顺序

C ++保证编译单元(.cpp文件)中的变量按照声明的顺序进行初始化。 对于编译单元的数量,这个规则分别适用于每个单元(我是指类之外的静态变量)。 但是,变量初始化的顺序在不同的编译单元中是未定义的。 我在哪里可以看到关于gcc和MSVC的这个命令的一些解释(我知道依赖于这是一个非常糟糕的主意 - 它只是了解我们在移植到新的GCC主要版本和不同的操作系统时可能会遇到的遗留代码问题) ? 如您所说,订单在不同的编译

Singleton instance as static field vs. static variable in getInstance() method

In this thread, the following is said about singleton instances: The static variable can be static to the GetInstance() function, or it can be static in the Singleton class. There's interesting tradeoffs there. What are these trade-offs? I am aware that, if declared as a static function variable, the singleton won't be constructed until the function is first called. I've also r

单例实例作为静态字段与getInstance()方法中的静态变量

在这个线程中,关于单例实例的内容如下: 静态变量可以是GetInstance()函数的静态变量,也可以是Singleton类中的静态变量。 那里有一些有趣的折衷。 这些折衷是什么? 我知道,如果声明为static函数变量,那么在函数第一次调用之前,单例不会被构造。 我也读过一些关于线程安全的内容,但并不知道究竟是什么,或者这两种方法在这方面有何不同。 两者之间是否还有其他重大差异? 哪种方法更好? 在我的具体例子中,

Variable creation on heap or stack in C++

Circle is a class, with public method GetDiameter() . What is the difference between the following 2 sets of code? Qn1: Does Method 1 allocates memory for c on stack (hence no need free memory), while Method 2 allocates memory for c on heap (need manually free memory)? Qn2: When should we use Method 1 or Method 2? Method 1: void Init() { Circle c; c.GetDiameter(); return; } Method 2:

在C ++中堆或堆栈上的变量创建

Circle是一个类,使用公共方法GetDiameter() 。 以下两组代码有什么区别? Qn1: 方法1是否为堆栈上的 c分配了内存(因此不需要空闲内存),而方法2是否为堆上的 c分配了内存(需要手动释放内存)? Qn2:我们应该什么时候使用方法1或方法2? 方法1: void Init() { Circle c; c.GetDiameter(); return; } 方法2: void Init() { Circle *c = new Circle(); c->GetDiameter(); return; } 作为良好编码实践