Skip to content

Commit 6ec18ae

Browse files
committed
minor : update streaming_compression example
display a warning when requesting multi-threading while linking to a library that doesn't support multi-threading.
1 parent e256e43 commit 6ec18ae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

examples/streaming_compression.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve
4242
*/
4343
CHECK_ZSTD( ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, cLevel) );
4444
CHECK_ZSTD( ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1) );
45-
ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, nbThreads);
45+
if (nbThreads > 1) {
46+
size_t const r = ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, nbThreads);
47+
if (ZSTD_isError(r)) {
48+
fprintf (stderr, "Note: the linked libzstd library doesn't support multithreading. "
49+
"Reverting to single-thread mode. \n");
50+
}
51+
}
4652

4753
/* This loop read from the input file, compresses that entire chunk,
4854
* and writes all output produced to the output file.
@@ -117,7 +123,7 @@ int main(int argc, const char** argv)
117123
}
118124

119125
int cLevel = 1;
120-
int nbThreads = 4;
126+
int nbThreads = 1;
121127

122128
if (argc >= 3) {
123129
cLevel = atoi (argv[2]);

0 commit comments

Comments
 (0)