source: tests/collections/string-ctx-manage.cfa @ 4b3b352

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 4b3b352 was 4b3b352, checked in by Michael Brooks <mlbrooks@…>, 2 years ago

String hybrid has working separated sharing contexts

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <string.hfa>
2#include <string_sharectx.hfa>
3#include <string_res.hfa>
4
5void baseline() {
6    string x = "hi";
7
8    string y = x; // construct y in same context, no write yet => no copy yet
9    assert( y.inner->Handle.s == x.inner->Handle.s);
10    sout | y; // hi
11
12    x = "bye";
13    y = x; // y in same context, no write yet => no copy yet
14    assert( y.inner->Handle.s == x.inner->Handle.s);
15    sout | y; // bye
16}
17
18void eagerCopy() {
19    string x = "hi";
20    string_sharectx c = { NEW_SHARING };
21
22    string y = x; // construct y in different context => eager copy
23    assert( y.inner->Handle.s != x.inner->Handle.s);
24    sout | y; // hi
25
26    x = "bye";                                                     //.... Bookmark 9/30 shallow:  surprisingly this step failed
27    y = x; // y was already in different context => eager copy
28    assert( y.inner->Handle.s != x.inner->Handle.s);
29    sout | y; // bye
30}
31
32void failSoloAlloc() {
33    string x = "hi";
34    string_sharectx c = { NO_SHARING };
35
36    // want: allocation into private pad, with forced eager copy into it
37    // got: assertion failure, "Need to implement private contexts"
38    string y = x;
39}
40
41volatile bool showFail = false;
42
43int main() {
44    baseline();
45    eagerCopy();
46    if (showFail) {
47        failSoloAlloc();
48    }
49    printf("done\n");
50}
Note: See TracBrowser for help on using the repository browser.