Difference between pages "r7.1.1:Typedef libshared pal thread handle t" and "r7.1.1:Typedef libshared pal thread return t"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
{{DISPLAYTITLE:typedef libshared_pal_thread_handle_t}}
{{DISPLAYTITLE:typedef libshared_pal_thread_return_t}}
==Source File==
==Source File==
  └───test_and_benchmark
  └───test_and_benchmark
Line 8: Line 8:


==Typedef==
==Typedef==
  typedef [type] test_pal_thread_handle_t;
  typedef [type] libshared_pal_thread_return_t;


==Optionality==
==Optionality==
Line 14: Line 14:


==Example==
==Example==
  typedef HANDLE test_pal_thread_state_t;
  typedef DWORD test_pal_thread_state_t;


==Notes==
==Notes==
Threads typically have associated with them both an ID and a handle.
When a thread function returns, it returns a value to the OS.  This typedef is the type of than return value.


This typedef is for the handle - i.e. the datum which the OS can wait on for thread termination.
If we look at the Windows thread function prototype;


If we look at the Windows CreateThread function;
DWORD WINAPI ThreadProc( _In_ LPVOID lpParameter );


HANDLE WINAPI CreateThread( _In_opt_  LPSECURITY_ATTRIBUTES  lpThreadAttributes,
We see the return type is ''DWORD''.
                            _In_      SIZE_T                dwStackSize,
                            _In_      LPTHREAD_START_ROUTINE lpStartAddress,
                            _In_opt_  LPVOID                lpParameter,
                            _In_      DWORD                 dwCreationFlags,
                            _Out_opt_ LPDWORD                lpThreadId );


We see there is an argument, ''lpThreadId '', which receives the thread ID, but that the function returns a ''HANDLE'', which is the datum used by ''WaitForSingleObject'' to sleep until the thread has terminated.
(The ''WINAPI'' part is actually a compiler directive and is handled in the abstraction layer by the ''[[r7.1.1:define LIBSHARED_PAL_THREAD_CALLING_CONVENTION|LIBSHARED_PAL_THREAD_CALLING_CONVENTION]]'' define.)


==See Also==
==See Also==
* [[r7.1.1:Porting Guide (libshared)|Porting Guide (libshared)]]
* [[r7.1.1:Porting Guide (libshared)|Porting Guide (libshared)]]

Latest revision as of 20:16, 17 February 2017

Source File

└───test_and_benchmark
    └───libshared
        └───inc
            └───libshared
                    libshared_porting_abstraction_layer_compiler.h

Typedef

typedef [type] libshared_pal_thread_return_t;

Optionality

This typedef is mandatory.

Example

typedef DWORD test_pal_thread_state_t;

Notes

When a thread function returns, it returns a value to the OS. This typedef is the type of than return value.

If we look at the Windows thread function prototype;

DWORD WINAPI ThreadProc( _In_ LPVOID lpParameter );

We see the return type is DWORD.

(The WINAPI part is actually a compiler directive and is handled in the abstraction layer by the LIBSHARED_PAL_THREAD_CALLING_CONVENTION define.)

See Also