Win32 API 日本語リファレンス
ホームSystem.Threading › CloseThreadpoolCleanupGroupMembers

CloseThreadpoolCleanupGroupMembers

関数
クリーンアップグループの全メンバーを解放する。
DLLKERNEL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

void CloseThreadpoolCleanupGroupMembers(
    PTP_CLEANUP_GROUP ptpcg,
    BOOL fCancelPendingCallbacks,
    void* pvCleanupContext   // optional
);

パラメーター

名前方向説明
ptpcgPTP_CLEANUP_GROUPinクリーンアップグループを定義する TP_CLEANUP_GROUP 構造体へのポインターです。このポインターは CreateThreadpoolCleanupGroup 関数によって返されます。
fCancelPendingCallbacksBOOLinこのパラメーターが TRUE の場合、まだ開始されていない未処理のコールバックをキャンセルします。FALSE の場合、未処理のコールバック関数が完了するまで待機します。
pvCleanupContextvoid*inoutoptionalアプリケーションのクリーンアップグループコールバック関数に渡すアプリケーション定義のデータです。このコールバック関数は、SetThreadpoolCallbackCleanupGroup を呼び出すときに指定できます。

戻り値の型: void

公式ドキュメント

指定したクリーンアップグループのメンバーを解放し、すべてのコールバック関数の完了を待機します。また、必要に応じて未処理のコールバック関数をキャンセルします。

解説(Remarks)

CloseThreadpoolCleanupGroupMembers 関数は、クリーンアップグループのメンバーであるすべての作業オブジェクト、待機オブジェクト、およびタイマーオブジェクトを 1 回の操作で解放することにより、スレッドプールのコールバックオブジェクトのクリーンアップを簡素化します。オブジェクトは、クリーンアップグループの作成時に指定されたスレッドプールコールバック環境を使用して作成されると、そのクリーンアップグループのメンバーになります。詳細については、CreateThreadpoolCleanupGroup を参照してください。

CloseThreadpoolCleanupGroupMembers 関数は、現在実行中のすべてのコールバック関数が終了するまでブロックします。fCancelPendingCallbacks が TRUE の場合、未処理のコールバックはキャンセルされます。それ以外の場合、この関数はすべての未処理のコールバックも終了するまでブロックします。CloseThreadpoolCleanupGroupMembers 関数が戻った後、アプリケーションは CloseThreadpoolCleanupGroupMembers の呼び出し時にクリーンアップグループのメンバーであったオブジェクトを使用してはなりません。また、これらのオブジェクトは既に解放されているため、アプリケーションは CloseThreadpoolWork などの関数を呼び出して個別に解放してはなりません。

CloseThreadpoolCleanupGroupMembers 関数は、クリーンアップグループ自体を閉じません。クリーンアップグループは、CloseThreadpoolCleanupGroup 関数が呼び出されるまで存続します。また、クリーンアップグループを閉じても、関連付けられたスレッドプールコールバック環境には影響しません。コールバック環境は、DestroyThreadpoolEnvironment を呼び出して破棄されるまで存続します。

クリーンアップグループが存続している限り、そのクリーンアップグループに関連付けられたスレッドプールコールバック環境を使用して作成された新しいオブジェクトは、クリーンアップグループに追加されます。これにより、アプリケーションはクリーンアップグループを再利用できます。ただし、CloseThreadpoolCleanupGroupMembers を呼び出すコードと新しいオブジェクトを作成するコードを同期させない場合、エラーが発生する可能性があります。たとえば、あるスレッドが 2 つのスレッドプール作業オブジェクト Work1 と Work2 を作成するとします。別のスレッドが CloseThreadpoolCleanupGroupMembers を呼び出します。スレッドの実行タイミングによっては、次のいずれかが発生する可能性があります。

保留中の作業項目を解放せずに、単に待機またはキャンセルするには、スレッドプールコールバック関数のいずれかを使用します。WaitForThreadpoolIoCallbacksWaitForThreadpoolTimerCallbacksWaitForThreadpoolWaitCallbacks、または WaitForThreadpoolWorkCallbacks です。

