与我之前关于使用正则表达式进行不区分大小写的关键字匹配的问题相关.
在Marpa中是否可以不区分大小写地匹配字符串?如果是这样,怎么样?
假设我有语法
:start ::= script
identifier ~ [\w]+
script ::= 'script' identifier code
code ::= command*
command ::= 'run' | 'walk' | 'stop'
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它符合任何script
,Script
,SCRIPT
或更低和大写字母任何其他组合?
我使用pthread TLS实现了一种"线程本地单例",我想知道在这种情况下如何(以及何时)我可能删除pthread_key_t,因为现在,TLS键使用的内存永远不会是免费的' d.
这样做的目的是让类A派生自ThreadLocalSingleton <A>,它使A成为一个线程本地单例,假设A只有私有构造函数而ThreadLocalSingleton <A>是A的朋友.
哦,还 - 你认为这个实现有任何问题; 我忽略了什么重要的事吗?
#include <pthread.h>
#include <iostream>
template <class T>
class ThreadLocalSingleton
{
private:
static pthread_key_t tlsKey;
static pthread_once_t tlsKey_once;
static void tls_make_key()
{
(void)pthread_key_create(&ThreadLocalSingleton::tlsKey, ThreadLocalSingleton::tls_destructor);
}
static void tls_destructor(void* obj)
{
delete ((T*)obj);
pthread_setspecific(tlsKey, NULL); // necessary or it will call the destructor again.
}
public:
/*
* A thread-local singleton getter, the resulted object must never be released,
* it is auto-released when the thread exits.
*/
static T* getThreadInstance(void)
{ …
Run Code Online (Sandbox Code Playgroud)