malloc and free in atomic transactions

malloc and free in atomic transactions

Ritratto di lukedalessandro

Hi Everyone,
I am trying to create a simple list benchmark, and running into some issues using malloc and free. I see transactional versions of these functions in libitm.a, which I am assuming are transaction safe. I don't see a header where there are declared, so I create one of my own that uses the annotation to link to the correct symbols.

wrappers.h
-----------

#ifndef WRAPPERS_H
#define WRAPPERS_H

#ifdef __cplusplus
extern "C" {
#endif
#include 

     void* mymalloc(size_t);
     void myfree(void*);

#ifdef __cplusplus
}
#endif

#endif
Then I try to use malloc and free inside of atomic transactions. This works fine when they are lexically scoped inside of an outer transaction, but if they appear inside of a function, the compiler complains "error: non transaction ready function "malloc_it" called inside __transaction section".
test.cc
--------

#include 
#include 
#include "wrappers.h"

 void* malloc_it(size_t s) {
 return malloc(s);
}

int main(int argc, char* const argv[]) {
 void* address = NULL;
 __transaction  address = malloc(sizeof(int)); // fine
 printf("%p\\n", address);
 __transaction  address = malloc_it(sizeof(int)); // error
 printf("%p\\n", address);
 __transaction  address = malloc_it(sizeof(int)); // fine
  printf("%p\\n", address);
 return 0;
}
1) Is this simply a not-yet-implemented feature? 2) Is there a workaround, other than using relaxed transactions? 3) Is the libitm.a malloc._$TXN , or is it simply ? Thanks, Luke
4 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di lukedalessandro

I noticed now that the explicit wrapping of malloc and free isn't necessary, as the compiler is recognizing these and linking the existing wrappers appropriately---I thought the wrapping was necessary because of the unexpected behavior inside of . The rest of my question was asked before in this thread, but was never answered.

Ritratto di lukedalessandro

Actually, it seems like I can redeclare malloc and free as transaction safe without any complaints from the compiler.

wrappers.h
-------------

#ifndef WRAPPERS_H
#define WRAPPERS_H

#ifdef __cplusplus
extern "C" {
#endif

#include 

     void* malloc(size_t) __THROW;
     void  free(void*) __THROW;

#endif
This seems to produce the expected code. Is this the recommended way for dealing with the situation?

Thanks,
Luke
Ritratto di

Accedere per lasciare un commento.