MapleRegisterThread - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


MapleRegisterThread

register user threads with Maple

MapleUnregisterThread

cleanup the Maple structures from registered threads

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

MapleRegisterThread(kv, M_INT options )

MapleUnregisterThread(kv)

Parameters

kv

-

kernel handle of type MKernelVector

options

-

specify which Maple features the thread needs

Description

• 

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.

Examples

#include "maplec.h"

 

void  DoGMPWorkInThread( void *args )

{

   MKernelVector kv;

 

   kv = (MKernelVector)args;

   if ( MapleRegisterThread( kv, MAPLE_ENABLE_GMP ) != MAPLE_SUCCEEDED )

   {

       return NULL;

   }

 

   MaplePushGMPAllocators( kv, my_malloc, my_realloc, my_free );

   GMPWork();

   MaplePopGMPAllocators( kv );

   MapleUnregisterThread( kv );

 

   return NULL;

}

 

ALGEB M_DECL ExternalCallFunction( MKernelVector kv, ALGEB args )

{

   M_INT i;

   pthread_t id[NUM_THREADS];

 

   for ( i = 0; i < NUM_THREADS; i++ )

    {

       pthread_create( id+i, NULL, DoGMPWorkInThread, kv );

    }

 

   for ( i = 0; i < NUM_THREADS; i++ )

    {

       pthread_join( id[i], NULL );

    }

 

   return ToMapleNULL( kv );

}

See Also

CustomWrapper

define_external

eval

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

OpenMaple/C/MapleGetInterruptValue

OpenMaple/C/MaplePopGMPAllocators

OpenMaple/C/MaplePushGMPAllocators