MCPcopy Create free account
hub / github.com/Tencent/MMKV / threadFunction

Function threadFunction

POSIX/demo/demo.cpp:235–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233vector<string> arrStringKeys;
234
235void *threadFunction(void *lpParam) {
236 auto threadIndex = (size_t) lpParam;
237 auto mmkv = MMKV::mmkvWithID(MMKV_ID);
238 mmkv->lock();
239 cout << "thread " << threadIndex << " starts" << endl;
240 mmkv->unlock();
241
242 auto segmentCount = keyCount / threadCount;
243 auto startIndex = segmentCount * threadIndex;
244 for (int32_t index = startIndex; index < startIndex + segmentCount; index++) {
245 mmkv->set(index, arrIntKeys[index]);
246 mmkv->set("str-" + to_string(index), arrStringKeys[index]);
247 }
248
249 mmkv->lock();
250 cout << "thread " << threadIndex << " ends" << endl;
251 mmkv->unlock();
252 return nullptr;
253}
254
255void threadTest() {
256 pthread_t threadHandles[threadCount] = {0};

Callers

nothing calls this directly

Calls 5

mmkvWithIDFunction · 0.85
to_stringFunction · 0.70
lockMethod · 0.45
unlockMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected