memcheck/tests/sh-mem-random.c: Set huge_addr to 240GB
[valgrind.git] / drd / tests / std_string.cpp
blob63f94729aab74348495db57a5477cf2e625c1a1a
1 /*
2 * Test program that uses std::string object from more than one thread and
3 * that also triggers a call to __GI_strlen() (from inside strdup()). See also
4 * https://bugs.kde.org/show_bug.cgi?id=326091.
5 */
7 #include <list>
8 #include <string>
9 #include <cstring>
10 #include <pthread.h>
11 #if defined(__FreeBSD__)
12 #include <stdio.h>
13 #endif
14 #include <stdlib.h>
15 #include <unistd.h>
17 char* list2byteArray()
19 size_t data_size = 24;
20 char *data = new char[data_size];
21 for (size_t i = 0; i < data_size; i++)
22 data[i] = 'a';
23 data[data_size - 1] = 0;
24 char *ret = strdup(data);
25 delete[] data;
26 return ret;
29 int addRecord()
31 char *data = list2byteArray();
32 usleep(100);
33 free(data);
34 return 0;
37 void *fillTable(void *ptr)
39 for (int i = 0; i < 100; i++) {
40 std::string id("000");
41 id.append(1, 'a' + i);
42 std::list<std::string> record;
43 record.push_back("some data");
44 addRecord();
46 usleep(1000 * 1000);
47 return NULL;
50 int main(int argc, char* argv[])
52 pthread_t thread[2];
54 for (int i = 0; i < sizeof(thread)/sizeof(thread[0]); i++) {
55 int ret = pthread_create(&thread[i], NULL, &fillTable, NULL);
56 if (ret) {
57 fprintf(stderr, "Failed to create thread %d: %d\n", i, ret);
58 return 1;
62 for (int i = 0; i < sizeof(thread)/sizeof(thread[0]); i++) {
63 int ret = pthread_join(thread[i], NULL);
64 if (ret != 0) {
65 fprintf(stderr, "Failed to join thread %d: %d\n", i, ret);
66 return 1;
70 return 0;