Multiple contexts for host-side concurrency

Let's first briefly review how to create a single host thread in Python that can return a value to the host with a simple example. (This example can also be seen in the single_thread_example.py file under 5 in the repository.) We will do this by using the Thread class in the threading module to create a subclass of Thread, as follows:

import threadingclass PointlessExampleThread(threading.Thread):

We now set up our constructor. We call the parent class's constructor and set up an empty variable within the object that will be the return value from the thread:

def __init__(self):    threading.Thread.__init__(self)    self.return_value = None

We now set up the run function within our thread class, which ...

Get Hands-On GPU Programming with Python and CUDA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.