diff --git a/CHANGELOG.md b/CHANGELOG.md index 9191829a83..6fd7dfb771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Fixed a flattening issue for certain complex `map` nestings (#1168). + * Made API function `futhark_context_clear_caches()` thread safe + (#1169). + ## [0.18.1] ### Added diff --git a/src/Futhark/CodeGen/Backends/CCUDA/Boilerplate.hs b/src/Futhark/CodeGen/Backends/CCUDA/Boilerplate.hs index b810f6b4bb..0dea262848 100644 --- a/src/Futhark/CodeGen/Backends/CCUDA/Boilerplate.hs +++ b/src/Futhark/CodeGen/Backends/CCUDA/Boilerplate.hs @@ -461,7 +461,9 @@ generateContextFuns cfg cost_centres kernels sizes failures = do GC.publicDef_ "context_clear_caches" GC.MiscDecl $ \s -> ( [C.cedecl|int $id:s(struct $id:ctx* ctx);|], [C.cedecl|int $id:s(struct $id:ctx* ctx) { + lock_lock(&ctx->lock); CUDA_SUCCEED(cuda_free_all(&ctx->cuda)); + lock_unlock(&ctx->lock); return 0; }|] ) diff --git a/src/Futhark/CodeGen/Backends/COpenCL/Boilerplate.hs b/src/Futhark/CodeGen/Backends/COpenCL/Boilerplate.hs index b4b15c0a72..bc8325d6ad 100644 --- a/src/Futhark/CodeGen/Backends/COpenCL/Boilerplate.hs +++ b/src/Futhark/CodeGen/Backends/COpenCL/Boilerplate.hs @@ -492,7 +492,9 @@ generateBoilerplate opencl_code opencl_prelude cost_centres kernels types sizes GC.publicDef_ "context_clear_caches" GC.MiscDecl $ \s -> ( [C.cedecl|int $id:s(struct $id:ctx* ctx);|], [C.cedecl|int $id:s(struct $id:ctx* ctx) { + lock_lock(&ctx->lock); ctx->error = OPENCL_SUCCEED_NONFATAL(opencl_free_all(&ctx->opencl)); + lock_unlock(&ctx->lock); return ctx->error != NULL; }|] )