问题描述:

I have written a C++ function to convert a string in markdown format to a string in html format wrapping the C library libmarkdown2 (Discount) on linux:

string markdown2html(const string& markdown)

{

auto m = mkd_string(&markdown[0], markdown.size(), 0);

mkd_compile(m, 0);

char* text;

int len = mkd_document(m, &text);

string html(text, text+len);

mkd_cleanup(m);

return html;

}

Is this threadsafe? That is, can I safely call this function multiple times in parallel from different thread contexts? Do Discount markdown handles share any global state that could prevent this? Is there any special per-process or per-thread initialization I need to do to prepare for such usage?

网友答案:

As far as I know the only thing that might not be re-entrant in Discount is the mkd_initialize() function, though I did a small redesign in 2.1.{mumble} to try to keep the globals static.

相关阅读:
Top