register user threads with Maple
cleanup the Maple structures from registered threads
MapleRegisterThread(kv, M_INT options )
kernel handle of type MKernelVector
specify which Maple features the thread needs
The MapleRegisterThread and MapleUnregisterThread functions allow user created threads to register and unregister themselves with Maple so that those threads can have access to Maple's functionality.
A user created thread is a thread that was not created by Maple (via Threads:-Create or as part of the Task Programming Model). For example, threads created when a user calls pthread_create or a similar function.
The only Maple external call function usable by an unregistered thread is MapleGetInterruptValue. No other functions are supported.
By calling MapleRegisterThread, Maple creates thread local data structures required to execute various Maple features. Which structures are created are specified by the options field.
Currently only the MAPLE_ENABLE_GMP option is supported. This creates the structure necessary to allow MaplePushGMPAllocators and MaplePopGMPAllocators to function properly in the current thread.
The MapleUnregisterThread function removes the data structures when the thread is finished using Maple features.
On success, MapleRegisterThread and MapleUnregisterThread returns MAPLE_SUCCEEDED. On failure one of the following error codes are returned:
MAPLE_ERROR_INVALID_OPTIONS: the given options is not valid.
MAPLE_ERROR_ALREADY_REGISTERED: the thread has already been registered or it is a thread created by Maple.
MAPLE_ERROR_NOT_REGISTERED: a call to unregister is made on a thread that has not been registered.
void DoGMPWorkInThread( void *args )
kv = (MKernelVector)args;
if ( MapleRegisterThread( kv, MAPLE_ENABLE_GMP ) != MAPLE_SUCCEEDED )
MaplePushGMPAllocators( kv, my_malloc, my_realloc, my_free );
MaplePopGMPAllocators( kv );
MapleUnregisterThread( kv );
ALGEB M_DECL ExternalCallFunction( MKernelVector kv, ALGEB args )
for ( i = 0; i < NUM_THREADS; i++ )
pthread_create( id+i, NULL, DoGMPWorkInThread, kv );
pthread_join( id[i], NULL );
return ToMapleNULL( kv );
Download Help Document