Futures-rs: Race condition with `ThreadUnpark`?

Created on 12 Jan 2017  路  3Comments  路  Source: rust-lang/futures-rs

Specifically, lines 443-444 with lines 451-452. If the order of execution is 443,{451,452},444, then that future will never complete, right?

One solution is to use a sync_channel instead, with recv on park and send on unpark.

Most helpful comment

Thanks for the report @critiqjo! Due to how thread unpark/park work I don't think this is actually a race. If an unpark happens before a park, it'll flag the park to immediately wake up. You can find more docs about park/unpark in the official docs.

@StefanoD in a technical sense Rust protects you from data races, not race conditions.

All 3 comments

Naive question: I thought race conditions are not possible in Rust due to the ownership model.

Thanks for the report @critiqjo! Due to how thread unpark/park work I don't think this is actually a race. If an unpark happens before a park, it'll flag the park to immediately wake up. You can find more docs about park/unpark in the official docs.

@StefanoD in a technical sense Rust protects you from data races, not race conditions.

@StefanoD I think a better explanation is provided here. Race condition is tied to correctness of a system. It doesn't matter whether the system is just a single process, or a huge geographically distributed system. Data races is just a local phenomena that deals with concurrent memory accesses.

@alexcrichton Thanks for the clarification.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FSMaxB-dooshop picture FSMaxB-dooshop  路  4Comments

jedisct1 picture jedisct1  路  3Comments

mqudsi picture mqudsi  路  5Comments

jonhere picture jonhere  路  4Comments

jimblandy picture jimblandy  路  5Comments