> ## 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.

# 방법: 복합 작업 큐 만들기

> 방법: 복합 작업 큐 만들기

## 예제

\*복합 작업 큐(composite task queue)\*는 다른 큐의 일부로 구성된 작업 큐입니다. 복합 작업 큐는 하나의 비동기 작업이 다른 비동기 작업을 호출해야 하며, 해당 작업의 완료가 완료 스레드에서 사이클을 낭비해서는 안 되는 중간 단계일 때 유용합니다. 이 경우 복합 큐를 만들 수 있습니다. 이 복합 큐의 작업 포트와 완료 포트는 모두 원본 큐의 작업 포트를 사용합니다.

다음 예에서는 작업에 스레드 풀을 사용하지만 완료 포트 콜백을 Win32 WindowProc 콜백 함수에 통합합니다. 이 예에서는 또한 작업 큐를 다른 스레딩 모델과 통합할 때 작업 큐를 올바르게 종료하는 방법을 보여 줍니다.

```c++ theme={null}
void CreatingCompositeQueue()  
{  
    XTaskQueueHandle queue;  
  
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::ThreadPool,  
        XTaskQueueDispatchMode::Manual,  
        &queue);  
  
    if (FAILED(hr))  
    {  
        printf("Failed to create task queue: 0x%x\r\n", hr);  
        return;  
    }  
  
    XTaskQueuePortHandle workPort;  
  
    // Create a composite queue that uses the work port from  
    // another queue for both the work and the completion ports.  
  
    hr = XTaskQueueGetPort(queue, XTaskQueuePort::Work, &workPort);  
    if (FAILED(hr))  
    {  
        printf("Failed to get work port 0x%x\r\n", hr);  
        XTaskQueueCloseHandle(queue);  
        return;  
    }  
  
    XTaskQueueHandle compositeQueue;  
    hr = XTaskQueueCreateComposite(workPort, workPort, &compositeQueue);  
    if (FAILED(hr))  
    {  
        printf("Failed to create composite queue 0x%x\r\n", hr);  
        XTaskQueueCloseHandle(queue);  
        return;  
    }  
  
    // Use the queue as needed.  
    SubmitCallbacks(compositeQueue);  
  
    // Wait a while for the callbacks to run.  
    Sleep(1000);  
  
    XTaskQueueCloseHandle(compositeQueue);  
    XTaskQueueCloseHandle(queue);  
}  
```

이를 위한 또 다른 방법은 작업 및 완료 디스패치 유형이 *immediate*인 로컬 큐를 만드는 것입니다. 즉시(immediate) 디스패치 모드는 어떤 비동기 활동도 관여시키지 않습니다. 다음 코드 예제와 같이 콜백이 제출되는 즉시 디스패치합니다.

```c++ theme={null}
void CreatingImmediateQueue()  
{  
    XTaskQueueHandle queue;  
  
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::Immediate,  
        XTaskQueueDispatchMode::Immediate,  
        &queue);  
  
    if (FAILED(hr))  
    {  
        printf("Failed to create task queue: 0x%x\r\n", hr);  
        return;  
    }  
  
    // Use the queue as needed.  
    SubmitCallbacks(queue);  
  
    // Wait a while for the callbacks to run.  
    Sleep(1000);  
  
    XTaskQueueCloseHandle(queue);  
}  
```

## 참고 항목

[작업 큐 설계](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [방법: 수동 작업 큐 만들기](/ko/build/core-features/common/async/async-task-queue-design-howto/creating-manual-task-queue.md)
- [방법: 스레드 풀 작업 큐 만들기](/ko/build/core-features/common/async/async-task-queue-design-howto/creating-thread-pool-task-queue.md)
- [작업 큐 만들기 예제](/ko/build/core-features/common/async/async-libraries/async-library-xtaskqueue-example-create-task-queue.md)
- [비동기 작업 큐 설계](/ko/build/core-features/common/async/async-task-queue-design.md)
- [작업 큐 정리 예제](/ko/build/core-features/common/async/async-libraries/async-library-xtaskqueue-example-cleanup-task-queue.md)