この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT を 0x0600 以上として定義します。

例については、Using the Thread Pool Functions を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

void CloseThreadpoolCleanupGroupMembers(
    PTP_CLEANUP_GROUP ptpcg,
    BOOL fCancelPendingCallbacks,
    void* pvCleanupContext   // optional
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern void CloseThreadpoolCleanupGroupMembers(
    IntPtr ptpcg,   // PTP_CLEANUP_GROUP
    bool fCancelPendingCallbacks,   // BOOL
    IntPtr pvCleanupContext   // void* optional, in/out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Sub CloseThreadpoolCleanupGroupMembers(
    ptpcg As IntPtr,   ' PTP_CLEANUP_GROUP
    fCancelPendingCallbacks As Boolean,   ' BOOL
    pvCleanupContext As IntPtr   ' void* optional, in/out
)
End Sub
' ptpcg : PTP_CLEANUP_GROUP
' fCancelPendingCallbacks : BOOL
' pvCleanupContext : void* optional, in/out
Declare PtrSafe Sub CloseThreadpoolCleanupGroupMembers Lib "kernel32" ( _
    ByVal ptpcg As LongPtr, _
    ByVal fCancelPendingCallbacks As Long, _
    ByVal pvCleanupContext As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CloseThreadpoolCleanupGroupMembers = ctypes.windll.kernel32.CloseThreadpoolCleanupGroupMembers
CloseThreadpoolCleanupGroupMembers.restype = None
CloseThreadpoolCleanupGroupMembers.argtypes = [
    ctypes.c_ssize_t,  # ptpcg : PTP_CLEANUP_GROUP
    wintypes.BOOL,  # fCancelPendingCallbacks : BOOL
    ctypes.POINTER(None),  # pvCleanupContext : void* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
CloseThreadpoolCleanupGroupMembers = Fiddle::Function.new(
  lib['CloseThreadpoolCleanupGroupMembers'],
  [
    Fiddle::TYPE_INTPTR_T,  # ptpcg : PTP_CLEANUP_GROUP
    Fiddle::TYPE_INT,  # fCancelPendingCallbacks : BOOL
    Fiddle::TYPE_VOIDP,  # pvCleanupContext : void* optional, in/out
  ],
  Fiddle::TYPE_VOID)
#[link(name = "kernel32")]
extern "system" {
    fn CloseThreadpoolCleanupGroupMembers(
        ptpcg: isize,  // PTP_CLEANUP_GROUP
        fCancelPendingCallbacks: i32,  // BOOL
        pvCleanupContext: *mut ()  // void* optional, in/out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern void CloseThreadpoolCleanupGroupMembers(IntPtr ptpcg, bool fCancelPendingCallbacks, IntPtr pvCleanupContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CloseThreadpoolCleanupGroupMembers' -Namespace Win32 -PassThru
# $api::CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext)
#uselib "KERNEL32.dll"
#func global CloseThreadpoolCleanupGroupMembers "CloseThreadpoolCleanupGroupMembers" sptr, sptr, sptr
; CloseThreadpoolCleanupGroupMembers ptpcg, fCancelPendingCallbacks, pvCleanupContext
; ptpcg : PTP_CLEANUP_GROUP -> "sptr"
; fCancelPendingCallbacks : BOOL -> "sptr"
; pvCleanupContext : void* optional, in/out -> "sptr"
#uselib "KERNEL32.dll"
#func global CloseThreadpoolCleanupGroupMembers "CloseThreadpoolCleanupGroupMembers" sptr, int, sptr
; CloseThreadpoolCleanupGroupMembers ptpcg, fCancelPendingCallbacks, pvCleanupContext
; ptpcg : PTP_CLEANUP_GROUP -> "sptr"
; fCancelPendingCallbacks : BOOL -> "int"
; pvCleanupContext : void* optional, in/out -> "sptr"
; void CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, void* pvCleanupContext)
#uselib "KERNEL32.dll"
#func global CloseThreadpoolCleanupGroupMembers "CloseThreadpoolCleanupGroupMembers" intptr, int, intptr
; CloseThreadpoolCleanupGroupMembers ptpcg, fCancelPendingCallbacks, pvCleanupContext
; ptpcg : PTP_CLEANUP_GROUP -> "intptr"
; fCancelPendingCallbacks : BOOL -> "int"
; pvCleanupContext : void* optional, in/out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCloseThreadpoolCleanupGroupMembers = kernel32.NewProc("CloseThreadpoolCleanupGroupMembers")
)

// ptpcg (PTP_CLEANUP_GROUP), fCancelPendingCallbacks (BOOL), pvCleanupContext (void* optional, in/out)
r1, _, err := procCloseThreadpoolCleanupGroupMembers.Call(
	uintptr(ptpcg),
	uintptr(fCancelPendingCallbacks),
	uintptr(pvCleanupContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure CloseThreadpoolCleanupGroupMembers(
  ptpcg: NativeInt;   // PTP_CLEANUP_GROUP
  fCancelPendingCallbacks: BOOL;   // BOOL
  pvCleanupContext: Pointer   // void* optional, in/out
); stdcall;
  external 'KERNEL32.dll' name 'CloseThreadpoolCleanupGroupMembers';
result := DllCall("KERNEL32\CloseThreadpoolCleanupGroupMembers"
    , "Ptr", ptpcg   ; PTP_CLEANUP_GROUP
    , "Int", fCancelPendingCallbacks   ; BOOL
    , "Ptr", pvCleanupContext   ; void* optional, in/out
    , "Int")   ; return: void
●CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext) = DLL("KERNEL32.dll", "int CloseThreadpoolCleanupGroupMembers(int, bool, void*)")
# 呼び出し: CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext)
# ptpcg : PTP_CLEANUP_GROUP -> "int"
# fCancelPendingCallbacks : BOOL -> "bool"
# pvCleanupContext : void* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn CloseThreadpoolCleanupGroupMembers(
    ptpcg: isize, // PTP_CLEANUP_GROUP
    fCancelPendingCallbacks: i32, // BOOL
    pvCleanupContext: ?*anyopaque // void* optional, in/out
) callconv(std.os.windows.WINAPI) void;
proc CloseThreadpoolCleanupGroupMembers(
    ptpcg: int,  # PTP_CLEANUP_GROUP
    fCancelPendingCallbacks: int32,  # BOOL
    pvCleanupContext: pointer  # void* optional, in/out
) {.importc: "CloseThreadpoolCleanupGroupMembers", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
void CloseThreadpoolCleanupGroupMembers(
    ptrdiff_t ptpcg,   // PTP_CLEANUP_GROUP
    int fCancelPendingCallbacks,   // BOOL
    void* pvCleanupContext   // void* optional, in/out
);
ccall((:CloseThreadpoolCleanupGroupMembers, "KERNEL32.dll"), stdcall, Cvoid,
      (Int, Int32, Ptr{Cvoid}),
      ptpcg, fCancelPendingCallbacks, pvCleanupContext)
# ptpcg : PTP_CLEANUP_GROUP -> Int
# fCancelPendingCallbacks : BOOL -> Int32
# pvCleanupContext : void* optional, in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void CloseThreadpoolCleanupGroupMembers(
    intptr_t ptpcg,
    int32_t fCancelPendingCallbacks,
    void* pvCleanupContext);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext)
-- ptpcg : PTP_CLEANUP_GROUP
-- fCancelPendingCallbacks : BOOL
-- pvCleanupContext : void* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const CloseThreadpoolCleanupGroupMembers = lib.func('__stdcall', 'CloseThreadpoolCleanupGroupMembers', 'void', ['intptr_t', 'int32_t', 'void *']);
// CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext)
// ptpcg : PTP_CLEANUP_GROUP -> 'intptr_t'
// fCancelPendingCallbacks : BOOL -> 'int32_t'
// pvCleanupContext : void* optional, in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  CloseThreadpoolCleanupGroupMembers: { parameters: ["isize", "i32", "pointer"], result: "void" },
});
// lib.symbols.CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext)
// ptpcg : PTP_CLEANUP_GROUP -> "isize"
// fCancelPendingCallbacks : BOOL -> "i32"
// pvCleanupContext : void* optional, in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void CloseThreadpoolCleanupGroupMembers(
    intptr_t ptpcg,
    int32_t fCancelPendingCallbacks,
    void* pvCleanupContext);
