code: def test_user_event(ctx_factory):
      ctx = ctx_factory()
      if ctx._get_cl_version() < (
          1,
          1,
      ) and cl.get_cl_header_version() < (1, 1):
          from pytest import skip
  
          skip("UserEvent is only available in OpenCL 1.1")
  
      # https://github.com/pocl/pocl/issues/201
      _xfail_if_pocl(
          ctx.devices[0].platform,
          (0, 13),
          "PoCL's user events don't work right",
      )
  
      status = {}
  
      def event_waiter1(e, key):
          e.wait()
          status[key] = True
  
      def event_waiter2(e, key):
          cl.wait_for_events([e])
          status[key] = True
  
      from threading import Thread
      from time import sleep
  
      evt = cl.UserEvent(ctx)
      Thread(target=event_waiter1, args=(evt, 1)).start()
      sleep(0.05)
      if status.get(1, False):
          raise RuntimeError("UserEvent triggered before set_status")
      evt.set_status(cl.command_execution_status.COMPLETE)
      sleep(0.05)
      if not status.get(1, False):
          raise RuntimeError("UserEvent.wait timeout")
      assert (
          evt.command_execution_status
          == cl.command_execution_status.COMPLETE
      )
  
      evt = cl.UserEvent(ctx)
      Thread(target=event_waiter2, args=(evt, 2)).start()
      sleep(0.05)
      if status.get(2, False):
          raise RuntimeError("UserEvent triggered before set_status")
      evt.set_status(cl.command_execution_status.COMPLETE)
      sleep(0.05)
      if not status.get(2, False):
          raise RuntimeError("cl.wait_for_events timeout on UserEvent")
      assert (
          evt.command_execution_status
          == cl.command_execution_status.COMPLETE
      )
  
imports: import numpy
  import numpy.linalg
  import pytest
  import pyopencl
  import pyopencl.array
  import pyopencl.cltypes
  import pyopencl.clrandom
  from pyopencl.tools import pytest_generate_tests_for_pyopencl, ImmediateAllocator, DeferredAllocator
  from pyopencl.characterize import get_pocl_version
label_desc: Use image node_id 25 for calling a global function with example usage: test_user_event(ctx_factory) without return types