> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XTaskQueueRegisterMonitor

> XTaskQueueRegisterMonitor

# XTaskQueueRegisterMonitor

이 큐에 콜백이 제출될 때마다 호출될 콜백을 등록합니다.

## 구문

```cpp theme={null}
HRESULT XTaskQueueRegisterMonitor(  
         XTaskQueueHandle queue,  
         void* callbackContext,  
         XTaskQueueMonitorCallback* callback,  
         XTaskQueueRegistrationToken* token  
)  
```

### 매개 변수

*queue*   \_In\_\
형식: XTaskQueueHandle

제출 콜백을 등록할 큐입니다.

*callbackContext*   \_In\_opt\_\
형식: void\*

제출 콜백에 전달할 선택적 컨텍스트 포인터입니다.

*callback*   \_In\_\
형식: [XTaskQueueMonitorCallback\*](/reference/system/xtaskqueue/functions/xtaskqueuemonitorcallback)

새 콜백이 큐에 제출될 때 호출될 콜백입니다.

*token*   \_Out\_\
형식: [XTaskQueueRegistrationToken\*](/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken)

콜백을 제거하려면 [XTaskQueueUnregisterMonitor](/reference/system/xtaskqueue/functions/xtaskqueueunregistermonitor)를 호출할 때 사용하는 토큰입니다.

### 반환 값

형식: HRESULT

HRESULT 성공 또는 오류 코드입니다.

## 설명

<Note>이 함수는 시간에 민감한 스레드에서 호출하기에 안전하지 않습니다. 자세한 내용은 [시간에 민감한 스레드](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)를 참조하세요.</Note>

다음 예제는 작업 큐가 디스패치할 항목이 있을 때 조건 변수에 신호를 보내는 데 어떻게 사용될 수 있는지 보여 줍니다. 애플리케이션은 이를 사용하여 작업 큐에 사용하는 스레드를 애플리케이션의 다른 작업과 공유할 수 있습니다.

<Note>**SubmitCallback**은 [XTaskQueueSubmitCallback](/reference/system/xtaskqueue/functions/xtaskqueuesubmitcallback) 함수에 대한 코드 예제에서 정의된 도우미 함수입니다.</Note>

```cpp theme={null}
// We will use condition variables to signal when there is something for us 
// in the queue and a bool to signal when we want the whole thing to close.
// Keep all this in a struct for convenient access
struct QueueControl
{
    std::condition_variable workActivity;
    std::mutex workMutex;
    std::condition_variable completionActivity;
    std::mutex completionMutex;
    bool terminate = false;
} queueControl;

void CALLBACK TaskQueueNewItemSubmitted(void* context, XTaskQueueHandle, XTaskQueuePort port)
{
    // A new callback has been submitted. notify the correct condition variable
    QueueControl* queueControl = static_cast<QueueControl*>(context);
    switch (port)
    {
    case XTaskQueuePort::Work:
        queueControl->workActivity.notify_all();
        break;

    case XTaskQueuePort::Completion:
        queueControl->completionActivity.notify_all();
        break;
    }
}

void CreatingTaskQueueWithManualSignaling()
{
    // Create a manual task queue
    XTaskQueueHandle queue;
    HRESULT hr = XTaskQueueCreate(
        XTaskQueueDispatchMode::Manual, 
        XTaskQueueDispatchMode::Manual, 
        &queue);

    if (FAILED(hr))
    {
        printf("Creating queue failed: 0x%x\r\n", hr);
        return;
    }

    // Listen to callback submitted notifications to signal
    // our condition variable.
    XTaskQueueRegistrationToken token;
    hr = XTaskQueueRegisterMonitor(
        queue, &queueControl, 
        TaskQueueNewItemSubmitted, &token);

    std::thread workThread([&]()
    {
        std::unique_lock<std::mutex> lock(queueControl.workMutex);
        while (!queueControl.terminate)
        {
            queueControl.workActivity.wait(lock);
            XTaskQueueDispatch(queue, XTaskQueuePort::Work, 0);
        }
    });

    std::thread completionThread([&]()
    {
        std::unique_lock<std::mutex> lock(queueControl.completionMutex);
        while (!queueControl.terminate)
        {
            queueControl.completionActivity.wait(lock);
            XTaskQueueDispatch(queue, XTaskQueuePort::Completion, 0);
        }
    });

    SubmitCallbacks(queue);

    // Wait a while for the callbacks to run
    Sleep(1000);

    XTaskQueueTerminate(queue, true, nullptr, nullptr);

    queueControl.terminate = true;
    queueControl.workActivity.notify_all();
    queueControl.completionActivity.notify_all();

    workThread.join();
    completionThread.join();
}
```

## 요구 사항

**헤더:** XTaskQueue.h

**라이브러리:** xgameruntime.lib

**지원 플랫폼:** Windows, XBOX One 제품군 콘솔 및 XBOX Series 콘솔

## 개념 문서

* [XTaskQueue 라이브러리 개요](/build/core-features/common/async/async-libraries/async-library-xtaskqueue)
* [시간에 민감한 스레드](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 함께 보기

[XTaskQueue 멤버](/reference/system/xtaskqueue/xtaskqueue_members)\
[비동기 프로그래밍 모델](/build/core-features/common/async/async-programming-model)\
[비동기 작업 큐 디자인](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [XTaskQueueUnregisterMonitor](/ko/reference/system/xtaskqueue/functions/xtaskqueueunregistermonitor.md)
- [XTaskQueueMonitorCallback](/ko/reference/system/xtaskqueue/functions/xtaskqueuemonitorcallback.md)
- [XSAPI C API에서 비동기 호출 수행](/ko/services/xbox-services/fundamentals/xbox-services-api/live-flatc-async-patterns.md)
- [비동기 호출 만들기](/ko/services/playfab/sdks/c/async.md)
- [PlayFab Unified SDK에서 비동기 호출 수행](/ko/services/playfab/sdks/unified-sdk/async-model.md)