C, "KERNEL32.dll");
// $ffi->CloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext);
// ptpcg : PTP_CLEANUP_GROUP
// fCancelPendingCallbacks : BOOL
// pvCleanupContext : void* optional, in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    void CloseThreadpoolCleanupGroupMembers(
        long ptpcg,   // PTP_CLEANUP_GROUP
        boolean fCancelPendingCallbacks,   // BOOL
        Pointer pvCleanupContext   // void* optional, in/out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun CloseThreadpoolCleanupGroupMembers = CloseThreadpoolCleanupGroupMembers(
    ptpcg : LibC::SSizeT,   # PTP_CLEANUP_GROUP
    fCancelPendingCallbacks : Int32,   # BOOL
    pvCleanupContext : Void*   # void* optional, in/out
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CloseThreadpoolCleanupGroupMembersNative = Void Function(IntPtr, Int32, Pointer<Void>);
typedef CloseThreadpoolCleanupGroupMembersDart = void Function(int, int, Pointer<Void>);
final CloseThreadpoolCleanupGroupMembers = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<CloseThreadpoolCleanupGroupMembersNative, CloseThreadpoolCleanupGroupMembersDart>('CloseThreadpoolCleanupGroupMembers');
// ptpcg : PTP_CLEANUP_GROUP -> IntPtr
// fCancelPendingCallbacks : BOOL -> Int32
// pvCleanupContext : void* optional, in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure CloseThreadpoolCleanupGroupMembers(
  ptpcg: NativeInt;   // PTP_CLEANUP_GROUP
  fCancelPendingCallbacks: BOOL;   // BOOL
  pvCleanupContext: Pointer   // void* optional, in/out
); stdcall;
  external 'KERNEL32.dll' name 'CloseThreadpoolCleanupGroupMembers';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CloseThreadpoolCleanupGroupMembers"
  c_CloseThreadpoolCleanupGroupMembers :: CIntPtr -> CInt -> Ptr () -> IO ()
