ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change
on this file since 4b3b352 was
4b3b352,
checked in by Michael Brooks <mlbrooks@…>, 3 years ago
|
String hybrid has working separated sharing contexts
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[0f781fb8] | 1 | #include <string.hfa> |
---|
| 2 | #include <string_sharectx.hfa> |
---|
[4b3b352] | 3 | #include <string_res.hfa> |
---|
[0f781fb8] | 4 | |
---|
[4b3b352] | 5 | void 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 | } |
---|
[0f781fb8] | 17 | |
---|
[4b3b352] | 18 | void eagerCopy() { |
---|
[0f781fb8] | 19 | string x = "hi"; |
---|
[4b3b352] | 20 | string_sharectx c = { NEW_SHARING }; |
---|
[0f781fb8] | 21 | |
---|
[4b3b352] | 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 |
---|
[0f781fb8] | 30 | } |
---|
| 31 | |
---|
| 32 | void 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 | |
---|
| 41 | volatile bool showFail = false; |
---|
| 42 | |
---|
| 43 | int main() { |
---|
[4b3b352] | 44 | baseline(); |
---|
| 45 | eagerCopy(); |
---|
[0f781fb8] | 46 | if (showFail) { |
---|
| 47 | failSoloAlloc(); |
---|
| 48 | } |
---|
| 49 | printf("done\n"); |
---|
| 50 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.