[Swift-devel] swift write once array/struct

Tim Armstrong tim.g.armstrong at gmail.com
Sat Mar 21 10:14:16 CDT 2015


Also, if you're curious about semantics of Swift data structures I've been
doing some work on that recently, would be happy to talk about it in more
detail.

- Tim

On 21 March 2015 at 10:06, Tim Armstrong <tim.g.armstrong at gmail.com> wrote:

> Hi Ketan,
>   I'm not sure that I fully understand the distinction between
> internal/external implementation.  In terms of externally observable
> behaviour, writing an already written cell will cause a runtime error
> immediately.  There's no way you can cause a deadlock or observe
> inconsistent values.  Deadlocks with array cells should only happen if
> something is waiting for a cell that has been assigned 0 times.
>
> If you're curious, i copied and pasted the relevant code fragment for
> Swift/T (it's in data.c in lb).  It's relatively straightforward, even
> though it's handling a few cases.  Essentially it's if (A[i] exists)
> return error code;.  The data structure is only accessed by a single
> thread so no race conditions are possible.
>
> I believe there's something similar in swift/k.
>
> - Tim
>
>       // Does the link already exist?
>       adlb_container_val t = NULL;
>       bool found = container_lookup(c, curr_sub, &t);
>
>       if (found && (value == NULL || t != NULL))
>       {
>         // Can overwrite reserved (unlinked) entries with actual data, but
>         // cannot double reserve entries.
>
>         // Don't print error by default: caller may want to handle
>         DEBUG("already exists: "ADLB_PRIDSUB,
>               ADLB_PRIDSUB_ARGS(id, d->symbol, subscript));
>         return ADLB_DATA_ERROR_DOUBLE_WRITE;
>       }
>       // Following code actually assigns the array cell
>       ...
>
>
>
>
>
> On 20 March 2015 at 23:33, Ketan Maheshwari <ketan at mcs.anl.gov> wrote:
>
>> Hi,
>>
>> So, in the meeting today, I was curious about wether the Swift write once
>> array/struct property is enforced via some external function or is it
>> intrinsic to the array/struct.
>>
>> In other words, is  the array/struct implemented in such a way that it
>> will automatically not allow anything to write once its i-th item has been
>> written or some external entity keeps track of this property and gets
>> triggered every time a write happens.
>>
>> I thought with intrinsic property, write operations will be atomic and
>> free of deadlocks as opposed to externally tracked/enforced property.
>>
>> --
>> Ketan
>>
>> _______________________________________________
>> Swift-devel mailing list
>> Swift-devel at ci.uchicago.edu
>> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20150321/922df03f/attachment.html>


More information about the Swift-devel mailing list