-- ptpcg : PTP_CLEANUP_GROUP -> CIntPtr
-- fCancelPendingCallbacks : BOOL -> CInt
-- pvCleanupContext : void* optional, in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let closethreadpoolcleanupgroupmembers =
  foreign "CloseThreadpoolCleanupGroupMembers"
    (intptr_t @-> int32_t @-> (ptr void) @-> returning void)
(* ptpcg : PTP_CLEANUP_GROUP -> intptr_t *)
(* fCancelPendingCallbacks : BOOL -> int32_t *)
(* pvCleanupContext : void* optional, in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("CloseThreadpoolCleanupGroupMembers" close-threadpool-cleanup-group-members :convention :stdcall) :void
  (ptpcg :int64)   ; PTP_CLEANUP_GROUP
  (f-cancel-pending-callbacks :int32)   ; BOOL
  (pv-cleanup-context :pointer))   ; void* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CloseThreadpoolCleanupGroupMembers = Win32::API::More->new('KERNEL32',
    'void CloseThreadpoolCleanupGroupMembers(LPARAM ptpcg, BOOL fCancelPendingCallbacks, LPVOID pvCleanupContext)');
# my $ret = $CloseThreadpoolCleanupGroupMembers->Call($ptpcg, $fCancelPendingCallbacks, $pvCleanupContext);
# ptpcg : PTP_CLEANUP_GROUP -> LPARAM
# fCancelPendingCallbacks : BOOL -> BOOL
# pvCleanupContext : void* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目