Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在c++;_C++_Multithreading - Fatal编程技术网

C++ 在c++;

C++ 在c++;,c++,multithreading,C++,Multithreading,新手问题…我创建了这个类: class CThreadMaster { public: CThreadMaster(); ~CThreadMaster(); void AddGroup(TCHAR *sGroupName); // Adds a group to the class void RemoveGroup(TCHAR *sGroupName); // Removes a group from the class void Cleanu

新手问题…我创建了这个类:

class CThreadMaster
{
public:
    CThreadMaster();
    ~CThreadMaster();

    void AddGroup(TCHAR *sGroupName);   // Adds a group to the class
    void RemoveGroup(TCHAR *sGroupName);    // Removes a group from the class
    void CleanupGroups(void);  // somehow go through the list of created classes (?)

private:
    TCHAR *m_GroupName;
    HANDLE *m_GroupThreadHandle;

};
组名位于数据库文件中。我的目标是为文件中出现的任何新组创建一个线程。我想我可以使用一个类来跟踪组名和关联的线程句柄

在下面的代码中,我有一个数组来完成这项工作,但这似乎非常低效,这就是为什么我想使用一个类-也许是一个类数组?如何循环浏览已创建类的所有实例,以便跟踪已创建关联线程的组

// In main(); each thread has a group name and a handle
#define GROUPSMAX 1024  // arbitrary number; would prefer not to be limited
struct THREADMASTER
{
HANDLE hGroupThreadHandle;
TCHAR sGroupName[128];
};
static struct THREADMASTER aGroupThreads[500] = {0,0};
//从数据库中获取组名 (……)

//查看是否已在监视组名。

对于(i=0;i您正在为自己做更多的工作。请尝试查看,例如…使用映射,您可以关联由线程ID键入的线程。

此答案需要更多的cowbell。
// See if we are already monitoring the group name.
for (i=0;i<GROUPSMAX;i++)
    {
    // See if the array has a group name filled in.
    if (_tcslen(aGroupThreads[i].sGroupName))
        {
        // Get the currently saved group name
        _stprintf_s(sGroupNameToFind,dwSizeAllGroups ,L"%s",aGroupThreads[i].sGroupName);

        // If the group name is found, exit this for loop.
        if (strstr(sAllGroupsInDB,sGroupNameToFind))
            {
            bFound = TRUE;
            break;
            }
        }
    }

if (bFound == FALSE)
    {
    for (i=0;i<GROUPSMAX;i++)
        {
        // See if the array has a group name filled in.
        if (_tcslen(aGroupThreads[i].sGroupName) == 0)
            {
            // create the thread and assign the handle
            aGroupThreads[i].sGroupName = sGroupNameToFind...
            aGroupThreads[i].hGroupThreadHandle = _beginthreadex(...)
            break;
            }
        }
    }